Texture blending stage help needed

Started by
2 comments, last by Mark Tanner 20 years, 2 months ago
Hi everyone, Stuck with these confusing texture blending stages for a terrain type engine. All I want to do is use the alpha channel from a previous stage''s texture to blend the next. Stage 0: Normal texture, no alpha, repeated/tiled many times (so the texture coordinates are not important). No alpha, just a regular 24 bit tex. Stage 1: Color ''overlay'' texture. Applied to the entire map similar to a lightmap, so textures coords range from 0-1.0f. This texture also contains the alpha I want to use for the next stage. Stage 2: Normal texture, like stage 0 repeated many times, no alpha (24 bits), but the texture should use the the alpha channel contained in texture for stage 1, above, so parts of the texture will be visible and parts not, depending on the alpa channel in stage 1. Obviously I cannot set/include an alpha channel in this stage''s texture since it is tiled many times. What should the colorop/args and the alpha op/args be set to? Thanks for your time! Mark
Advertisement
// Select texture 1,  Set alpha to something...anything.pDev->SetTSS(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);pDev->SetTSS(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);pDev->SetTSS(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);pDev->SetTSS(0, D3DTSS_ALPHAARG1, D3DTA_CURRENT);// Mix texture 2 with color, and select alphapDev->SetTSS(1, D3DTSS_COLOROP, D3DTOP_MODULATE);pDev->SetTSS(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);pDev->SetTSS(1, D3DTSS_COLORARG2, D3DTA_CURRENT);pDev->SetTSS(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);pDev->SetTSS(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);// Mix texture 3 using alpha from last stagepDev->SetTSS(2, D3DTSS_COLOROP, D3DTOP_BLENDCURRENTALPHA);pDev->SetTSS(2, D3DTSS_COLORARG1, D3DTA_TEXTURE);pDev->SetTSS(2, D3DTSS_COLORARG2, D3DTA_CURRENT);pDev->SetTSS(2, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);pDev->SetTSS(2, D3DTSS_ALPHAARG1, D3DTA_CURRENT);// EndpDev->SetTSS(3, D3DTSS_COLOROP, D3DTOP_DISABLE);pDev->SetTSS(3, D3DTSS_ALPHAOP, D3DTOP_DISABLE);  

Note that your color overlay affects only the first texture, and not the third texture. You can get around this in a variety of ways if it's a problem, but the way you've described makes it seems like this might be what you want. This also assumed you didn't want the vertex color/lighting included in any way.

edit: Be aware the many cards can't do multitexturing, and many can only multitexture 2 textures. I think the GeForce2 is limited to 2 textures, and GeForce3 is limited to 4. Radeon cards will be similar. My point being, using 3 textures limits you to GeForce3 cards and above, at which point you're free to use vertex and pixel shader hardware... while the vertex shader may be beyond you (you have to do quite a lot of work yourself), a basic pixel shader isn't any more complex than setting the texture stage states, and makes more things possible, and some things easier.

[edited by - namethatnobodyelsetook on October 4, 2003 11:33:56 PM]
Exactly what I was looking for! - this gives the blending effect I wanted, except like you suspected I want the color overlay to affect the second texture also (stage 2). That''s the only thing left.

You said there are various ways around it -

The color overlay doesn''t need to be in stage1 for this to be possible, but since it''s alpha channel needs to affect texture#2, is there any other way around it, like taking the alpha from the next stage rather than the current active alpha?
(Assuming sticking the overlay in stage 2 makes this any easier).

Luckily you seem to know what effect I am going for (by the way, there is a lightmap in stage3, the last stage but I didn''t mention this since I guess it makes the problem no different).

Nearly there

Compatibility-wise, I know, it requires a GF3. But is this such a problem? Real gamers are not going to be using a GF2 in 2004.
Apart from the lack of features, these cards are quickly becoming too slow anyway.

But I should look into pixel shaders maybe. (but then, we get into that version support on the GF2,3,Radeon,etc.)

Thanks for any follow up!

Mark


Not sure how this came to the top again without a reply or edit, but apparently I never saw your reply until now (and nobody else did either?)

Anyway... If you''re already aiming for the GeForce3 crowd, a pixel shader is the easiest way.

This topic is closed to new replies.

Advertisement