I am trying to implement a simple CPU based Raytracer in C++. But on implementing the Reflections in the scene I am getting some absurd results, the reflections are not covering the whole object that I am trying to get reflections on. I have attached the image for reference.
Here is the Reflection Algorithm I am using.
//reflected ray
Vec3 ref =(dir - 2*((dir.dot(Normal))*Normal)).normalized();
Vec3 reflect_orig;
if(depth < MAX_DEPTH && figurelist[figureHit]->reflectness>0.0f ){
if(ref.dot(Normal)<0.0f){
reflect_orig = p0 - (Normal*0.001f);
}
else{
reflect_orig = p0 + (Normal*1e-3f);
}
reflectcolour = reflectcolour+ray_trace(reflect_orig,ref,depth+1);
return Pixelcolour = reflectcolour;
}
else{
Pixelcolour = diffuse+specular;
}
where "dir" is the direction of ray.