Jump to content
  • Advertisement
Sign in to follow this  
robustpotato

DirectX Particles depth/blend problem

This topic is 2783 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

This is a topic Ive seen tonnes of threads about. im still not sure about how to go about solving it.

Ok i have a particle engine. the particle im emitting a smoke texture with alpha channel (just a circular gradient).

the emitter works fine. when i coded it i had no scene. just black background. I knew that i would encounter problems because i was disabling z buffer. but thats the only way i could blend them properly.

so i added some models. And im sure you know what happens. without the z buffer objects draw in the wrong order, with it, the blending doesnt work.

im using this as my blending parameters

device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);


im drawing my models 1st with z buffer on, and then turning it off for the particles.

problem is if there is a model positioned in front of the particles, the particles always draw in front when they should be behind it.

ive read about alpha testing or something but im not really sure how to do it, or what the theory is behind it. Anychance anyone can offer me a solution.

Share this post


Link to post
Share on other sites
Advertisement
Typically for particles and other transparent geometry you want to leave z-testing on, but turn off z-writes. This way the particles don't occlude each other, but can still be occluded by opaque geometry.

Share this post


Link to post
Share on other sites
D3DRS_ZWRITEENABLE = FALSE (turn off writing depth to the z-buffer)
D3DRS_ZENABLE = TRUE (turn on comparing of depth values)

Share this post


Link to post
Share on other sites
Alpha blending:

device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
DrawParticles();
device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);


I dont think you want alpha test on particles, but you can/should use it for
grass, fences...:

device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
device->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
device->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER);
device->SetRenderState(D3DRS_ALPHAREF, 150);//for example cut below alpha value of 150
DrawGrass();

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!