Jump to content
  • Advertisement
Sign in to follow this  
Programmer16

Sorting question

This topic is 4836 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'm going to be working on 2D games, and I'm worried about sorting. I've read that I should sort my alpha blended objects, is this true? If so, why? Does the zbuffer not recognize alpha blended pixels? Are there any other sorting problems that I have to worry about? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Yes, you should sort the objects. The only time you don't need to do this is if you are using only additive blending, only subtractive blending or only multiplicative blending. (Any combination and sorting is already required to prevent artefacts).

The z-buffer simply stores the Z value of the pixel rendered at each location. To replace sorting with z-buffering isn't possible because you'd need more than one z value (and colour value) per pixel.

BTW, with 2D games, sorting is usually a lot less of a hassle than with 3D games.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kippesoep
Yes, you should sort the objects. The only time you don't need to do this is if you are using only additive blending, only subtractive blending or only multiplicative blending. (Any combination and sorting is already required to prevent artefacts).

The z-buffer simply stores the Z value of the pixel rendered at each location. To replace sorting with z-buffering isn't possible because you'd need more than one z value (and colour value) per pixel.

BTW, with 2D games, sorting is usually a lot less of a hassle than with 3D games.


I had planned on sorting them, I was just wondering if I should sort by depth, and then by alpha blending, etc.

I wasn't asking if I could replace the z-buffer with sorting, I was just wondering why they say you're supposed to sort alpha blended objects separately (and I suspected it had something to do with the z-buffer).

Thanks for your reply!

Share this post


Link to post
Share on other sites
Quote:
Original post by Programmer16
I had planned on sorting them, I was just wondering if I should sort by depth, and then by alpha blending, etc.


Just sorting them by depth will be good enough and gives perfect results.

Share this post


Link to post
Share on other sites
Assuming you have a significant number of non-blended objects, you should ideally draw the solid objects from near to far (which will get you fill-rate gains thanks to the ZBuffer), then draw alpha-blended stuff sorted from far to near to they blend together properly.

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!