Sign in to follow this  
Spa8nky

[XNA] [HLSL] Fading out objects with alpha.

Recommended Posts

I've set up my draw calls so that they:


• Set Opaque RenderStates:


[code]


game.GraphicsDevice.BlendState = BlendState.Opaque;
game.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
[/code]

• Draw all opaque geometry

• Set Transparent RenderStates:


[code]

game.GraphicsDevice.BlendState = BlendState.Additive; // Additive blending
game.GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
[/code]

• Sort alpha blended objects by distance from the camera, then draw them in order from back to front

I have an object that should fade using an alpha value that interpolates from 1.0f to 0.0f over a period of time. However, alpha values that are close to 1.0f are already very transparent and there doesn't appear to be a smooth linear progression of transparency:

[img]http://www.rhysperkins.com/XNA/AdditiveQuad.png[/img]


Why are the higher alpha values not very opaque?

Share this post


Link to post
Share on other sites
maybe you're not rendering srgb correct, IMO blending should be done in a gamma correct space.

a better lookin solution might be alpha to coverage, it would look like dithering out, while you wouldn't get any issues like with transparent objects (e.g. sorting properly, shadow casting/receiving, fog, lighting...)

Share this post


Link to post
Share on other sites
[quote]
[color="#1C2837"][size="2"]maybe you're not rendering srgb correct, IMO blending should be done in a gamma correct space[/size][/color]
[color="#1C2837"][size="2"][/quote][/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"]I'm not certain how it would be rendered incorrectly, where should I be checking?[/size][/color]
[size="2"][color="#1C2837"]
[/color][/size][quote]
[color="#1C2837"][size="2"]a better lookin solution might be alpha to coverage, it would look like dithering out[/size][/color]
[color="#1C2837"][size="2"][/quote][/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"]I've not come across this before, could you please explain some more?[/size][/color]

Share this post


Link to post
Share on other sites
It's because you're using Additive blending. Although Additive has many nice properties (like being order independent, etc...), it's not going to give you the 'fade out' effect you want in this case. Are you using it to fix sorting problems within the object during the fade?

Share this post


Link to post
Share on other sites
[quote]
Are you using it to fix sorting problems within the object during the fade?
[/quote]

Not in this case, no. All my transparent objects are triangle sorted, or quadrangle sorted, depending on the object type.

What method of alpha blending would you recommend?

EDIT:

NonPremultiplied works as intended, yay! :)

[code]
game.GraphicsDevice.BlendState = BlendState.NonPremultiplied;
[/code]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this