Texture Stage Setup

Started by
1 comment, last by Kest 18 years, 7 months ago
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.
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 ); // NormalSetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_SPECULAR ); // Normal DirSetTexture( 1, DiffuseTexture );SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 0 );SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE); // Combine texture and diffuseSetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE ); // TextureSetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); // DiffuseSetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_ADD ); // Add ambience to DotProductSetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_CURRENT ); // Dot3SetTextureStageState( 1, D3DTSS_ALPHAARG2, D3DTA_SPECULAR ); // AmbienceSetTexture( 2, NULL );SetTextureStageState( 2, D3DTSS_TEXCOORDINDEX, 0 );SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_BLENDCURRENTALPHA); // blend from current to zero(!) with alphaSetTextureStageState( 2, D3DTSS_COLORARG1, D3DTA_CURRENT ); // Texture * DiffuseSetTextureStageState( 2, D3DTSS_COLORARG2, D3DTA_TFACTOR ); // zero!SetTextureStageState( 2, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE ); // Diffuse alphaSetTextureStageState( 2, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); // store real alpha

I really hope there's a better way.
No one has tried to do this?

Even a small suggestion would be great.

This topic is closed to new replies.

Advertisement