particle transparency

Started by
9 comments, last by Mijin 18 years, 4 months ago
Hey Im making this particle system and Im pretty much done except for one problem. I dont know how to set it so that the background color of the particle picture isnt rendered. My particles are circles and I dont rly want black squares surrounding each one. I looked through my directX book and couldnt find anything, and Id look in the msdn reference except I rly have no clue what to search for.
Advertisement
Given you are using a file format that supports transparency/alpha channels you can just set the appropriate render states so that the alpha blending can be enabled and then destination can be alpha blended with the source. Also note that you will need to render the solid objects first and then the transparent objects.

c++ example
pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);


C# example
Device.RenderState.SourceBlend = Blend.SourceAlpha;Device.RenderState.DestinationBlend = Blend.InvSourceAlpha;Device.RenderState.AlphaBlendEnable = true;


I hope this helps.
Take care.
yea thanks I found an old post that suggested that but it still isnt working. I loaded the texture with the Ex function and specified the background color as the colorkey...
^bump

it kind of works, but I get flashes of black where its supposed to be transparent.
Sounds like everything's working in your program, but you need to inspect the texture itself... When you say 'flashes of black', do you mean there's little pieces of black around your particles? If so, examine your particle texture's alpha channel carefully in your paint program... I'm suspecting you'll find parts of the black area of your texture are going to appear masked along with your main round particle image. Edit your texture and clean up its alpha channel, and see if that gets rid of the black anomalies.

Hope that helps!
"The crows seemed to be calling his name, thought Caw"
yes I have that problem but its subtle and not whats happening. Whats happening is most of the particles look like circles, with nothing around them, and then sometimes when Im looking at one I see the black corners appear for a second.
Is ZWRITEENABLE render state turned OFF?

It needs to be OFF for sprite-style particles.
I had it turned off but then I get all these weird effects where particles that are farther away appear in front so I turned it back on. If I turn it back off, how do I fix that? is sorting them the only way?
But you've got alpha blending ON...surely the order that the particles are drawn won't make a difference?

Maybe a screenshot to clarify what the remaining problem(s) are...
The order in which they are drawn will make a difference. To be totally correct yes you would need to sort the particles by depth, often however you can get away with approximations like just sorting the emitters by depth. For sorting you might want to look into radix sort, have a look here for example.

This topic is closed to new replies.

Advertisement