Sign in to follow this  

fixed pipeline texture blending

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

Is it possible with DirectX fixed pipeline multitexturing to get this effect: texture A is blended with texture B using monochrome single channel texture C as a mask? All textures have different mapping sets. I couldn't find any piece of code that does the above. I saw a solution that assumes texture C is an alpha channel of texture B but this is not the way to go.

Share this post


Link to post
Share on other sites
Quote:
Original post by therealremi
Is it possible with DirectX fixed pipeline multitexturing to get this effect:
texture A is blended with texture B using monochrome single channel texture C as a mask?
All textures have different mapping sets.
I couldn't find any piece of code that does the above. I saw a solution that assumes texture C is an alpha channel of texture B but this is not the way to go.

I don't think so, but I could be wrong. The only way I can think of is to use render to texture to blend the monochrome texture and Texture A, then render to another texture to blend the monochrom texture with Texture B (Using inverse blending), then to render those two textures to the render target.

Which is less than efficient [smile]

Assuming I'm right, and it's not possible, is there a reason you can't update one of the first textures to write the monochrome texture into the alpha channel, and then blend them normally?

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Assuming I'm right, and it's not possible, is there a reason you can't update one of the first textures to write the monochrome texture into the alpha channel, and then blend them normally?


This is not possible cause the monochrome texture that is meant to be a mask will be applied with different UV coordinates and has different resolution than the textures that will be blended together.
I know that this would be a trivial task when using pixel shader but for some reasons I try to achieve this effect using texture stages.

Share this post


Link to post
Share on other sites
Texture[0]=(textureA);
Texture[1]=(textureB);
Texture[2]=(textureC);

ColorOp[0]=SELECTARG1;
ColorArg1[0]=TEXTURE;
AlphaOp[0]=SELECTARG1;
AlphaArg1[0]=CURRENT;
ResultArg[0]=TEMP;

ColorOp[1]=SELECTARG1;
ColorArg1[1]=TEXTURE;
AlphaOp[1]=SELECTARG1;
AlphaArg1[1]=CURRENT;

ColorOp[2]=BLENDTEXTUREALPHA;
ColorArg1[2]=CURRENT;
ColorArg2[2]=TEMP;
AlphaOp[2]=SELECTARG1;
AlphaArg1[2]=TEXTURE;

ColorOp[3]=DISABLE;
AlphaOp[3]=DISABLE;

The first problem with this approach is that it makes use of the TEMP register, which is something that needs to be checked through the D3DPMISCCAPS_TSSARGTEMP device cap. Second is that it messes up your result argument state for the first texture stage. That's something that usually isn't touched and I assume wouldn't be reset back to CURRENT in any of your other shaders. So you might need a quick code "hack" that resets it after the draw call.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zipster
The first problem with this approach is that it makes use of the TEMP register, which is something that needs to be checked through the D3DPMISCCAPS_TSSARGTEMP device cap. Second is that it messes up your result argument state for the first texture stage. That's something that usually isn't touched and I assume wouldn't be reset back to CURRENT in any of your other shaders. So you might need a quick code "hack" that resets it after the draw call.
Ahh, I totally forgot about the temp register, I couldn't think of any way to get the colour into the alpha channel [smile]

Share this post


Link to post
Share on other sites
The bad news is that I can't set D3DTSS_RESULTARG in the API I'm using (I don't have direct acess to DirectX functions). I can only call:
virtual bool SetTextureColorOp (DWORD stage, DWORD colorOp)=0
virtual bool SetTextureColorArg (DWORD stage, DWORD argNum, DWORD colorArg)=0
virtual bool SetTextureAlphaOp (DWORD stage, DWORD alphaArg)=0
virtual bool SetTextureAlphaArg (DWORD stage, DWORD argNum, DWORD alphaArg)=0

:(

Share this post


Link to post
Share on other sites
Quote:
Original post by therealremi
The bad news is that I can't set D3DTSS_RESULTARG in the API I'm using (I don't have direct acess to DirectX functions). I can only call:
virtual bool SetTextureColorOp (DWORD stage, DWORD colorOp)=0
virtual bool SetTextureColorArg (DWORD stage, DWORD argNum, DWORD colorArg)=0
virtual bool SetTextureAlphaOp (DWORD stage, DWORD alphaArg)=0
virtual bool SetTextureAlphaArg (DWORD stage, DWORD argNum, DWORD alphaArg)=0

:(

Well, shoot :/

I've done some thinking and luckily it may still be possible:
Texture[0]=(textureA);
Texture[1]=(textureC);
Texture[2]=(textureB);
Constant=0x00000000;

ColorOp[0]=SELECTARG1;
ColorArg1[0]=TEXTURE;
AlphaOp[0]=SELECTARG1;
AlphaArg1[0]=CURRENT;

ColorOp[1]=BLENDTEXTUREALPHA;
ColorArg1[1]=CURRENT;
ColorArg2[1]=CONSTANT;
AlphaOp[1]=SELECTARG1;
AlphaArg1[1]=TEXTURE;

ColorOp[2]=MODULATEINVALPHA_ADDCOLOR;
ColorArg1[2]=CURRENT;
ColorArg2[2]=TEXTURE;
AlphaOp[2]=SELECTARG1;
AlphaArg1[2]=CURRENT;

Share this post


Link to post
Share on other sites
Quote:
Original post by therealremi
I couldn't find any piece of code that does the above. I saw a solution that assumes texture C is an alpha channel of texture B but this is not the way to go.

I'm assuming A and B are colour only without alpha, and C is alpha, and that the resulting alpha in the last stage doesn't matter, because no alpha blending (or testing) is done on the result.

The mentioned solution is presumably:
0. Select Texture A colour
1. Blend Current and Texture B using Texture B alpha

Then you could do something similar just carrying things between stages:
0. Select Texture A colour
1. Select Current colour and Texture C alpha
2. Blend Current and Texture B using Current alpha

Share this post


Link to post
Share on other sites
Thanks all. I know nothing whatever about DirectX but I managed to tweak Zipster's code to get what I want ;-)
The key hack for me was to use a format for C (the mask) which contains alpha only - fortunately DirectX supports such format. Because evidently you can't use RGB intensity as an alpha information in DirectX texture stages.

Share this post


Link to post
Share on other sites
Quote:
Original post by therealremi
The key hack for me was to use a format for C (the mask) which contains alpha only - fortunately DirectX supports such format.
Are you refering to D3DFMT_A8? If so, you might want to be careful - prior to the GeForce 6-series and Radeon 9500's this isn't supported. That is, every piece of hardware where you might be required to use fixed-func blending because pixel shaders aren't available won't allow this trick [wink]

hth
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
Quote:
Original post by therealremi
The key hack for me was to use a format for C (the mask) which contains alpha only - fortunately DirectX supports such format.
Are you refering to D3DFMT_A8? If so, you might want to be careful - prior to the GeForce 6-series and Radeon 9500's this isn't supported. That is, every piece of hardware where you might be required to use fixed-func blending because pixel shaders aren't available won't allow this trick [wink]

hth
Jack


Yes, I meant D3DFMT_A8. Thanks for pointing out this to me.
But this single channel alpha format is just for users, so that they don't get confused when editing a mask. Internally this alpha information can be put into more compatible format (but still only alpha channel will be used).

Share this post


Link to post
Share on other sites

This topic is 3772 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this