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

This topic is 2686 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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

Why are the higher alpha values not very opaque?

##### 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 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 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 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; 

1. 1
2. 2
JoeJ
20
3. 3
4. 4
frob
12
5. 5

• 10
• 13
• 21
• 13
• 20
• ### Forum Statistics

• Total Topics
632195
• Total Posts
3004703

×