CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Sep 2005
    Posts
    42

    weird raytrace bug (dot product)

    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);
    				}
    			}
    		}
    Attached Images Attached Images
    Last edited by garma; November 17th, 2005 at 03:06 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured