Skip to content

Commit

Permalink
Merge pull request #1477 from zenustech/rectangle
Browse files Browse the repository at this point in the history
Improve ray-rectangle precision
  • Loading branch information
littlemine authored Oct 19, 2023
2 parents 7809d2b + 8d25051 commit 1eef107
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions zenovis/xinxinoptix/Shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ struct RectShape {

inline bool hitAsLight(LightSampleRecord* lsr, const float3& ray_orig, const float3& ray_dir) {

// assuming vectors are all normalized
// assuming normal and ray_dir are normalized
float denom = dot(normal, -ray_dir);
if (denom <= __FLT_DENORM_MIN__) {return false;}

Expand All @@ -118,6 +118,9 @@ struct RectShape {
auto P = ray_orig + ray_dir * t;
auto delta = P - v0;

P -= normal * dot(normal, delta);
delta = P - v0;

auto v1v1 = dot(v1, v1);
auto q1 = dot(delta, v1);
if (q1<0.0f || q1>v1v1) {return false;}
Expand All @@ -126,14 +129,15 @@ struct RectShape {
auto q2 = dot(delta, v2);
if (q2<0.0f || q2>v2v2) {return false;}

lsr->dir = ray_dir;
lsr->dist = t;

lsr->p = P;
lsr->PDF = 1.0f;
lsr->n = normal;
lsr->NoL = denom;

lsr->p = P;
lsr->PDF = 1.0f;
lsr->p = rtgems::offset_ray(lsr->p, lsr->n);

lsr->dir = ray_dir;
lsr->dist = length(lsr->p - ray_orig);

return true;
}
Expand Down Expand Up @@ -423,4 +427,4 @@ struct SphereShape {
return pbrt::LightBounds(bounds(), dc.w, phi * area,
dc.cosTheta, fmaxf(cos(M_PIf / 2.0f), 0.0f), doubleSided);
}
};
};

0 comments on commit 1eef107

Please sign in to comment.