Hello,
I want to implement bump-mapping for educational purposes before implementing it in a real project. I went online and searched for it and found this tutorial/e-book:
[link]
http://72.14.253.104/search?q=cache:FBWtsQXeibAJ:www.csee.umbc.edu/~olano/s2002c17/ch05.pdf+D3DTOP_BUMPENVMAP&hl=en&ct=clnk&cd=20&gl=us
[/link]
I am using code from there (directly copy pasted with just a change in my variable name):
//d3ddev->SetTexture( 0, m_pEarthTexture );
d3ddev->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 1 );
d3ddev->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
d3ddev->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
d3ddev->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
//d3ddev->SetTexture( 1, m_psBumpMap );
d3ddev->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 1 );
hr = d3ddev->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_BUMPENVMAP );
d3ddev->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
d3ddev->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
d3ddev->SetTextureStageState( 1, D3DTSS_BUMPENVMAT00, F2DW(0.5f) );
d3ddev->SetTextureStageState( 1, D3DTSS_BUMPENVMAT01, F2DW(0.0f) );
d3ddev->SetTextureStageState( 1, D3DTSS_BUMPENVMAT10, F2DW(0.0f) );
d3ddev->SetTextureStageState( 1, D3DTSS_BUMPENVMAT11, F2DW(0.5f) );
d3ddev->SetTextureStageState( 1, D3DTSS_BUMPENVLSCALE, F2DW(4.0f) );
d3ddev->SetTextureStageState( 1, D3DTSS_BUMPENVLOFFSET, F2DW(0.0f) );
//d3ddev->SetTexture( 2, m_pEnvMapTexture );
d3ddev->SetTextureStageState( 2, D3DTSS_TEXCOORDINDEX, 0 );
d3ddev->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_ADD );
d3ddev->SetTextureStageState( 2, D3DTSS_COLORARG1, D3DTA_TEXTURE );
d3ddev->SetTextureStageState( 2, D3DTSS_COLORARG2, D3DTA_CURRENT );
Reason for commenting is that I set the texture stages to 3 textures earlier in my code.
There are two problems:
1: When I run this code, I see a white square that I am rendering devoid of any texture (background I fill up with green). I tried disabling and enabling 3D lighting but nothing changed. When I comment out this line:
hr = d3ddev->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_BUMPENVMAP );
I see the first texture slapped on to the square properly (but no additive environment map or bump map from second texture stage). I should see texture slightly perturbed at positions where my second texture is dark I think. Please tell me what I'm missing to get this sample to work.
2. I noticed in the DX SDK that the sample for bump mapping uses luminance rather than bump mapping. That is, it uses:
d3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_BUMPENVMAPLUMINANCE);
When I replace this with
D3DTOP_BUMPENVMAP
it doesn't work (I take all code from the DX SDK help sample under "bump mapping" chapter.
I guess I'm doing something fundamentally wrong here...
3. I have one last question: In both samples, they use texture coordinate index 1 for base texture and bump map, while they use texture coordinate index 0 for the environment map. Is there a reason for this? Code below:
// Base texture:
d3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 1 );
// Bump map texture:
d3dDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 1 );
// Environment map texture:
d3dDevice->SetTextureStageState( 2, D3DTSS_TEXCOORDINDEX, 0 );
Any particular reason why they choose index 0 for environment mapping? To me it seems that all should be the same if the textures are supposed to overlay (one upon another).
Thank you,
Regards,
P.S. Sorry about my English; it is not my first language.