# My faces are too dark

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

## Recommended Posts

Hi! My scene has one point-light source and a mesh. The problem is: the light is in the middle of the mesh (it is a room) and the walls which are closer to the light are darker than the walls far away. The normals of the mesh have the same length. How can I fix this problem? Any suggestions? Thanx in advance! SONB

##### Share on other sites
Normals shouldn't have a length.. They should be normalized to unit vectors (0.0 to 1.0).

Could you show us your Light initialization? And activation (enabling)?

##### Share on other sites
Of course normals do have a length, as they are vectors. In most cases normals will have a length of 1, which would make them normalized vectors (or unit vectors) and will mean that their components would be in the interval [0.0, 1.0], obviously.

##### Share on other sites
I'm not quit sure ,but it maybe cause of the dirction of normals.Try put your light out of the room ,if it looks right that's it.
Try to change the cull mode to D3DCULL_CW,by using pdev->SetRenderState( D3DRS_CULLMODE,D3DCULL_CW)

##### Share on other sites
Quote:
 Original post by matches81Of course normals do have a length, as they are vectors. In most cases normals will have a length of 1, which would make them normalized vectors (or unit vectors) and will mean that their components would be in the interval [0.0, 1.0], obviously.

But in this context, I think when he's saying that he's not sure if the lengths of the normals aren't correct, he is not talking about the lengths along the axes but the length of the vector. Since the length of the vector isn't used when dealing with normals I think it's safe to say that normals indicate a direction (angle and maybe length along each axis) and not a distance (length).

##### Share on other sites
@Pipo DeClown:

When calculating lighting on a face using the normal of the face (or vertices) the vector length does matter. The normals must be unit length, else lighting will be flawed.

@SONB:

How are your normals calculated? Are they normals to the vertices themselfes or normals to the surface the vertices create (in this case walls, floor and ceiling)? In the latter case, if the lightsource is close to one wall the angle between the light and the vertices will be big, and the vertices will therefor be dark, leading to a darker surface then expected.

Also: Make sure your normals face into the room

//emijo

##### Share on other sites
Quote:
 Original post by cannonicus@Pipo DeClown:When calculating lighting on a face using the normal of the face (or vertices) the vector length does matter. The normals must be unit length, else lighting will be flawed.@SONB:How are your normals calculated? Are they normals to the vertices themselfes or normals to the surface the vertices create (in this case walls, floor and ceiling)? In the latter case, if the lightsource is close to one wall the angle between the light and the vertices will be big, and the vertices will therefor be dark, leading to a darker surface then expected.Also: Make sure your normals face into the room//emijo

If you look at the Original Post, you can see he uses "same length" to describe his normals. To me it seems that he does not know that normals are unit vectors. I wanted to inform him that normals may have lengths but those aren't important since they are always the same (1).

So basically what I tried to say was that normals are used to hold directions and not distances. Maybe I didn't explain myself well enough.

##### Share on other sites
Wow, thanx a lot for your replies!

Well, the normals are all normalized and face into the room and they are normals to the surface the vertices create. How can I change the way they are calculated?

I made the mesh in Maya, if that helps.

SONB

##### Share on other sites
Are you using the fixed-function pipeline, and are you doing any scaling when rendering? If so, try setting D3DRS_NORMALIZENORMALS to TRUE and see if it sorts things out [smile]

It's a subtle bug that's caught me out a few times over the years... but under the FF the scaling of the world matrix affects the length of the normals, which feeds into the calculations. Reducing the size of your world gives darker lighting and increasing the size makes things a whole lot brighter.

hth
Jack

##### Share on other sites
Quote:
 Original post by SONBHow can I change the way they are calculated?

If it's being loaded in to an ID3DXMesh container, you could look into the D3DXComputeNormals() function.

hth
Jack

##### Share on other sites

I'm using the fixed-function pipeline and set D3DRS_NORMALIZENORMALS to TRUE with no results. Then I used the D3DXComputeNormals() function and there was some positive changes BUT the two walls which are far away from the light are still better lit than the other two walls, floor and ceiling which are close to it.

##### Share on other sites
Here I post the initialization code of the light:

D3DLIGHT9 m_Light;ZeroMemory(&m_Light, sizeof(D3DLIGHT9));m_Light.Type = D3DLIGHT_POINT;m_Light.Range = 1000.0f;m_Light.Falloff = 1.0f;m_Light.Attenuation0 = 0.0f;m_Light.Attenuation1 = 1.0f;m_Light.Attenuation2 = 0.0f;m_Light.Diffuse.r = 1.0f;m_Light.Diffuse.g = 1.0f;m_Light.Diffuse.b = 1.0f;m_pD3DDevice->SetLight(0, &m_Light);m_pD3DDevice->LightEnable(0, TRUE);

That's it. I'm not sure about the attenuation settings.

Could a flexible-function pipeline be a solution for my problem?

[Edited by - SONB on November 30, 2005 2:30:48 PM]

##### Share on other sites
It seems like you're not assigning a position (PointLights have positions, y'know) so it's defaulting to zero, zero, zero (ZeroMemory). What are the vertices' positions?

##### Share on other sites
Quote:
 Original post by SONBHere I post the initialization code of the light:*** Source Snippet Removed ***That's it. I'm not sure about the attenuation settings.Could a flexible-function pipeline be a solution for my problem?

m_Light.Position = D3DXVECTOR3(x, y, z);

Replacing x, y and z with your light's desired position, of course.