Archived

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

MadProgrammer

scaling kills lighting.... why?

Recommended Posts

i have some 3d meshes (loaded from .x files) in a program i''m working on. The meshes are really big, though, in relation to everything else, so i shrink them using D3DXMatrixScaling. This really messes up the lighting (looks like it concentrates the light, makes things that are in the light appear white). i''m using a directional light coming from almost straight above anyone have any suggestions? if i shrink the models before i make the .x files, it works fine, but if i do the scaling in real-time, it kills the lighting... thanks matt

Share this post


Link to post
Share on other sites
When you scale the mesh, you also scale the normals.

Thus, the effect of the light (which is computed with the help of normals) gets brighter or darker.

You should clamp the normals back to [0.0f, 1.0f].


-- Murat

Share this post


Link to post
Share on other sites
If you are using fixed function vertex processing, you can set D3DRS_NORMALIZENORMALS, and D3D will normalize your normals for you. If you are using a vertex shader, you will need to do it yourself inside the shader.. DP3, RSQ, MUL.

xyzzy

Share this post


Link to post
Share on other sites
quote:
Original post by airbug
You should clamp the normals back to [0.0f, 1.0f].



Clamping keeps the values within that range the same while cutting them off at the extremes, that''ll mess up the lighting even more. The normals need to be scaled back to what they were.

D3DRS_NORMALIZENORMALS will work but there''s a performance hit, normalizing withing a vertex shader would have the same problem.

The best solution is to just author everything at the same scale. Then no additional trickery is required. Is there a reason why you can''t pre-scale the meshes?



Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites