Sign in to follow this  
Locust

Partial blending problem

Recommended Posts

Locust    102
Hello

I'm trying to make transparent wall in the front, so the walls in the back are partially visible through it. I'm using Direct x 10 and I have a code which is suppose to do it, but something is not right, because one of the walls in the back is visible and the other one is not. You can see it on the attached screenshot.

[attachment=2915:blending.jpg]

So here is the code setting BlendState:

ID3D10BlendState* pBlendState = NULL;
D3D10_BLEND_DESC blendDesc;
ZeroMemory(&blendDesc, sizeof(D3D10_BLEND_DESC));
blendDesc.BlendEnable[0] = true;
blendDesc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
blendDesc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
blendDesc.BlendOp = D3D10_BLEND_OP::D3D10_BLEND_OP_ADD;
blendDesc.SrcBlendAlpha = D3D10_BLEND_ZERO;
blendDesc.DestBlendAlpha = D3D10_BLEND_ZERO;
blendDesc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
blendDesc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;

pDevice->CreateBlendState(&blendDesc, &pBlendState);
pDevice->OMSetBlendState(pBlendState, 0, 0xFFFFFFFF);
The wall in the front has alpha set to 0.5, all of the others have 1.0.

By the way I'd like to ask, what is the difference between blending and alpha blending? I suspect it's the same thing it just applies to different values, first one to color values, second one to alpha value. Am I right?

To be honest I also don't quite get why SrcBlendAlpha and DestBlendAlpha should be set to D3D10_BLEND_ZERO (I've taken the code from this tutorial [url="http://takinginitiative.net/2010/04/09/directx-10-tutorial-6-transparency-and-alpha-blending/"]http://takinginitiat...alpha-blending/[/url] ) cause if I get it right what BlendOpAlpha does is producing new alpha of a pixel which will be draw to render target, so it will set it to zero. I'm not sure if actually matters, but still I'm curious.

Share this post


Link to post
Share on other sites
Hodgman    51324
[quote name='Locust' timestamp='1307528369' post='4820868']I'm trying to make transparent wall in the front, so the walls in the back are partially visible through it. I'm using Direct x 10 and I have a code which is suppose to do it, but something is not right, because one of the walls in the back is visible and the other one is not. You can see it on the attached screenshot.[/quote]From the picture, it looks like:
*The dark purple quad renders first, filling in the depth buffer and drawing purple over the background.
*The grey quad then renders second, filling in the depth buffer, and blending itself over the background and the purple quad.
*The teal quads draw last, with large parts of them failing the depth-test, as they are behind the grey quad.

To get correct blending results, translucent objects have to be rendered after all opaque objects. Also, if there's more than one translucent objects, you need to draw the furthest one first and the nearest one last.

"Blending" is short for "Alpha blending". It's called that because traditionally the only input was the alpha channel ([i]these days you can configure that though[/i]). Setting SrcBlendAlpha and DestBlendAlpha to D3D10_BLEND_ZERO only matters if you're going to be reading alpha values out of the render-target later ([i]in most cases you don't, so this doesn't matter[/i]).

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