Help finding right render blending choice

Started by
1 comment, last by MasterWorks 16 years, 12 months ago
Hello! Here's an easy one for ya... I'm trying to find the best blending choice for my 2D game. Right now I'm rendering particles using this method:
	g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );
	g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
	g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,  D3DTOP_MODULATE );
	g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
But that method looks ugly whenever an orange particle scrolls over a blue object. What would be the best way to render a particle where it gets a transparency similar to ONE-ONE, but otherwise keeps its color? For example, an orange particle scrolling over a blue object still looks orange instead of funky purple? Thanks in advance for the help! [smile]
"The crows seemed to be calling his name, thought Caw"
Advertisement
i could tell you the answer but i rather tell you how i learned the differances between the src and dst blend factors

setup 2 keys 1 for source 1 for blend each time one key is pressed change the value of the source or destination factor and watch how they blend together

i also had it print to the screen what values i was using so i could know them better rather than trying to guess what values were set
You can't have both additive blending and non-additive-blending selectively exactly as you described. One of the problems with additive blending is that certain colors get washed out, and bright backgrounds are a problem (as you have realized). You can use textures that have alpha channels in combination with additive blending but this will just modulate the effect, not create a different effect. The ONE blending method never makes the resulting pixels darker, so oversaturation is pretty much inevitable.

One thing you can look into is using premultiplied alpha in your 32-bit particle texture in combination with your engine. If you use the right render states you can have a single texture with both regular alpha blending and additive alpha blending (which is specified by having brightness values in the RGB channel that exceed the alpha value for that channel), but I'm not sure this is what you're asking for.

Do you have a screenshot of the effect you're looking for? I will add that in my most recent game I decided to use regular alpha blending for the explosion/particle animations because of the very problem you discuss. Making particle systems that look good on a variety of background colors is not as simple as it might seem.

This topic is closed to new replies.

Advertisement