Jump to content
  • Advertisement
Sign in to follow this  
Endemoniada

Add Color Blend Mode ?

This topic is 2608 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 guys,

I can't figure out how to set the blend mode so it adds the source to the destination.

So if the background is RGB(128,0,0) and the texture is RGB(64,64,64) the result would be RGB(192,64,64).

Any help would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Which API are you using? The API-agnostic answer is to set the blend-op to 'add', and both of the blend-factors to 'one', resulting in the equation: [font="'Courier New"]new = src*1 + dst*1[/font]

Share this post


Link to post
Share on other sites
D3D11_BLEND_OP_ADD for BlendOp in the blending description if your using direct3d 11.

D3D11_BLEND_DESC blendDesc;
ZeroMemory( &blendDesc, sizeof(blendDesc) );

D3D11_RENDER_TARGET_BLEND_DESC rtbd;
ZeroMemory( &rtbd, sizeof(rtbd) );

rtbd.BlendEnable = true;
rtbd.SrcBlend = D3D11_BLEND_SRC_COLOR;
rtbd.DestBlend = D3D11_BLEND_BLEND_FACTOR;
rtbd.BlendOp = D3D11_BLEND_OP_ADD;
rtbd.SrcBlendAlpha = D3D11_BLEND_ONE;
rtbd.DestBlendAlpha = D3D11_BLEND_ZERO;
rtbd.BlendOpAlpha = D3D11_BLEND_OP_ADD;
rtbd.RenderTargetWriteMask = D3D10_COLOR_WRITE_ENABLE_ALL;

blendDesc.AlphaToCoverageEnable = false;
blendDesc.RenderTarget[0] = rtbd;

d3d11Device->CreateBlendState(&blendDesc, &Transparency);



Direct3d 9 blending:
http://braynzarsoft.mezoka.com/braynzarold/dxblending.php

Direct3d 10 blending:
http://braynzarsoft.mezoka.com/index.php?p=Blending

Direct3d 11 blending:
http://braynzarsoft.mezoka.com/index.php?p=D3D11BLENDING

Share this post


Link to post
Share on other sites

D3D11_BLEND_DESC blendDesc;
ZeroMemory( &blendDesc, sizeof(blendDesc) );

D3D11_RENDER_TARGET_BLEND_DESC rtbd;
ZeroMemory( &rtbd, sizeof(rtbd) );

rtbd.BlendEnable = true;
rtbd.SrcBlend = D3D11_BLEND_SRC_COLOR;
rtbd.DestBlend = D3D11_BLEND_BLEND_FACTOR;
rtbd.BlendOp = D3D11_BLEND_OP_ADD;
rtbd.SrcBlendAlpha = D3D11_BLEND_ONE;
rtbd.DestBlendAlpha = D3D11_BLEND_ZERO;
rtbd.BlendOpAlpha = D3D11_BLEND_OP_ADD;
rtbd.RenderTargetWriteMask = D3D10_COLOR_WRITE_ENABLE_ALL;

blendDesc.AlphaToCoverageEnable = false;
blendDesc.RenderTarget[0] = rtbd;

d3d11Device->CreateBlendState(&blendDesc, &Transparency);



I agree with iedoc, although I would suggest making the additive blending independent from the blend factor. So just go with:

rtbd.BlendEnable = true;
rtbd.SrcBlend = D3D11_BLEND_ONE;
rtbd.DestBlend = D3D11_BLEND_ONE;
rtbd.BlendOp = D3D11_BLEND_OP_ADD;
rtbd.SrcBlendAlpha = D3D11_BLEND_ONE;
rtbd.DestBlendAlpha = D3D11_BLEND_ONE;
rtbd.BlendOpAlpha = D3D11_BLEND_OP_ADD;
rtbd.RenderTargetWriteMask = D3D10_COLOR_WRITE_ENABLE_ALL;

But thats a matter of taste. It always depends on whether you need control over the amount of blending or not.

Share this post


Link to post
Share on other sites
Thanks a lot guys. I should have specified that I'm using D3D9. Between the explanations and those nice links iedoc posted I got it working.

If anyone is wondering all I had to do was this:

d3dDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE);
d3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE);

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!