Light direction for Bumpmapping

Started by
0 comments, last by S1CA 18 years, 10 months ago
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
Visit my homepage www.ericbehme.deDon't miss the download section ;)
Advertisement
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).

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

This topic is closed to new replies.

Advertisement