View previous topic :: View next topic |
Author |
Message |
Downsider

Joined: 16 Sep 2008 Posts: 478
|
Posted: Mon Jun 21, 2010 3:40 am Post subject: Depth-sorting particles.. |
|
|
I don't want all my particles being additively blended. And when I have those being additively blended with those not being it looks like complete ass because of lack of depth sorting.
I'm assuming there's probably a huge performance impact when it comes to sorting by depth; is there? |
|
Back to top |
|
 |
Spike
Joined: 05 Nov 2004 Posts: 944 Location: UK
|
Posted: Mon Jun 21, 2010 7:50 am Post subject: |
|
|
depends on your sorting algorithm
if you disable depth writing for it, you can just draw them all with aproximate depth without really caring about actual depth.
this is what fte does - just sorts them into buckets based on distance then goes through the buckets drawing each group as they come. _________________ What's a signature? |
|
Back to top |
|
 |
mh

Joined: 12 Jan 2008 Posts: 910
|
Posted: Mon Jun 21, 2010 8:19 am Post subject: |
|
|
DirectQ does rough depth-sorting of particles by initially grouping them into batches based on the function that spawned them, then depth-sorting those batches. The particle depth-sort goes through the same sorting routine as anything else with alpha, so you get a more-or-less accurate blend not only between particles and other particles, but also between particles and everything else. You'll obviously need to re-engineer your particle system a little for this, of course. _________________ DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines |
|
Back to top |
|
 |
Sajt
Joined: 16 Oct 2004 Posts: 1026
|
Posted: Mon Jun 21, 2010 7:11 pm Post subject: |
|
|
mh wrote: | DirectQ does rough depth-sorting of particles by initially grouping them into batches based on the function that spawned them, then depth-sorting those batches. The particle depth-sort goes through the same sorting routine as anything else with alpha, so you get a more-or-less accurate blend not only between particles and other particles, but also between particles and everything else. You'll obviously need to re-engineer your particle system a little for this, of course. |
What about smoke trails? _________________ F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe. |
|
Back to top |
|
 |
mh

Joined: 12 Jan 2008 Posts: 910
|
Posted: Mon Jun 21, 2010 10:04 pm Post subject: |
|
|
Sajt wrote: | mh wrote: | DirectQ does rough depth-sorting of particles by initially grouping them into batches based on the function that spawned them, then depth-sorting those batches. The particle depth-sort goes through the same sorting routine as anything else with alpha, so you get a more-or-less accurate blend not only between particles and other particles, but also between particles and everything else. You'll obviously need to re-engineer your particle system a little for this, of course. |
What about smoke trails? |
Yeah, it does those too. They all come from R_RocketTrail but it groups by type within that. A trail in R_RocketTrail is actually a quite short thing, so reasonably decent sorting is obtainable.
Typically there might be just over 100 groups to be sorted in a typical trail/explosion combination, but that's not too bad. There's no need to sqrt the distances for doing the comparison op, and if you justuse qsort rather than trying anything fancy it all works out fine. _________________ DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines |
|
Back to top |
|
 |
Downsider

Joined: 16 Sep 2008 Posts: 478
|
Posted: Tue Jun 22, 2010 4:34 am Post subject: |
|
|
From what I'm getting here, I'll have to do the following:
When creating particles, put them in groups.
Sort groups by distance.
In those groups, sort each particle in the group by distance as well.
Go down the sorted list of groups..
Render each particle in the group based upon the previously sorted particles.
Works? =D |
|
Back to top |
|
 |
mh

Joined: 12 Jan 2008 Posts: 910
|
Posted: Tue Jun 22, 2010 9:06 am Post subject: |
|
|
Nah, I don't bother with the sorting each particle in the group by distance part. It's rough but it works. The setup goes something like this:
Code: | void Particle_SpawnFunc (vec3_t org, int count, etc)
{
particle_type_t *pt = R_NewParticleType ();
VectoryCopy (org, pt->origin);
for (i = 0; i < count; i++)
{
particle_t *p = R_NewParticle (pt);
}
} |
Then depth-sort on pt->origin.
Have a look at my code, it should be clearer there. _________________ DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines |
|
Back to top |
|
 |
Spike
Joined: 05 Nov 2004 Posts: 944 Location: UK
|
Posted: Tue Jun 22, 2010 9:45 am Post subject: |
|
|
if the particles are close enough and have compatible blend modes, they don't really need to be sorted if depth writing is off.
its only really when the blend mode is destructive that they need sorting.
If the only particles on screen are additive rocket-explosion particles, then sorting isn't needed.
Tbh though, whatever lets you batch particles best will give better speedup than would be lost from sorting them. _________________ What's a signature? |
|
Back to top |
|
 |
Downsider

Joined: 16 Sep 2008 Posts: 478
|
Posted: Tue Jun 22, 2010 5:29 pm Post subject: |
|
|
The problem resides in my own particle effects, where it's several smokepuffs being emitted in a radial pattern around an additively blended yellowish explosion particles in the center.
The smokepuffs that end up behind it show as if they were in front of it.
I think I'd have to sort by depth for every particle in that situation, wouldn't you agree? |
|
Back to top |
|
 |
|