# Thread: Lightning - Help Me!!!

1. ## 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. ## Re: Lightning - Help Me!!!

Are you sure for the normals?

3. ## 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. ## Re: Lightning - Help Me!!!

My normal calcs: (based on triangles)

Code :
```quad_vect Cross(quad_vect vVector1, quad_vect vVector2)
{
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;
}

{
vVector.x = vPoint1.x - vPoint2.x;
vVector.y = vPoint1.y - vPoint2.y;
vVector.z = vPoint1.z - vPoint2.z;
return vVector;
}

{
return (float)sqrt( (vNormal.x * vNormal.x) +
(vNormal.y * vNormal.y) +
(vNormal.z * vNormal.z) );
}

{
float magnitude = Magnitude(vNormal);
vNormal.x /= magnitude;
vNormal.y /= magnitude;
vNormal.z /= magnitude;
return vNormal;
}

{
vNormal = Normalize(vNormal);
return vNormal;
}```

5. ## Re: Lightning - Help Me!!!

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

same problem

7. ## 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. ## 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. ## Re: Lightning - Help Me!!!

How to average the normals?

10. ## 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
•