Sign in to follow this  
SONB

My faces are too dark

Recommended Posts

SONB    122
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 this post


Link to post
Share on other sites
matches81    474
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 this post


Link to post
Share on other sites
skybreaker    126
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 this post


Link to post
Share on other sites
Pipo DeClown    804
Quote:
Original post by matches81
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.


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 this post


Link to post
Share on other sites
cannonicus    136
@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.

[Edit]

Also: Make sure your normals face into the room

//emijo

Share this post


Link to post
Share on other sites
Pipo DeClown    804
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.

[Edit]

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 this post


Link to post
Share on other sites
SONB    122
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 this post


Link to post
Share on other sites
jollyjeffers    1570
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 this post


Link to post
Share on other sites
jollyjeffers    1570
Quote:
Original post by SONB
How 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 this post


Link to post
Share on other sites
SONB    122
Hm, thank you for your advice, jollyjeffers!

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 this post


Link to post
Share on other sites
SONB    122
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 this post


Link to post
Share on other sites
Flimflam    665
Quote:
Original post by SONB
Here 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?


Try adding:

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

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this