• 10
• 9
• 12
• 14
• 14

# Blending equations, how to 'remove black'?

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

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

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].SrcBlendAlpha			= D3D11_BLEND_ONE;
transparentDesc2.RenderTarget[0].DestBlendAlpha			= D3D11_BLEND_ONE;



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

(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 on other sites

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 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 on other sites

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

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

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