Jump to content
  • Advertisement
Sign in to follow this  
Icebraker

Problem with reflection in raytracing

This topic is 3743 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm currently writing a triangle-raytracer using the triangle intersection by Moeller & Trumbore. I can raytrace a normal scene perfectly, but I don't get reflections working properly. Obviously I misunderstood something about reflections... However, here is my code: Vec3f dir=-originOfOriginalRay+pointOfIntersection; dir.Normalize(); //! Compute new ray Vec3f reflect = 2.0*dir.Dot3(normal)*normal-dir; reflect.Normalize(); for(vector<triangle>::iterator itReflect = triangleList->begin(); itReflect != triangleList->end(); itReflect++) { Vec3f vertex0(itReflect->getVertices(0,0),itReflect->getVertices(0,1),itReflect->getVertices(0,2)); Vec3f vertex1(itReflect->getVertices(1,0),itReflect->getVertices(1,1),itReflect->getVertices(1,2)); Vec3f vertex2(itReflect->getVertices(2,0),itReflect->getVertices(2,1),itReflect->getVertices(2,2)); Vec3f edge1=vertex1-vertex0; Vec3f edge2=vertex2-vertex0; if(intersect_triangle(pointOfIntersection, reflect,vertex0,edge1,edge2,&t,&u,&v)==1) { //! Enters this part all the time... } } I know that the normals and my pointOfIntersection are OK as phong lighting works perfectly, but I always detect an intersection of my reflection ray, even if it should just reflect out of the scene. Does anybodt spot a mistake in my code? Icebraker

Share this post


Link to post
Share on other sites
Advertisement
When you create a new ray after an intersection occourred, you should always offset the origin point of the new raz, to avoid the famous self intersection problem due to floating point precision limits:

vector reflection_origin = intersection_point + surface_normal * EPSILON

where epsilon is a small value (i.e 0.001).

Have you already implemented shadow rays? Because you should get this error with them too...

By the way, this is the code I use to reflect a vector:

const vector4<T> Reflect(const vector4<T> &n) const
{
return *this - (T(2) * (this->Dot(n))) * n;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!