• Advertisement
Sign in to follow this  

HLSL and alpha

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

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
Advertisement
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
Sign in to follow this  

  • Advertisement