I am implementing a Ray Tracer in C++.
I am having trouble with adding reflections to my scene.
Here is a simple scene with no reflections [ link ].
Here is the same scene with 1 level of reflections on the sphere [ link ].
There are no other objects in the scene.
As an example, this is the sort of thing I expect to achieve: https: //puu.sh/uAbMX/d2c8922c7d.jpg
[take out the space, soz SO only lets me post 2 links]
I'm pretty sure my calculation of reflection direction is sound, as I am getting correct specular highlights.
Any ideas what might be causing this?
My code for adding reflection component to rendered colour:
// Takes incoming vector (towards surface) and surface normal
void Scene::reflectionTrace( Ray &R, Vex &hitN, int &lvl, Obj *closest, double &t, Col &traceCol ) {
Vex reflDir = reflectedDir( hitN, R.D );
Vex reflPos = R.posAt( t );
reflPos += ((R.D.revV( ) | hitN) < 0.0) ? (hitN * -BIAS) : (hitN * BIAS);
// offset ray starting point to avoid self-reflections. | indicates dot product
Ray reflectRay = Ray( reflDir, reflPos );
Col reflCol = rayTrace( reflectRay, (lvl - 1) );
double fresRef = 1.0; //Fresnel( objN, R.D, closest->mat->ior, true );
traceCol += (closest->kr( ) * (reflCol * fresRef));
}
My reflectedDir function, to calculate the normalised vector ("Vex") for the reflection:
Vex Scene::reflectedDir( Vex &N, Vex &I ) { // R = I - ((2.0 * (I . N)) * N)
return ((N * (2.0 * (N | I))) > I).normaliseV( ); // > indicates the left argument taken from the right argument
}
Is the issue with the actual reflection calculation, or perhaps with assigning colours?
Thanks in advance :)
Aucun commentaire:
Enregistrer un commentaire