[Solved] Custom BlendState Advice

Hey,

I’ve been bashing my head against a wall trying to get custom blendstates working. Google the crap out of it, tried almost all possibilities, wrote out the math… I just can’t get it working.

Details–

  • Doing shadows and lights (also have fx running)
  • The textures are circle gradient light textures, png, white to transparent
  • Trying to draw one light texture and another one light texture on top of it but smaller and have it subtract the alpha.

BlendState.Additive, increases the light strength, great! Now I need something that is the opposite. I’ve been trying to get opposite of BlendState.Additive working but only on the Alpha channel. Essentially BlendState.AlphaSubtractive.

For the life of me I can’t get it to work. Does anyone have a BlendState.Subtractive or BlendState.AlphaSubtractive working?

This is closest I could get to it working but it isn’t.

public readonly static BlendState AlphaSubtractive = new BlendState
{
    ColorSourceBlend = Blend.InverseSourceAlpha,
    AlphaSourceBlend = Blend.InverseSourceAlpha,
    AlphaBlendFunction = BlendFunction.Subtract,
    ColorDestinationBlend = Blend.One,
    AlphaDestinationBlend = Blend.One
};

Edit:
If that was confusing, here is another way to understand what I am trying to do. Essentially, there is a solid white rectangle, I’m trying to subtract the alpha from that rectangle from what the texture drawn over it has as alpha.

Subtract is usually done as:

ColorSourceBlend = Blend.One;
AlphaSourceBlend = Blend.One;
ColorDestinationBlend = Blend.One;
AlphaDestinationBlend = Blend.One;
ColorBlendFunction = BlendFunction.ReverseSubtract;
AlphaBlendFunction = BlendFunction.ReverseSubtract;

Subtract-Alpha is:

ColorSourceBlend = Blend.SourceAlpha;
AlphaSourceBlend = Blend.SourceAlpha;
ColorDestinationBlend = Blend.One;
AlphaDestinationBlend = Blend.One;
ColorBlendFunction = BlendFunction.ReverseSubtract;
AlphaBlendFunction = BlendFunction.ReverseSubtract;

I’ve never seen a useful case for the straight subtract blend-function, only R-subtract.

1 Like

Did either of those work for you? A follow-up would be useful for others.

Thanks AcidFaucent. It worked on my small scale tests but I’m still reworking my RenderSystem to include it in my main game now.

I also made this other one which works for another one of my use cases.

Color Blend with Alpha Subtract

        ColorSourceBlend = Blend.DestinationAlpha,
        AlphaSourceBlend = Blend.One,
        ColorDestinationBlend = Blend.InverseSourceColor,
        AlphaDestinationBlend = Blend.One,
        ColorBlendFunction = BlendFunction.Add,
        AlphaBlendFunction = BlendFunction.ReverseSubtract