about "AlphaToCoverage"

Started by
3 comments, last by GL3336563 9 years, 9 months ago

When i use AlphaToCoverage blendstate i get some bug . I found the alpha texture edge has white edge,like leaf.

finally I find when the alpha texture render without Opaque blendstate the texture's has one black rectange with the
valid pixel in other program. But In my program when I use opaque blendstate it's don't have that black rectange it's whole white. So i think if I can solve why the texture lost the black Rectange.I can solve this problem.
Who konw this is Why? Thank you very much.
I use WPF render host with SharpDX(DirectX11) do this.

var atcDesc = new BlendStateDescription
{
AlphaToCoverageEnable = true,
IndependentBlendEnable = false,
};
atcDesc.RenderTarget[0].IsBlendEnabled = false;
atcDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
AlphaToCoverageBS = new BlendState(device, atcDesc);

I found AlphaToCoverage Can't render correctly in a RenderTaget. It is only correct render in the swapchain directly.So It means I can't uese any PostProcess Effect like HDR. Who know if this problem can solve.

Advertisement

Off the top of my head, that tends to happen when your leaves (or whatever else you have that uses a transparent texture) are rendered out of order, meaning that the edges of the leaves will blend with the background colour of the wrong object (for example your skybox instead of what is immediately behind them).

To solve this you'll have to either ensure all your transparent objects are drawn back-to-front and that your non-transparent objects are drawn in a previous pass, separate from the transparent ones (or you can sort them all but that generally wastes some more time). Another approach is to skip alpha blending and instead just clip pixels whose alpha value is below some threshold from your pixel shader. That looks blockier up close, but since you have no alpha blending and just overwrite pixels with the ones closer to the camera, you don't need to sort all your foliage, which can be a lot of overhead if you have plenty of it.

I think it is related how texture is created. Make sure that your "background" color is matching with leaves/branches color on edges

Look at this tutorial for nice explanation: http://www.cgtextures.com/content.php?action=tutorial&name=alphabg


Off the top of my head, that tends to happen when your leaves (or whatever else you have that uses a transparent texture) are rendered out of order, meaning that the edges of the leaves will blend with the background colour of the wrong object (for example your skybox instead of what is immediately behind them).

He's using AlphaToCoverage, so the order shouldn't matter. It should be like alpha testing, except for a MSAA render target.

I agree with belfegor that it's probably an issue with your texture. The "green-ness" of your leaves needs to extend all the way through the texture, even the transparent bits.

 

Off the top of my head, that tends to happen when your leaves (or whatever else you have that uses a transparent texture) are rendered out of order, meaning that the edges of the leaves will blend with the background colour of the wrong object (for example your skybox instead of what is immediately behind them).

 
He's using AlphaToCoverage, so the order shouldn't matter. It should be like alpha testing, except for a MSAA render target.
 
I agree with belfegor that it's probably an issue with your texture. The "green-ness" of your leaves needs to extend all the way through the texture, even the transparent bits.

 

Thanks for the whole reply! When I use winform(we usually use it) instead of WPF(use D3DImage) it's

Normal. I use the same code only different renderHost. you can see the difference. I guess WPF is

only support DX9 so When I render the DX11 rendertarget then I convert it to DX9 texture, Maybe this

process lost someting "AlphaToCoverage" need. But i don't know what it is. So my Editer with WPF can't use

this tech now,only can use alphablend. May be this problem can't solve in WPF Maybe can solve. if

someone konw,please help me. Thanks very much. My english is Bad! Sorry...

This topic is closed to new replies.

Advertisement