GettingStartedWithRTXRayTracing
GettingStartedWithRTXRayTracing copied to clipboard
Bad getPerpendicularVector usage
This particular method of generating a perpendicular vector doesn't return a unit vector in most cases, so the following line (as well as line 137) should normalize() the result, otherwise you'll end up with a different distribution of rays than the one that's intended:
https://github.com/NVIDIAGameWorks/GettingStartedWithRTXRayTracing/blob/f1946147ea50987efd4e897d8bb996e2f8bc99df/12-DiffuseGlobalIllumination/Data/Tutorial12/simpleDiffuseGIUtils.hlsli#L121
This is just something I happened across while skimming the code quickly, so I haven't looked for other uses elsewhere in this sample or the others.
It's maybe not a horrendous error, since a quick test suggests that the mean norm is ~0.96, but the worse case can be ~0.82.
Thanks, good catch. I think you're right, that the vector is perpendicular but unnormalized from getPerpendicularVector() - makes sense. That function makes a non-parallel vector 1,0,0, or 0,1,0, or 0,0,1 and crosses it with the input vector. Unless the input vector is also axis-aligned, the resulting vector won't be one unit long, like you say.
I've asked the author to take a look.
The same issue was fixed in Falcor's implementation (perp_stark
) in 4.4: https://github.com/NVIDIAGameWorks/Falcor/pull/278
Code here: https://github.com/NVIDIAGameWorks/Falcor/blob/5236495554f57a734cc815522d95ae9a7dfe458a/Source/Falcor/Utils/Math/MathHelpers.h#L42-L54