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


DOT3 Bump Mapping problems...

Recommended Posts

Hi there, maybe someone can help me with my dot3 bump mapping problem... I have my texture and a generated normal map. I''m using the following texture states with the normal map as stage 0 and the texture as stage 1.
pDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3);
pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TFACTOR);

pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

pDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE2X); // This may not be correct but it works, kinda
pDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);

pDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
pDevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); 
The problem is not in the actual blending which seems to be working kinda correctly (maybe modulate2x as my stage 1 color-op isn''t exactly what i need). What i''m having trouble with is supplying a correct lighting vector as the TFactor.
DWORD dwFactor = VectorToDword(vLight);
pDevice->SetRenderState(D3DRS_TEXTUREFACTOR, dwFactor);
So, for example, say my ''sun'' is at x=0, y=5, z=5. This means that my light vector is x=0, y=-5, z=-5. I use this vector converted to a dword as above, but what happens is instead of a correctly shaded result i get an even black shade over the whole texture. I guess my question is: What do I need to do to my ''light'' vector to somehow correct it so that i get the correct result out.. Hopefully this will make sense to someone experienced with this method of bump mapping..

Share this post

Link to post
Share on other sites
1) Since there''s no equivilent of the per vertex ambient, the light will be very directional and any normal 90 degrees or more away will be totally black.

2) How are you generating your normal map?, are the normals in there properly normalised into the -127 to 128 range after conversion from the height map?

3) Is the normal map much smaller than the model it''s being applied to?, and are the texture coordinates correct? Try changing the filter mode for stage 0 to D3DTEXF_POINT. If the normals get heavily bilinear filtering, then the resultant vectors in the texture will become smaller than unit length, resulting in black patches!!!

4) And the VectorToDword - is that correct?

Simon O''Connor
Creative Asylum Ltd

Share this post

Link to post
Share on other sites