Members - Reputation: 580
Posted 26 September 2012 - 05:58 AM
I am currently having a problem understanding XNA 4.0's blend states. After a few hours of experimenting and playing around, trying to achieve additive blending (using BlendState.Additive) on a polygon rendered using an Effect, I came to realize XNA 4.0 now uses pre-multiplied alpha.
After reading various websites, I found the solution to my problem, and have now got additive blending working properly :
[source lang="csharp"]BlendState state2 = new BlendState();state2.AlphaSourceBlend = Blend.SourceAlpha;state2.ColorSourceBlend = Blend.SourceAlpha;state2.AlphaDestinationBlend = Blend.One;state2.ColorDestinationBlend = Blend.One;[/source]
I am now trying to get the alpha to saturate whilst retaining the same colour : essentially additive alpha, and constant/replace colour. I tried using BlendFunction.Max, but for some reason, it does not seem to do anything at all.
In other words, by layering an alpha of 0.5 with an alpha of 0.5, I should be getting a final value of 1.0, which I then want to use as the alpha for my final colour : the new colour should fully replace the previous fragment (opaque).
I would have thought that this would have achieved the effect :
[source lang="csharp"]BlendState state3 = new BlendState();state3.AlphaBlendFunction = BlendFunction.Max;state3.AlphaSourceBlend = Blend.One;state3.ColorSourceBlend = Blend.SourceAlpha;state3.AlphaDestinationBlend = Blend.One; state3.ColorDestinationBlend = Blend.One;[/source]
Unfortunately, nothing happens at all. Basically, the effect I am trying to achieve is painting with alpha (to saturation/ additive), and replace/splat the colour. Instead I get this (notice the darker lines between the two green blobs when in fact they should be brighter)
Thanks in advance for your help!!