szellmann / visionaray

A C++-based, cross platform ray tracing library
https://vis.uni-koeln.de/visionaray.html
MIT License
429 stars 37 forks source link

pathtracing.inl: wrong shadow rays for delta lights #29

Closed jampekka closed 5 years ago

jampekka commented 5 years ago

When the lights are sampled in visionray::pathtracing::kernel, the shadow is cast with max length of ld at: https://github.com/szellmann/visionaray/blob/f557d7d206b0ff3431ba634be9d05619d541ad3f/include/visionaray/detail/pathtracing.inl#L155

However, for delta lights ld is always set to one (presumably due to handle the solid angle computations later) at: https://github.com/szellmann/visionaray/blob/f557d7d206b0ff3431ba634be9d05619d541ad3f/include/visionaray/detail/pathtracing.inl#L140

Using the proper length for the shadow ray seems to fix this issue. Eg:

auto lhr = any_hit(shadow_ray, params.prims.begin, params.prims.end, length(ls.pos - hit_rec.isect_pos) - S(2.0f * params.epsilon), isect);
szellmann commented 5 years ago

Good catch! With the current code and delta lights, max_t for calculating shadow rays is always 1-2*EPSILON. Just using the shadow ray's length instead of ld for max_t seems like a proper fix to me, too. Thanks for reporting!

szellmann commented 5 years ago

I fixed this in a slightly different way. Seems a bit more concise to me handling this just where solid angle is computed.