0
\$\begingroup\$

Today, I have implemented soft particles by rendering them to a separate render target and blending that with the scene, which worked as expected with additive blended particles. In that case I render the particles to a rendertarget while blending them additively, then drawing that rendertarget in fron of the scene while blending additively, works like a charm, I even save some render time if I use a smaller render target. In the case of alpha blended particles, I have a serious issue. First I draw them with a blend state set up for alpha blending:

D3D11_BLEND_DESC bd;
bd.RenderTarget[0].BlendEnable=true;
bd.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
bd.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
bd.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
bd.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ZERO;
bd.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
bd.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
bd.RenderTarget[0].RenderTargetWriteMask = 0x0f;
bd.IndependentBlendEnable=true;

(This is it after reading the GPU Gems article on this subject.)

The render target which I draw them to is cleared by zero for all channels. When I draw this rendertarget to the screen I use a blend state set up for alphablending (it is used for all the 2d images and definetly works well) and I get this: enter image description here It seems as if I have depth writing turned on but I made sure it is turned off. If I draw the rendertarget with these alpha blended particles on it, but with no blending (for the RT) I get this: enter image description here Which seems correct, it just doesn't blend how I want to. On GPU gems there are sure some well described formulas for the blending, but if I set the blendstate descibed there I won't get the results they get. Could someone help me with what I am missing?

\$\endgroup\$
  • \$\begingroup\$ Damn... I have tried changing settings for a whole day, posted this and the next minute I try setting the blendstate's SrcBlendAlpha to D3D11_BLEND_ONE and it works. Though I don't understand why, if anyone describes I am accepting it as an answer. \$\endgroup\$ – János Turánszki Feb 7 '14 at 16:56
0
\$\begingroup\$

because you first blend particle color with black render target use src_alpha

so the image in the render target is multiply alpha yet
when you use the render target you should not multiply alpha again or it will dark the part of the image where alpha is low

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.