PDA

View Full Version : How to sort 3d particles back to front



Dylan
11-16-2006, 02:55 AM
I want to visualize my particles in a 3D space correctly, from every view. Till now I used gl_Disable(DEPTH_MASK) since the partciles showed weird artifacts when looked from thge opposite direction. Now it looks pretty well, but still you can see some partciles show in front others, when they should be shown behind...

I use GL_POINTS and i'm not sure if it is possible to rrender these points if they were "real" 3D?

ZbuffeR
11-16-2006, 04:26 AM
If you don't use blending, you should keep depth testing.

If you have to use blending, depending on the enumber of particles, you can use bucket sort (http://en.wikipedia.org/wiki/Bucket_sort) .

darkrappey
11-23-2006, 01:13 AM
This is the way I do it:
Create a std::vector that holds all the particles.(in this case it is called particleStorage)


//replace IDSprite with your particle data type.
struct compareByZ {

bool operator() (IDSprite *lhs, IDSprite *rhs) {

return lhs->location.z < rhs->location.z;

}

};



void functionWhereYouSortParticle()
{
sort(particleStorage.begin(), particleStorage.end(),compareByZ());
}I just realized that this will not work if you rotate the camera but it should be a good start!

If you need any help please let me know.