Hello, I'm writing a raytracer. please take a look at the attachment. all of the balls should be grey but where the normals are almost perpendicular to the viewer, no color is assigned (and thus assigned the error value red). also the error seems to have an orientation towards the light (the light is the middle ball on the bottom); the light is in the middle above the middle ball.
Please look at my code. I know what does wrong (the dot product appears to be lower than 0, and so the if statement fails) but I have no clue as of why.
Any idea's?
Code:
// init color on black
Color* color = new Color( 0,0,0);
// walk through lights
for(int i = 0; i< world->GetNrSurfaces(); i++){
Surface* surface = world->GetSurface(i);
if(surface->IsLight()){
Surface* light = surface;
vector3 L = *((Sphere*) light)->GetCenter() - intersectionPoint;
L.Normalize();
vector3 N = *GetSurfaceNormal(&intersectionPoint);
// apply diffuse lighting
if( material->GetDiffuse() > 0){
float dot = DOT(N, L);
if(dot > 0){
float diff = dot * material->GetDiffuse();
// add the diffuse component
//*color += diff * *material->GetColor() * *light->GetMaterial()->GetColor();
*color += *light->GetMaterial()->GetColor();
}
else *color += new Color(1.0f,0,0);
}
}
}
Last edited by garma; November 17th, 2005 at 03:06 AM.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.