help: Blendstate ADDS color from sprites, so black from sprites is NOT drawn [SOLVED]

I have a blank, transparent render-target.
I draw some level geometry on it.

Then I want to super-impose a texture on that geometry, so I switch blend-states
and draw the texture.

BlendState blend = new BlendState
{

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

}

This DOES super-impose the texture, but BLACK disappears, and darker colors fade into transparency.

Is there a way to do this, to super-impose a texture on to non-transparent bits of the render-target, WITHOUT losing any opacity?

Right now you have additive blending, that’s why black doesn’t show. Adding black doesn’t change the result. Assuming the alpha value is 1 (white), the resulting color is now the sum of the background color (destination) + texture color (source). So there is not really any opactiy at all, because all of the background is in the final result, nothing gets blocked. Opacity means that some, or all, of the background gets blocked.

If you set ColorDestinationBlend to InverseDestinationAlpha you should get full opacity, because now the background gets fully blocked (again assuming the alpha is 1).

I’m not sure what you want exactly, but it sounds like you want some sort of semi transparency. which means you want some of the background to show in the final result, but not 100% of it. That means you would need to set ColorDestinationBlend to something that gives you values somewhere between 0 and 1. DestinationAlpha or InverseDestinationAlpha can do that, but only if you use alpha values between 0 and 1, not sure if that’s an option here. You could also try SourceAlpha or InverseSourceAlpha, which means the alpha value from the texture determines how much of the background is showing.

Maybe what you want is too complex for alpha blending. Maybe it could be done in multiple passes, but then it’s probably better to just go for a custom shader solution.

yes, this did it I think:

BlendState blend3 = new BlendState
{

                    ColorBlendFunction = BlendFunction.Add,
                    ColorSourceBlend = Blend.DestinationAlpha,
                    ColorDestinationBlend = Blend.InverseSourceAlpha,
                    
                    AlphaBlendFunction = BlendFunction.Add,
                    AlphaSourceBlend = Blend.Zero,
                    AlphaDestinationBlend = Blend.One,

            }