Jump to content
  • Advertisement
Sign in to follow this  
Spa8nky

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

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

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


• Set Opaque RenderStates:





game.GraphicsDevice.BlendState = BlendState.Opaque;
game.GraphicsDevice.DepthStencilState = DepthStencilState.Default;


• Draw all opaque geometry

• Set Transparent RenderStates:




game.GraphicsDevice.BlendState = BlendState.Additive; // Additive blending
game.GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;


• 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:

AdditiveQuad.png


Why are the higher alpha values not very opaque?

Share this post


Link to post
Share on other sites
Advertisement
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

[color="#1C2837"]maybe you're not rendering srgb correct, IMO blending should be done in a gamma correct space
[color="#1C2837"][/quote]
[color="#1C2837"]
[color="#1C2837"]I'm not certain how it would be rendered incorrectly, where should I be checking?
[color="#1C2837"]

[color="#1C2837"]a better lookin solution might be alpha to coverage, it would look like dithering out
[color="#1C2837"][/quote]
[color="#1C2837"]
[color="#1C2837"]I've not come across this before, could you please explain some more?

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

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


game.GraphicsDevice.BlendState = BlendState.NonPremultiplied;

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!