Sign in to follow this  

Sorting particles around other blended objects

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

I've been trying to figure out the best way to store all the objects in an area, and I've hit on something that I'd like other options on... I'd like to have a terrain-type map with many small billboards for trees to create forests, however I want to have other objects that may be blended move amongst the trees correctly. Picture a ghost floating through the trees, for instance. The ghost itself is an NPC, not a particle of the forest (tree) however since it is translucent, it must be drawn after the trees behind it and before the trees in front of it. There are three ways I've been thinking about doing this... The first way is to promote all the particles to full "game objects." That is, they'd derive from the GameObject class and have a spot in the item database all their own. The problem with this, is that I really don't want to be testing every single particle for collisions or culling or any of that. That should really all be handled by a single particle system object, ideally. The second way is that I would modify my "InFrustum" function to return a wrapper object that would contain the game object and an index. For objects with multiple indicies (particles), they would return many copies of that same object along with an index to use when calling its Draw function. The wrapper would also have an operator< that could be used to sort the list. The reason I don't like this one is that it strays away from the "Spatial Query" nature of the item database making the InFrustum call different from the other calls that return object references. In this case, it seems like I might as well add a Draw() function to the item database itself and forget returning anything. The final way would be that objects that need to draw blended elements would, instead of drawing them, insert references to them in a list of primitives along with position in world coordinates. These primitives would then be sorted and drawn after all the solid objects were on the screen. The only reason I don't like this one is that it separates the code that tests whether the object is in the frustum from the code that sorts it by distance, so the result of comparing its position to the near clipping plane cannot be cached. It also seems fairly involved so I'm not sure if I want to start working on it if it's not the "right" solution. Sorry that was so long ^_^; Any thoughts? =)

Share this post


Link to post
Share on other sites
uhh, you ought to building a queue of stuff to render anyway because some stuff you want to draw front to back [opaque stuff, reduce fill rate use], and some back to front [blended, evil on fill rate]

also, you can consider the delays in switching textures and changing other states...

well anyway, I'd suggest you try to avoid blending for as much of your environment as possible. Is it possible to use only alpha testing for trees? also for grass? or does this not fit with your style at all?

... did I miss something?

Share this post


Link to post
Share on other sites
Thanks for your reply!

I didn't know if it was customary to render through indirection like that, or just sort the objects and then render them in a particular order.

Looking at what I was planning to do, it seems like it would waste time at several stages... The InFrustum function would build up a vector of objects that fall within the visible area... and then return that vector. I'm not sure if that causes it to copy the whole thing or not. Then the calling function would call draw on each object in the vector, some of which would spawn render instructions would would build up in another vector, be sorted, and finally be drawn in the right order.

It seems like I should just forget the InFrustum function and have a Draw function...

But yeah, I should probably just give up and use Alpha testing... I've just always wanted to use 3D hardware to draw sprites BECAUSE of the blending... I like that anti-aliased look. I guess if it were easier, I could always use alpha testing and actual FFAA together... ::ponder::

Share this post


Link to post
Share on other sites

This topic is 4690 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this