Jump to content

  • Log In with Google      Sign In   
  • Create Account


Incorrect alpha...


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 stu_pidd_cow   Crossbones+   -  Reputation: 1724

Like
0Likes
Like

Posted 11 December 2012 - 11:39 PM

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):
Posted Image

and this is the result I'm getting:
Posted Image

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.

Sponsor:

#2 Gavin Williams   Members   -  Reputation: 646

Like
0Likes
Like

Posted 13 December 2012 - 04:43 AM

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.

#3 eppo   Crossbones+   -  Reputation: 2342

Like
0Likes
Like

Posted 13 December 2012 - 05:13 AM

Make sure to disable alpha-blending if you want to write a pixel shader's output directly into a render target.

#4 stu_pidd_cow   Crossbones+   -  Reputation: 1724

Like
0Likes
Like

Posted 13 December 2012 - 11:36 AM

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:
Posted Image
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.

#5 eppo   Crossbones+   -  Reputation: 2342

Like
3Likes
Like

Posted 13 December 2012 - 12:19 PM

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.

#6 stu_pidd_cow   Crossbones+   -  Reputation: 1724

Like
0Likes
Like

Posted 13 December 2012 - 12:43 PM

Ah, yes that seemed to fix the problem. Thanks a bunch!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS