Sign in to follow this  
paulshady

HLSL and alpha

Recommended Posts

Quick question heres my pixel shader:
PS_OUTPUT main_PS( VS_OUTPUT IN )
{
	PS_OUTPUT OUT;
	OUT.color.rgb = tex2D( waterTexture, IN.texcoord0.xy );
	OUT.color.a = 0.5f;

	return OUT;
}

and heres some my cpp code:
Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); 
Device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
Device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);

I thought the point of shaders was to avoid the renderstate calls and stuff like that. I'm pretty sure setting D3DRS_ALPHABLENDENABLE to true is necessary regardless, but I still have to set the src and dest blend? PS: Please don't insist I should use effects. ;) thanks in advance!

Share this post


Link to post
Share on other sites
RenderStates allow you to set settings for more than one part of the Graphics Pipeline.
If you have a look at this simple diagram of the pipeline, Vertex Shaders and Pixel Shaders only replace the "Vertex Processing", and "Pixel Processing" parts of the pipeline. Any RenderStates that affect other parts of the pipeline are still functional.
This would include Alphablending settings (From the "Pixel Rendering" part of the pipeline), and operations for the "Geometry Processing" part, such as CullMode and FillMode.

The Effect iterface merely encapsulates these settings, and sets them for you.

Hope this helps.

Share this post


Link to post
Share on other sites
Incidentally any states that can be set with SetRenderState can also be hardcoded in your shader (with the D3DRS_ prefix removed). e.g.: To setup render state for a particle system:


technique SimpleSprite
{
pass p0
{
VertexShader = compile vs_3_0 SimpleSpriteVS();
PixelShader = compile ps_3_0 SimpleSpritePS();
POINTSPRITEENABLE = TRUE;
ALPHABLENDENABLE = TRUE;
SRCBLEND = SRCALPHA;
DESTBLEND = ONE;
ZWRITEENABLE = FALSE;
ALPHATESTENABLE = FALSE;



}
}



Share this post


Link to post
Share on other sites

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