Hi! After some fooling around with basic ray tracing with spheres and planes I added reflections, but using the formula seen on many websites
ray direction - 2 * DotProduct(rayDirection , surfaceNormal) * surfaceNormal
the reflections seem to be orientated the wrong way.
but if I use
ray direction - 2 * DotProduct( -rayDirection , surfaceNormal) * surfaceNormal
The reflections on the spheres seem ok but isn`t the reflection on the plane a little strange?
The code that determines the color for a pixel goes as follows
//intersection point at time t point = ray.GetOrigin() + t * ray.GetDirection(); surfaceNormal = sceneObj->GetSurfaceNormal(point); //determine the reflection direction vector reflectDirection = ray.GetDirection() - (2.0f * DotProduct(-ray.GetDirection(),surfaceNormal))*surfaceNormal; //generate the color for this ray and generate a secondary ray, add the generated color return GenerateColor(point,sceneObj,surfaceNormal) + TraceRay(Ray(reflectDirection,point+reflectDirection * 0.001f),depth-1);
Thanks in advance