Sign in to follow this  
stu_pidd_cow

Incorrect alpha...

Recommended Posts

I'm using Direct3D 11 and getting some weird results when rendering to a texture. Everything is rendered properly except that the alpha channel is always set to 0. This is how it should look (according to PIX):
[img]http://i80.photobucket.com/albums/j178/stu_pidd/a.png[/img]

and this is the result I'm getting:
[img]http://i80.photobucket.com/albums/j178/stu_pidd/b.png[/img]

First the image was cleared to a white color, which seems to work fine, but everything drawn onto it after that has an alpha of zero. PIX tells me that everything was passed to the pixel shader properly. The pixel shader is really basic (it just returns the color that it was given) and I'm sure there isn't any mistake there.

There's a bit too much code to show here, but does anyone have any idea what could be causing this?

Thanks.

Share this post


Link to post
Share on other sites
Well I would say, and excuse the obviousness of it ... that you are writing alpha = 0 into your texture. You just have to find out where.

What drawing code can you comment out to remove the issue ?

What's the difference between the code that clears the texture to white and the code that draws the lines and numbers ?

Check your shaders and check your blend states maybe. If you can't work it out, you might have to post some code.

Share this post


Link to post
Share on other sites
I have blending set up the way I normally do (which has never caused problems in the past):
[source lang="cpp"]
D3D11_BLEND_DESC omDescBlend;
ZeroMemory( &omDescBlend, sizeof( D3D11_BLEND_DESC ) );
omDescBlend.RenderTarget[0].BlendEnable = true;
omDescBlend.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
omDescBlend.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
omDescBlend.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
omDescBlend.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO;
omDescBlend.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
omDescBlend.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
omDescBlend.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;

ID3D11BlendState* D3DBlendStateBlend = NULL;
D3DDevice->CreateBlendState( &omDescBlend, &D3DBlendStateBlend );

// ...

D3DContext->OMSetBlendState( D3DBlendStateBlend, 0, 0xffffffff );
[/source]

This is one of the lines that are being draw (no texture is applied to it) as it goes into the pixel shader:
[img]http://i80.photobucket.com/albums/j178/stu_pidd/c.png[/img]
And this is the code to the pixel shader:
[source lang="cpp"]
struct VS_OUTPUT
{
float4 position : SV_POSITION;
float4 color : COLOR;
};

float4 psMain( in VS_OUTPUT f ) : SV_TARGET
{
return f.color;
}
[/source]

So if the alpha sent to the pixel shader is 1 and the pixel shader returns the color it was given, shouldn't the returned pixel have an alpha of 1?

The only other thing that I have done differently from what I usually do is that I have depth testing disabled.

Share this post


Link to post
Share on other sites
D3D11 uses independent blend states for writing color and alpha values.
When it comes to colors, the alpha value output from the PS is used as a multiplier based on the SrcBlend state.
How the alpha value is (over)written depends on the SrcBlendAlpha field, which should be set D3D11_BLEND_ONE if you intend to overwrite the existing RT value.

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