Sign in to follow this  

Bump mapping example not working?

This topic is 3846 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 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.

Share this post


Link to post
Share on other sites
Check your caps for "D3DTEXOPCAPS_BUMPENVMAP" and "D3DTEXOPCAPS_BUMPENVMAPLUMINANCE". I remember that this form of bump mapping wasn't widely supported when it first came out. I have no idea how support changed from there. Everyone uses DOT3, normal mapping these days.

Share this post


Link to post
Share on other sites
Quote:
Original post by Namethatnobodyelsetook
Check your caps for "D3DTEXOPCAPS_BUMPENVMAP" and "D3DTEXOPCAPS_BUMPENVMAPLUMINANCE". I remember that this form of bump mapping wasn't widely supported when it first came out. I have no idea how support changed from there. Everyone uses DOT3, normal mapping these days.


The caps is actually true. I kind of figured out one problem: I copy-pasted the code from the website I quoted above in my first post and they were using wrap for the texture coordinates which was messing it up for some reason. Without wrap I do get color on my square, which is good. :)

But can someone explain why they use texture coordinate 0 for environment map, while they use texture coordinate 1 for the base and bump map? To me it seems that they should use the same for both.

Regards,

Share this post


Link to post
Share on other sites
You probably don't understand bump mapping very well the bump map is there to add bumps to your texture and the environment map is there to add reflection. the UVs of the environment map are constantly changing based on th position of the camera. You don't want your bump map to move around unless your adding bump mapping to your environment map. don't know why you would ever want to do that?

Share this post


Link to post
Share on other sites
Quote:
Original post by EmptyVoid
You probably don't understand bump mapping very well the bump map is there to add bumps to your texture and the environment map is there to add reflection. the UVs of the environment map are constantly changing based on th position of the camera. You don't want your bump map to move around unless your adding bump mapping to your environment map. don't know why you would ever want to do that?


Thank you, EmtpyVoid. Yes, I was off the mark when it came to DirectX bump mapping. I thought the regular bump mapping it has is bump mapping of the base texture with added environment mapping.

Correct me if I'm wrong here in my understanding: The bump mapping (not dot3, the regular one) that DirectX has is EMBM and it uses the regular, un-perturbed base texture coordinates. It applies base texture and then it uses the bump mapping to add perturbations to the environment texture before indexing it and adding the color to the primitive. For this reason, it uses the base texture's texture-coordinates for both the bump map as well as the base texture itself. However, the texture coordinates used for the environment map are different because that is view dependent.

Please tell me if I'm wrong or correct.

That being said, can anyone point me to a tutorial or application that is very simple (and doesn't use any other feature other than EMBM) and uses only EMBM without adding extra complexity. I don't want any meshes or complex dynamic vertex buffers or anything like that... just an EMBM small sample. (I haven't been able to find one for DX9).

Regards,

Share this post


Link to post
Share on other sites

This topic is 3846 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this