Jump to content
  • Advertisement
Sign in to follow this  
Kest

Texture Stage Setup

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

I can't come up with a working set of texture stages to accomplish this. I would like to keep the number of stages at or below 3, or better yet, 2. Anyway, this is what I'm working with: Diffuse - RGB vertex color, alpha component stores alpha for transparency Specular - RGB for dot product stage, ambience is stored in alpha NormalMap - normal map texture DiffuseMap - color texture This is the result I would like to reach: ResultColor = ( DotProduct3 + Specular.a ) * DiffuseMap * Diffuse ResultAlpha = Diffuse.a; I'm referring to ( NormalMap * Specular.rgb ) as DotProduct3 as this value can be stored in either a color or alpha channel (the result is just a float, but gets placed into all color channels). This is how it is calculated: SetTexture( ?, NormalMap ); SetTextureStageState( ?, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3 ); SetTextureStageState( ?, D3DTSS_COLORARG1, D3DTA_TEXTURE ); SetTextureStageState( ?, D3DTSS_COLORARG2, D3DTA_SPECULAR ); This is for terrain. The terrain needs to alpha blend different layers onto other layers, so the result alpha needs to store the diffuse alpha channel. The data storage is not finalized, so if moving that around helps, feel free. I can't seem to work my brain around it. Any help is much appreciated.

Share this post


Link to post
Share on other sites
Advertisement
I've got it working with this. But man, what a hack. I'm storing a zero value in texture factor, then blending with that the inverse of lighting:


SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );

SetRenderState( D3DRS_TEXTUREFACTOR, 0x00000000 );

SetTexture( 0, NormalMapTexture );
SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );
SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3 ); // Compute dot product (stored in alpha)
SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); // Normal
SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_SPECULAR ); // Normal Dir

SetTexture( 1, DiffuseTexture );
SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 0 );
SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE); // Combine texture and diffuse
SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE ); // Texture
SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); // Diffuse

SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_ADD ); // Add ambience to DotProduct
SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_CURRENT ); // Dot3
SetTextureStageState( 1, D3DTSS_ALPHAARG2, D3DTA_SPECULAR ); // Ambience

SetTexture( 2, NULL );
SetTextureStageState( 2, D3DTSS_TEXCOORDINDEX, 0 );
SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_BLENDCURRENTALPHA); // blend from current to zero(!) with alpha
SetTextureStageState( 2, D3DTSS_COLORARG1, D3DTA_CURRENT ); // Texture * Diffuse
SetTextureStageState( 2, D3DTSS_COLORARG2, D3DTA_TFACTOR ); // zero!

SetTextureStageState( 2, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE ); // Diffuse alpha
SetTextureStageState( 2, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); // store real alpha



I really hope there's a better way.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!