tunabrain / tantalum

WebGL 2D Light Transport
Other
558 stars 61 forks source link

Possible rounding error? #3

Closed AlexAti closed 8 years ago

AlexAti commented 8 years ago

First of all, this is a superb work, very beautiful.

I found something that looks like a small issue playing with it, though: in chrome, when selecting "cornell box", the right sphere seems in contact with the box on the lower end, and so some light rays escape the box. Perhaps it is not an issue but that the sphere is too low in the scene and overlaps with the box; but if they do not overlap, it might point to a rounding error of some sort.

tunabrain commented 8 years ago

You are correct! The sphere touches the floor exactly, which causes a minor light leak.

The reason for this is that rays are offset by a small epsilon from their intersection point before the next intersection test - this is to avoid interesting the same surface again. However, if you have two surfaces directly on top of each other, the ray will be offset through the second one before checking for the next intersection.

In this case, if a ray intersects the bottom of the sphere, it refracts and is offset through the floor before checking for the next intersection, so it flies right through the bottom of the box. I did notice this at some point, but it was a minor issue that I thought nobody would notice ;) In practice the best fix is to move the sphere up slightly.