garma
November 17th, 2005, 01:40 AM
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?
// 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);
}
}
}
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?
// 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);
}
}
}