Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

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.

If you intended to correct an error in the post then please contact us.

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


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

Share this post


Link to post
Share on other sites
Quote:
Original post by rollo
I 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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!