Cache Staheli Cache Staheli - 10 months ago 47
Java Question

Correctly raytracing reflective surfaces

I'm having some trouble with raytracing reflections.

Here is what I am expecting to see:


But this is what I am actually seeing:

Now, my basic understanding of how to get the new direction of the
reflection ray is like this:

Reflection direction equation

Here is my code that emulates that:

public Color calculateIlluminationModel(Vector normal, boolean isInShadow, Scene scene, Ray ray, Vector intersectionPoint)
if (isInShadow)
return getColorInShadow(scene);
Vector originalDirection = ray.getDirection();

Vector reflectionVector = originalDirection
Ray reflectionRay = Ray.translateRayByEpsilon(new Ray(intersectionPoint, reflectionVector));
return scene.getRayColor(reflectionRay);

But the sphere never appears to correctly reflect anything. Is there something wrong with the way I am calculating the reflection rays?

is the ray tracing component to determine the color that the ray hits. I believe it isn't the problem, but if you think it's necessary to show that piece, let me know.

Answer Source

Your reflection math appears correct. The image appears filled with a lot of shadow color. Check to see what happens if you fudge isInShadow to be false, that should help narrow it down.

Also make sure your normals point the right direction and that your direction vectors are all normalized (you said they are, but if anybody else is having a similar issue, it's worth double checking).