Can somebody help me with the refraction bug? #1641
-
Hello, I'm currently working through the Ray Tracing in One Weekend book and implementing it in Java with OpenGL. While implementing the dielectric material, I encountered a strange bug. Here's a screenshot of the issue: You can also check out my main compute shader code. I apologize if this turns out to be a simple issue, but I've been struggling with it for a while and haven't found a solution yet. Any help would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Note that an eta value of 1.0 should allow a ray to enter the sphere, and exit, without altering the direction of the ray, making the sphere effectively invisible. If you test this with your code, there are still problems. So you are correct that the refract is not the problem. I found two places that seem to be making this not behave properly:
|
Beta Was this translation helpful? Give feedback.
-
Thank you! The issue was indeed in the |
Beta Was this translation helpful? Give feedback.
Note that an eta value of 1.0 should allow a ray to enter the sphere, and exit, without altering the direction of the ray, making the sphere effectively invisible. If you test this with your code, there are still problems. So you are correct that the refract is not the problem.
I found two places that seem to be making this not behave properly:
near_zero()
you need to checking againstabs()
of each component. That is causing the bit of blue sphere visible in the lower half but not the upper.get_color()
, you only continue/recurse ifdot(ray.dir, hit_record.normal) > 0.0
. Inside theif (has_hit_anything)
block, I believe you should always continue/recurse.