Jump to content
  • Advertisement

Archived

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

Eric

Problem with D3D Texture Blending Cascade

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

Can anyone tell me what''s wrong with the following code? m_pd3dDevice->SetTexture( 0, terrTextures[ 0 ].m_pddsSurface ); m_pd3dDevice->SetTexture( 1, terrTextures[ 1 ].m_pddsSurface ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE ); m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT ); m_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_BLENDDIFFUSEALPHA ); m_pd3dDevice->SetTextureStageState( 2, D3DTSS_COLORARG1, D3DTA_CURRENT ); m_pd3dDevice->SetTextureStageState( 2, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); m_pd3dDevice->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_MODULATE ); Here''s what should be happening: In Stage 0, my 1st texture is rendered w/out any lighting. In Stage 1, my 1st and 2nd textures are combined using the diffuse lighting''s alpha. Basically the primitive fades from one texture at one end to the other texture at the other end. In Stage 2, diffuse lighting is applied. The code compiles and runs, but it doesn''t work as planned. Basically, only the diffuse lighting shows up. Since the diffuse color ranges from white to black, all my primitives just fade thru various ranges of gray. Neither of the textures show up in any way. Note: I experimented a little with other, similar setups. In stage 2, if I modulate a 3rd texture with "current", they are combined correctly. If I modulate a 3rd texture with diffuse, this also works. The problem seems to be combining "current" with diffuse. Though not shown in the code above, I''ve also tested return values on everything. Any advice is much appreciated

Share this post


Link to post
Share on other sites
Advertisement
It seems to me that the code does what you want. Let me write down the formula for the final color

Color0 = Texture1
Color1 = Texture2*DiffuseAlpha + Color0*(1-DiffuseAlpha)
Color2 = Color1*DiffuseColor

Color = (Texture2*DiffuseAlpha + Texture1*(1-DiffuseAlpha))*DiffuseColor

This is what you wanted, right?

Are you running this in hardware or software mode? If hardware, I''m not sure your cards supports more than two texture stages. Most cards don''t, some don''t support more than one. Have you checked the device capabilities?

Try to disable texture stage 2 and see if the textures are faded correctly. If they aren''t then you probably have something else wrong.



- WitchLord

Share this post


Link to post
Share on other sites
The results I described were from the RGB device, which had 8-stage capability. If I just combine the two textures (and don''t do a 3rd stage), they look correct.

Anyway, I didn''t want to get bogged down on this, so I just went ahead and used multi-pass instead, which works fine. Implementing the multi-pass in my terrain-render algorithm will actually be much easier, particular when I occasionally have to blend 3 textures. There aren''t many primitives that I need to blend w/ 2 or 3 textures, so the overall speed cost (vs. single-pass multi-texturing) should be trivial.

Thanks anyway, WitchLord, and thanks for the advice in my previous thread about using a VB -- I''m going to give that a shot today

Share this post


Link to post
Share on other sites
I''ve been trying a similar method for my terrain. But actually, the RGB device only supports 2 blending stages. It''s the Reference Rasterizer that supports 8, but that is so slow it''s hardly even worth it. Also, most cards that do support multitexturing only support 2 stages, so looks like multipass is our only feasible solution for now :-(

Noah Adler

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!