Jump to content
  • Advertisement
Sign in to follow this  

XNA 4.0 - Confusion about blend states (non-premultiplied alpha)

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

Hello all,

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!!

[attachment=11460:Biosphere 2012-09-26 12-47-06-90.png]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!