I have written a simple raytracer (the code is here but you don't have to debug it). It can render simple meshes:
It looks pretty cool, I think. There is no reflection in the raytracer and the pixels are shaded solely based on their interpolated normals. However, if you zoom up you see that there are rendering artifacts all over it:
My question is, what is causing these "dots" on the model? I know it must have something to do with the intersection test because here is the same model rendered with another intersection routine:
If you zoom, you can see that it has the same kind of rendering errors but they are much fewer. It is hard to debug this problem because it only manifests itself on high resolutions and high triangle count meshes that takes forever to render. Is this some kind of "known problem" with raytracing? If so, what can be done about it?
Edit: Appears my problem is precision related. I have a ray defined by the following origin and direction:
o = {11.998573303222656250000, 14.635927200317382812500, 9.681089401245117187500}
d = {-0.843012511730194091797, -0.274484694004058837891, -0.462588489055633544922}
It does not intersect the triangle defined by the following three vertices:
v0 = {-0.078872203826904296875, 10.742719650268554687500, 3.051664113998413085938}
v1 = {-0.071703910827636718750, 10.628479957580566406250, 3.061952114105224609375}
v2 = {-0.005743980407714843750, 10.743999481201171875000, 3.017672061920166015625}
My intersection test is correctly implemented which means that the non-hit must be due to the lack of precision in 32 bit floats. So then the question becomes what can be done about it?