Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8136095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:38:28+00:00 2026-06-06T10:38:28+00:00

Short Version: I’m looking for a technique to keep nearly-sorted data in nearly-sorted order

  • 0

Short Version:

I’m looking for a technique to keep nearly-sorted data in nearly-sorted order over time, despite the values changing slightly.

Here’s the scenario:

In the world of 3D graphics, it is often beneficial to order your objects from front-to-back before drawing. As your scene changes or your view of the scene changes, this data may require re-sorting, however it will usually be very close to the sorted order (i.e. it won’t change very much between frames). It’s also not critical that the data be exactly in sorted order. The worst thing that will happen is that a polygon will be rendered and then completely hidden. It’s a small performance hit, but not the end of the world.

With this in mind, is it possible to sort the data once ahead of time and then apply a minimal patch to the data once per frame to ensure that the data stays mostly sorted? In this scenario, the data would be considered mostly sorted if most of the objects were in ascending order. That is, 1 object that is 10 steps away from it’s proper location is much better (10x better) than 10 objects that are 1 step away from their proper location.

It’s also worth noting that the data could continue to be patched on a semi regular basis, as the data is typically rendered 30 times per second (or so). As long as the calculation was efficient, it could continue to be done over time until the changes stop and the list was completely sorted.

Existing Idea:

My knee jerk reaction to this problem is:

  1. Apply an n log n sort to the data when it is loaded, and on large changes (which I can track pretty easily).

  2. When the data starts changing slowly (e.g. when the scene is rotated), apply a single (linear) pass of some sort on the data to swap backwards neighbors and try to maintain sort order (I think this is basically shell sort – maybe there is a better algorithm to use for this single pass).

  3. Keep doing a single pass of the partial sort each frame until the changes stop and the data is completely sorted

  4. Go back to step 2 and wait for more changes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T10:38:32+00:00Added an answer on June 6, 2026 at 10:38 am

    From your description it sounds like the sort order changes without you changing the data itself. E.g. you change the camera, so the sort order should change, even though you have not modified any polygons.

    If so, you can’t detect sort order changes directly when they happen. If you could, I would create buckets for the list of polygons, and resort buckets when ‘enough’ polygons in that bucket have been touched.

    But I’m betting your system doesn’t work that way. The sort is determined by the view port. In that case polygons at the front of the sort matter much more than ones at the end.

    So I’d segment the poly list into fifths or something like that. Front to back, so that the first fifth is the part closest to the camera. I’d completely sort the first segment every frame. I’d divide the second segment into sub segments – say 5 again – and sort each sub segment every frame, such that every 5 frames the second fifth is completely sorted. segment the third through 5th segments into 15 sub segments and do those every 5 frames each such that the rest get sorted completely every 75 frames. At 60 fps you’d have the display list completely resorted a little more than once per second.

    The nice thing about prioritizing the front of the list, is
    1. Polys at the front are going to tend to be larger on the screen, and will fail depth test more often. Bad orders at the end of the list will more often than not just not matter.
    2. the front of the list is more susceptible sort changes due to camera changes.

    Also chose those segment ranges with a little overlap, so that polygons can migrate to their correct segment in 2 sorts.

    @OP: Thinking about it a little more. You are probably more concerned with having the sorting cost stay bounded – instead of exploding with scene complexity. Especially since a very complex scene should – surprisingly – be less susceptible to bad sorts ( because generally the polys get smaller ).

    You could define a fixed amount of sorting you are willing to do per frame. Use say 50% of the budget for as much of the front of the list as you can afford, 25% of the budget to sort the next region and 25% to spend equally on the rest.

    Say you budget 1000 polys sorted per frame, and you have 10000 polys in the scene. Sort the first 500 polys every frame. Sort 250 polys every tenth frame for the next region. So 501-750 on frame 1, 751-1000 on frame 2 etc. And then divide the rest of the list into 250 frame segments and sort them round robin for however many frames you need to.

    This keeps the sorting cost fixed s the scene gets more and less complex, and it is easy to tune, you just adjust the sorting budget to what you can afford.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short version: assuming I don't want to keep the data for long, how do
Short Version For those who don't have the time to read my reasoning for
Short Version I'm currently looking into an issue with MySQL collations and how they
Super-short version: I solved this problem when I was nearly finished writing the question.
Short version: What is the cleanest and most maintainable technique for consistant presentation and
Short Version : I'm using a 64bit dll (system.data.sqlite) in an Asp.net MVC app
Short Version Is there a way to have visually represented user re-sizable data ranges
Short version: What's the best way to override dict.keys() and friends to keep myself
Short version : echo testing | vim - | grep good This doesn't work
Short version: I have a similar setup to StackOverflow. Users get Achievements. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.