multitexturing - stage 0 not showing through

Started by
3 comments, last by SpiralGuru3d 19 years, 6 months ago
hi guys, I've just come back to directx, and in writing some shaders, I've hit a block with the old settexturestagestate stuff! =) I have 2 stages, 0 is an environment map, 1 is a texture that I want to mask the environment map behind it depending on its alpha channel. however, in stage 1, where alpha is anything but solid, I get the stage 1 texture blended with the background - stage 0 is not coming though! here's my setup (shader not relevant I assume): // envmap writes solidly into stage 0 stss( 0, D3DTSS_ALPHAOP, D3DTA_DISABLE ); stss( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); stss( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); stss( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); // surface map blends over the envmap stss( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); stss( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); stss( 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); stss( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE ); srs( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); srs( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); So, in stage 1, for texels with an alpha of 0, I'm not seeing the corresponding texel from stage 0. but shouldn't that be in the dest buffer by that point, having been written in stage 0? thanks -scott
-- Give me a hard copy right there ---
Advertisement
Try:

stss( 1, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
stss( 1, D3DTSS_ALPHAARG1, D3DTA_CURRENT );
stss( 1, D3DTSS_ALPHAARG2, D3DTA_TEXTURE );
stss( 1, D3DTSS_COLOROP, D3DTOP_MODULATE );
stss( 1, D3DTSS_COLORARG1, D3DTA_CURRENT );
stss( 1, D3DTSS_COLORARG2, D3DTA_TEXTURE );

You have to take the current texture (from stage zero) and modulate it with the second texture to achieve multitexturing.
stage 0 alpha disable is illegal. Both color and alpha ops must be present on any stage.

stage 1 colorop should be "selectarg1, current" to leave the color from stage 0. Right now you'll never use stage 0 as you overwrite everything in stage 1.

Stage2 should set alpha and color ops to disable
thanks guys, but that didn't help.

if I modulate with stage 0, I get the envmap showing through on the parts of stage 1 that are opaque. I don't want that, I just want it showing through where the alpha channel is semi-transparent.

I can write a q3a shader for it, but can't get it working in directx =(

Imagine stage 1 is a white square inside a larger grey one. You want the white square to be solide, but the envmap in stage 0 to blend with the grey area.

How do you get that?
-- Give me a hard copy right there ---
I got it working by drawing it in two passes.

As there were only two textures involved, I still don't understand why I couldn't get it going with multitexturing.
-- Give me a hard copy right there ---

This topic is closed to new replies.

Advertisement