Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Lightning - Help Me!!!

  1. #1
    Intern Contributor
    Join Date
    Dec 2001
    Location
    Porto Velho
    Posts
    98

    Lightning - Help Me!!!

    This code its how I put lights in my terrain engine, the problem is that the terrain looks like a chess-board, b&w quads.

    My calculation of normals its ok.

    Code :
     
    lights() its in REDRAW function too
     
    void lightsgl(void)
    {	
    	lights();    
    	glEnable(GL_LIGHT0);
    	glEnable(GL_LIGHTING);
    }
     
    void lights(void)
    {
    	float ambience[4] = {0.3f, 0.3f, 0.3f, 1.0};		
    	float diffuse[4] = {0.5f, 0.5f, 0.5f, 1.0};
    	float g_LightPosition[4] = {0, 1, 0, 1};
    	glLightfv( GL_LIGHT0, GL_AMBIENT,  ambience );		
    	glLightfv( GL_LIGHT0, GL_DIFFUSE,  diffuse );	
    	glLightfv( GL_LIGHT0, GL_POSITION, g_LightPosition ); 
    }

  2. #2
    Junior Member Newbie
    Join Date
    Mar 2002
    Posts
    6

    Re: Lightning - Help Me!!!

    Are you sure for the normals?

  3. #3
    Intern Contributor
    Join Date
    Mar 2002
    Posts
    61

    Re: Lightning - Help Me!!!

    I do agree, there is nothing wrong with your code here, it may be a problem of normals.

    How do you build them ?

  4. #4
    Intern Contributor
    Join Date
    Dec 2001
    Location
    Porto Velho
    Posts
    98

    Re: Lightning - Help Me!!!

    My normal calcs: (based on triangles)


    Code :
    quad_vect Cross(quad_vect vVector1, quad_vect vVector2)
    {
    	quad_vect vNormal;																
    	vNormal.x = ((vVector1.y * vVector2.z) - (vVector1.z * vVector2.y));
    	vNormal.y = ((vVector1.z * vVector2.x) - (vVector1.x * vVector2.z));														
    	vNormal.z = ((vVector1.x * vVector2.y) - (vVector1.y * vVector2.x));
    	return vNormal;								
    }
     
    quad_vect Vector(quad_vect vPoint1, quad_vect vPoint2)
    {
    	quad_vect vVector = {0};							
    	vVector.x = vPoint1.x - vPoint2.x;					
    	vVector.y = vPoint1.y - vPoint2.y;					
    	vVector.z = vPoint1.z - vPoint2.z;				
    	return vVector;										
    }
     
    float Magnitude(quad_vect vNormal)
    {
    	return (float)sqrt( (vNormal.x * vNormal.x) + 
    						(vNormal.y * vNormal.y) + 
    						(vNormal.z * vNormal.z) );
    }
     
    quad_vect Normalize(quad_vect vNormal)
    {
    	float magnitude = Magnitude(vNormal);			
    	vNormal.x /= magnitude;					
    	vNormal.y /= magnitude;							
    	vNormal.z /= magnitude;							
    	return vNormal;									
    }
     
    quad_vect normal(quad_vect p0,quad_vect p1,quad_vect p2)				
    {													
    	quad_vect vVector1 = Vector(p2, p0);
    	quad_vect vVector2 = Vector(p1, p0);
    	quad_vect vNormal = Cross(vVector1, vVector2);
    	vNormal = Normalize(vNormal);						
    	return vNormal;										
    }

  5. #5
    Intern Contributor
    Join Date
    Nov 2001
    Location
    Ireland
    Posts
    92

    Re: Lightning - Help Me!!!

    Try glShadeModel(GL_FLAT);

    I had a similar problem where quads lined up together had that checkerboard effect in a light. Even though my normals were correct.

  6. #6
    Intern Contributor
    Join Date
    Dec 2001
    Location
    Porto Velho
    Posts
    98

    Re: Lightning - Help Me!!!

    same problem

  7. #7
    Member Regular Contributor
    Join Date
    Jan 2002
    Posts
    296

    Re: Lightning - Help Me!!!

    Do the dark sqaures in you terrain look like they never get lit up even if you move around your terrain? Are there only two shades of color, like a white and a gray? Or there is a bit of a gray scale going on?
    If you have a gray scale color going on, I would say you are simply computing the normals and not the average normals which gives the effect of smoothness...

  8. #8
    Member Regular Contributor
    Join Date
    Jan 2002
    Posts
    296

    Re: Lightning - Help Me!!!

    Well, I was just looking at your normalization code, when you are not computing average normals which gives the effect of smothness... This is prolly what you need to do...

  9. #9
    Intern Contributor
    Join Date
    Dec 2001
    Location
    Porto Velho
    Posts
    98

    Re: Lightning - Help Me!!!

    How to average the normals?

  10. #10
    Intern Contributor
    Join Date
    Nov 2001
    Location
    Ireland
    Posts
    92

    Re: Lightning - Help Me!!!

    Are you sure you have all your triangles ordered the right way? Either all clockwise or anticlockwise?

Posting Permissions

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