Jump to content
  • Advertisement
Sign in to follow this  

Light direction for Bumpmapping

This topic is 4919 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

Hello, I have created a universe, the sun is at 0/0/0, and 30 planets rotating around it. Now I added some DOT3-Bumpmapping, but I am not sure about the correct direction. So is the following code correct, when 0/0/0 is the sun which is the light source, and planet is the current planet?
        m_vLight.x := planet3d.x;
        m_vLight.y := planet3d.y;
        m_vLight.z := planet3d.z;
        D3DXVec3Normalize(m_vLight, m_vLight);
        dwFactor := VectortoRGBA(m_vLight, 0.0);
        SetTexture(0, planet3d.bumptexture);
        SetRenderState(D3DRS_TEXTUREFACTOR, dwFactor);
        SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
        SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
        SetTextureStageState(0, D3DTSS_COLOROP,  D3DTOP_DOTPRODUCT3);
Thanks a lot, Firle

Share this post

Link to post
Share on other sites
The light vector needs to be in the same space as the normals encoded in your normal map texture. The dot product operation doesn't make any sense for lighting if the vectors aren't in the same space (or at least a related space).

So if the normals in the normal map are in object space, your light vector should be in object space too.

Light vectors are usually specified in world space.

To rotate the light vector from world space into object space, multiply it by the inverse of the top left 3x3 portion of the world matrix used for the object ("world matrix" really means "object space to world space matrix").

Tip: if the world matrix for your object is only made up from rotations and translations, transposing it is the same (but cheaper) as inverting it.

Only the top left 3x3 part of the matrix should be used to transform the light vector because the vector represents a direction rather than a position.

If the normals in the normal map are in a different space, you must transform the light vector into that space (if that space is tangent space, then the vector will be different for every vertex so you'll need to transform it on a per vertex basis).

Also, do remember that the light vector should be negated (i.e. for a directional light representing the sun, the vector should point towards the sun, not from it).

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!