Raytracing artifacts

Started by
12 comments, last by Yours3!f 11 years, 2 months ago

I have had a similar problem with my raytracer. When checking for intersections, I used to compare the factor for the direction with zero to determine whether the object is in front of the view plane:


...
t1 = object.intersect(ray);
if(t1 > 0 && ...)
...

It fixed once I compared to a value near zero, e.g. 0.000001 instead. I can only assume that some sort of floating point operation inaccuracy is the reason for the artifacts.

yeah I also noticed in the tutorials that it doesn't check for hitting something, but rather is it close enough?

Advertisement

Artifacts like that can be caused by reflected vectors intersecting the object ifself, you can avoid them by moving the ray origin my a small epsilon ie. rayOrigin += rayDirection * EPSILON, or checking that the distance to the next intersected point is further away than the epsilon.

It could be something else too, but that would be my first guess looking at the picture.

n!

If you look at the code I'm already doing this:

main.cpp, 536:

result += color * vec3( p->mat.reflectivity ) * raytrace( ray( point + re * epsilon, re, ++curr_id ) ... );

Hm since this would be representative to 0.000001m (at least in my raytracer), this should be close enough.

I didn't notice that you already did the same thing by moving the ray away from the object as described by nfactorial (the result is the same as my approach). What is your value for epsilon?

Hm since this would be representative to 0.000001m (at least in my raytracer), this should be close enough.

I didn't notice that you already did the same thing by moving the ray away from the object as described by nfactorial (the result is the same as my approach). What is your value for epsilon?

:)

globals.h, 24:

static const float fepsilon = 0.0001f;

This topic is closed to new replies.

Advertisement