Inside3D!
     

Depth-sorting particles..

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Engine Programming
View previous topic :: View next topic  
Author Message
Downsider



Joined: 16 Sep 2008
Posts: 478

PostPosted: Mon Jun 21, 2010 3:40 am    Post subject: Depth-sorting particles.. Reply with quote

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
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Mon Jun 21, 2010 7:50 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
mh



Joined: 12 Jan 2008
Posts: 909

PostPosted: Mon Jun 21, 2010 8:19 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Sajt



Joined: 16 Oct 2004
Posts: 1026

PostPosted: Mon Jun 21, 2010 7:11 pm    Post subject: Reply with quote

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
View user's profile Send private message
mh



Joined: 12 Jan 2008
Posts: 909

PostPosted: Mon Jun 21, 2010 10:04 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Downsider



Joined: 16 Sep 2008
Posts: 478

PostPosted: Tue Jun 22, 2010 4:34 am    Post subject: Reply with quote

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
View user's profile Send private message
mh



Joined: 12 Jan 2008
Posts: 909

PostPosted: Tue Jun 22, 2010 9:06 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Tue Jun 22, 2010 9:45 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Downsider



Joined: 16 Sep 2008
Posts: 478

PostPosted: Tue Jun 22, 2010 5:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Engine Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group