Jump to content
  • Advertisement
Sign in to follow this  
cozzie

Blending equations, how to 'remove black'?

This topic is 958 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

Hi all,

I'm trying to work my way through exercising with D3D11 blending.

In this case using blending states (not directly in the shader) and without using the alpha component.

 

I've created the spreadsheet below to make sure I understand the equations.

 

blending_equations.jpg

 

My questions:

1. Do you see any issues/ errors in the sheet?

2. I have the following challenge:

 

- render objects to the backbuffer

- render a cylinder with an animated texture

-- the animated texture has a large part of 'black' pixels

- I want the black pixels not to be rendered using blending (keep the 'dest'/  pixels on backbuffer the same), all others I want to stay the same

(not blended/ multiplied with the pixels already on the backbuffer.

 

So far I've tried this:

	transparentDesc2.RenderTarget[0].BlendEnable			= true;
	transparentDesc2.RenderTarget[0].SrcBlend			= D3D11_BLEND_ZERO;
	transparentDesc2.RenderTarget[0].DestBlend			= D3D11_BLEND_INV_SRC_COLOR;
	transparentDesc2.RenderTarget[0].BlendOp			= D3D11_BLEND_OP_ADD;

	transparentDesc2.RenderTarget[0].SrcBlendAlpha			= D3D11_BLEND_ONE;
	transparentDesc2.RenderTarget[0].DestBlendAlpha			= D3D11_BLEND_ONE;
	transparentDesc2.RenderTarget[0].BlendOpAlpha			= D3D11_BLEND_OP_ADD;
	transparentDesc2.RenderTarget[0].RenderTargetWriteMask		= D3D11_COLOR_WRITE_ENABLE_ALL;

The result is that the black pixels are indeed removed, but the color of the remaining pixels in the animated textures, are (I think) multiplied by the pixels already on the backbuffer, in this case the background color (after clearing the backbuffer).

 

blending_nok.jpg

(the non-black of the texture is dark blue/ greenish)

 

Can someone help me in the right direction to achieve my goal?

Any input is appreciated.

Edited by cozzie

Share this post


Link to post
Share on other sites
Advertisement

Can't you just do this by discarding completely black pixels in the pixel shader? Or are you trying to do it only with blendstates for some reason?

 

I'm not sure blendstates allow you to express the sharp discontinuity that you want at (0x0, 0x0, 0x0) -> (0x1, 0x0, 0x0).

Share this post


Link to post
Share on other sites


transparentDesc2.RenderTarget[0].SrcBlend = D3D11_BLEND_ZERO;

At least replace D3D11_BLEND_ZERO here with D3D11_BLEND_ONE or D3D11_BLEND_SRC_COLOR, depending on your needs.

Share this post


Link to post
Share on other sites
Thanks all.
I'm trying to achieve it without black pixel rejects in then PS.

After some more/ better reading, I think I might have to disable depth writing before drawing the object with the animated texture. I'm gonna play around with this and let you know how it works out.

@vstrakh: thanks and clear, srcBlend ZERO will ignore the whole animated texture object

Share this post


Link to post
Share on other sites

Fixed it, it was indeed the Z writing I needed to disable.

The result is now as aimed (although minimally different from the books example, but that's probably because of the different cylinder size, texcoords or something).

 

blending_ok.jpg

 

For blending src and dest I now used BLEND_ONE, combined with 'ADD'.

 

- render everything other then the cylinder 'normal' (Z-write enabled)

- disable Z writing through setting a depthstencil state

- render the cylinder with animated texture

- enable Z write again (Z testing and reading is left alone)

Edited by cozzie

Share this post


Link to post
Share on other sites


Fixed it, it was indeed the Z writing I needed to disable.

Perhaps you wanted something different (though maybe you're already satisfied with results).

You're not just adding "plasma" color to scene, since you've set D3D11_BLEND_INV_SRC_COLOR factor for destination color.

Means it's not glowing, but rather filtering light coming through "smoke".

As cylinder rotated, triangles will be drawn in different front/back order, and it might be noticeable, since alpha blending is not commutative.

 

So if that cylinder is not glowing instance, but sort of "energy shield" - hollow inside, only visible as thin shell, then it might be better to draw it twice, changing face culling in between. So first back triangles drawn, then front triangles. This trick works good on convex objects.

Share this post


Link to post
Share on other sites
Thanks, I understand what you mean and will try it out tonight.

It'll probably resemble more with the picture in the book that way ;)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!