# Problem with scaling a mesh smaller makes its lighting brighter and larger darker

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

## Recommended Posts

I'm using LPD3DXMESH and D3DXCreateSphere (with a radius of 1) for a sphere mesh. And I'm using the matrix scaling to draw spheres of different sizes. I'm using a directional light... The problem is when I set its scale to something small (0.5) it gets about twice as bright as if I had it scaled it something bigger (1). Or scaling it even bigger (3) makes it even darker. I guess it has something to do with scaling the normals, but I am unsure on why its doing this. Anyone have a clue? Thanks [Edited by - johnnyBravo on March 10, 2007 1:06:08 AM]

##### Share on other sites
I dont really know D3D that well, but if you do scaling you have to renormalize your normals.

##### Share on other sites
Quote:
 Original post by rolloI dont really know D3D that well, but if you do scaling you have to renormalize your normals.

Yep, what rollo said.

It's because your scaling is being done in the transformation matrix. When the mesh is transformed, the normals are transformed by that too, including scaling.

At the heart of typical [Lambertian] diffuse lighting you'll usually find a dot product between the normal vector and the light direction vector. A dot product between two vectors A,B is the equivilent of: d=cos(theta)*|A|*|B| which means "d= the cosine of the angle between the two vectors multiplied by the length of vector A multiplied by the length of vector B". When both vectors have a length of 1, then that just becomes d=cos(theta) because multiplying by 1 has no effect, which is what you want because you only care about the angle of the light relative to what it's lighting.

If you apply a scale value of say 0.5 to your world transform, then the length of L will be 1, but the length of N will come out as 0.5 so you get I=cos(theta)*1*0.5, which visually means it comes out darker...

If you use DX7 style fixed function lighting (D3DLIGHT etc), then enable the D3DRS_NORMALIZENORMALS render state.

If you do the lighting yourself in a shader, normalise the normal after it has been rotated by the rotational part of the [object to] world matrix

If possible/practical it's usually better to scale the vertices of your mesh instead of doing the scale in the transformation matrix - saves you needing to re-normalise things.

##### Share on other sites
Thanks for detailed explanation, its working now.

1. 1
2. 2
Rutin
15
3. 3
4. 4
5. 5

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633269
• Total Posts
3011147
• ### Who's Online (See full list)

There are no registered users currently online

×