• ### Popular Now

• 13
• 18
• 19
• 27
• 10

#### Archived

This topic is now archived and is closed to further replies.

# D3D8 Light problems... help!

This topic is 5097 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey, I'm getting some weird lighting errors in my 3d engine that I was hoping someone could work out... my normal code looks like the following:
for (k = 0; k < (int)uiNumberOfVertices; k += 3)
{
// k
a = pEntity->pPoly[uiBrush]->pVerts[k].pos;
b = pEntity[i]->pPoly[uiBrush]->pVerts[k + 1].pos;
c = pEntity[i]->pPoly[uiBrush]->pVerts[k + 2].pos;
p = b - a; q = c - a; n = (p ^ q) * -1;
pEntity[i]->pPoly[uiBrush]->pVerts[k].normal = n;
// k + 1
b = pEntity[i]->pPoly[uiBrush]->pVerts[k].pos;
a = pEntity[i]->pPoly[uiBrush]->pVerts[k + 1].pos;
c = pEntity[i]->pPoly[uiBrush]->pVerts[k + 2].pos;
p = b - a; q = c - a; n = (p ^ q);
pEntity[i]->pPoly[uiBrush]->pVerts[k + 1].normal = n;
// k + 2
c = pEntity[i]->pPoly[uiBrush]->pVerts[k].pos;
b = pEntity[i]->pPoly[uiBrush]->pVerts[k + 1].pos;
a = pEntity[i]->pPoly[uiBrush]->pVerts[k + 2].pos;
p = b - a; q = c - a; n = (p ^ q);
pEntity[i]->pPoly[uiBrush]->pVerts[k + 2].normal = n;
}
for (k = 0; k < (int)uiNumberOfVertices; k++)
{
n = pEntity[i]->pPoly[uiBrush]->pVerts[k].normal;
length = (float)sqrt(n.x * n.x + n.y * n.y + n.z * n.z);
if (length != 0)
{
n.x = (n.x / length);
n.y = (n.y / length);
n.z = (n.z / length);
}
else n = CVector(0,0,0);
pEntity[i]->pPoly[uiBrush]->pVerts[k].normal = n;
}
NOTE: ^ = cross product

And the errors I'm getting look like this: Here is the inside, note how the ceiling, floor and right are wall are all pitch black. (The light is behind the camera) Here is the outside, note how the one wall is illuminated despite the fact that the light is inside the level. Any thoughts? Thanks, Jesse [edited by - aphelion on April 2, 2004 8:39:40 PM]

##### Share on other sites
You could try 2 things:

- Switch of back face culling
(Maybe they get lighted correctly, but you just don''t see it?)

- Make all Normals point towards the inside of the building.
(Even tough i haven''t worked with DX a long time, if i remember correctly, if the Normal is pointing away from the Light Source, the Vertex doesn''t get lit)

##### Share on other sites
Hmm, good suggestion with the backface culling, but it still didn''t fix anything.
I think that it is a normal problem. Are there any obvious issues with the normal generating code?