HLSL - Additive blending

Started by
1 comment, last by CSharpCoder 5 years, 4 months ago

I have the following HLSL technique. I want to do additive blending on RGB (color) only, not alpha. The alpha should just override the underlying alpha. This also does additive blending on alpha.

How do I modify it to only do additive blending on RGB?
 


technique AdditiveTest
{
    pass Pass1
    {
        AlphaBlendEnable = FALSE;
        VertexShader = compile vs_3_0 AdditiveVertexShader();
        PixelShader = compile ps_3_0 AdditivePixelShader();
        SrcBlend = ONE;
        DestBlend = ONE;
    }
}

 

Advertisement

You need to set a BlendState for this, the following code adds the two colors together and calculates alpha as source * 1 + destination * 0, the result will of course be source.


BlendState additiveColorBlendState = new BlendState
{
    ColorBlendFunction = BlendFunction.Add,

    ColorSourceBlend = Blend.One,
    ColorDestinationBlend = Blend.One,

    AlphaSourceBlend = Blend.One,
    AlphaDestinationBlend = Blend.Zero,

    AlphaBlendFunction = BlendFunction.Add
};

 

This topic is closed to new replies.

Advertisement