Blending equations, how to 'remove black'?

Started by
6 comments, last by cozzie 8 years, 4 months ago

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.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

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).


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.

I'm fairly certain that what you want to do cannot be done with blend states alone.

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

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

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)

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me


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.

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 ;)

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

This topic is closed to new replies.

Advertisement