-
Notifications
You must be signed in to change notification settings - Fork 868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Image corruption if lambertian scattered ray direction is (0,0,0). #619
Comments
There would be multiple places to address this (and we might want to fix more than one).
|
In cases where the random unit vector is exactly or very closely equal to the reversed normal vector, the scatter direction vector will be zero or close to it. This can lead to infinite or NaN values after the call. Resolves #619
I've decided for now not to add a test in Also, I don't think it makes sense to slow down unit_vector() by adding a non-zero test. Finally, the optimization above is short-lived as the project develops, and not really worth the additional complexity / explanation. |
There is a small chance on lambertian materials that the scattered ray has direction (0,0,0):
In line:
vec3 scatter_direction = rec.normal + random_unit_vector();
If the random_unit_vector() is the opposite of the normal.
Later, on the ray_color() function, the scattered ray will be the ray r of the next recursive call:
On the next recursive call, if there is no hit, on this line, unit_direction() will become (-nan, -nan, -nan) since unit_vector() divides by length zero:
And this will cause ray_color() to return a -nan color.
The text was updated successfully, but these errors were encountered: