Jump to content
  • Advertisement
Sign in to follow this  
schupf

DX9: Shaders and Alpha-Blending

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

Hello,

I have some little questions about DX9 HLSL shaders and Alpha-Blending.

1) If I want to define the opacity per vertex, I guess I use these lines:

device->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
device->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_DIFFUSE);

and to define a vertex with 50% opacity I give him a diffuse color 0x7FFFFFFF. Is this correct? Does the alpha value always have to be the first byte?

2) If I want to use an alpha layer from a texture as alpha source I guess I just have to use this:
device->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
Is this correct?

3) Are the methods of 1) and 2) only related to the fixed function pipeline? I am only using HLSL shaders and I wonder how the float4 return value of the pixel shader is related to these SetTextureStageStates().
Lets say I return a float4(1,0,0, 0.5f) from the pixel shader. Does this mean the alpha value of this pixel is 0.5 regardless whether device->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE); is set?
If yes: Does this mean if I want to use alpha blending based on texture I have to sample the texture in the PS and return the alpha value from the texture in the 4th parameter of the float4 return value of the PS?

Share this post


Link to post
Share on other sites
Advertisement
Are the methods of 1) and 2) only related to the fixed function pipeline?

Does this mean if I want to use alpha blending based on texture I have to sample the texture in the PS and return the alpha value from the texture in the 4th parameter of the float4 return value of the PS?
Yes. Don't use SetTextureStageState when using shaders - instead use samplers and intrinsics like tex2d to replicate the 'fixed fucntion' behaviour that you want.
I am only using HLSL shaders and I wonder ... say I return a float4(1,0,0, 0.5f) from the pixel shader: Does this mean the alpha value of this pixel is 0.5 regardless whether device->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE); is set?[/quote]Yes, the pixel shader takes over that responsibility.

Share this post


Link to post
Share on other sites
As Hodgman already said, SetTextureStageStates is related only to the fixed-function pipeline. It is used in the texturing stage, which is sometimes called rather "configurable" than "fixed".

SetTextureStageStates allows you to configure how should the device apply colors (and separately also the alpha channel) from one of more textures, how they should be combined with the material color etc.
For example you can say something like "Take color from the current texture and multiply it with the material color. For alpha do the same, but add rather than multiply.".
As you can see, that's exacly what you do "manually" in your pixel shader code, with incomparably bigger flexibility - you can fully program it, not just configure.

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!