Jump to content
  • Advertisement
Sign in to follow this  
Locust

Partial blending problem

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 http://takinginitiat...alpha-blending/ ) 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
Advertisement
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.
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 (these days you can configure that though). 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 (in most cases you don't, so this doesn't matter).

Share this post


Link to post
Share on other sites
Yes, that was it. I kinda figured it out already after I've posted. Anyway thanks for help. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!