If only updating AS could also have good traversal performance.
Hi @novice, FWIW, it is possible to get good traversal performance and use AS updates, but you have to pay attention to how far things move and be careful. The AS update feature is really designed for typical animation, where things move coherently and slowly relative to the whole scene on a per-frame time scale. AS update is not meant to be a fast rebuild when things in your scene change dramatically.
If I understand the thread so far, it sounds like your update of 5% of the spheres might be dramatic position changes? If you are, for example, choosing random locations for these 5% of spheres, then you might be degrading the AS in a very very extreme way. Let me illustrate - if your built AS is producing a structure where you typically have 100 spheres overlapping, and then choose a new random position for 5000 of the spheres… statistically half of them will end up on the other side of the centroid of your scene from their current positions. Their bounding boxes will contain neighbors from the original AS build, so moving them will stretch those bounding boxes out to contain the new random position, and will suddenly overlap a huge swath of the scene. Because primitives are grouped together in the AS leaf nodes, you may actually be ballooning the size of not just 5% of the leaf bounds, but anywhere from 10% to 25% or even perhaps 50% of all your leaf boxes, it really depends on how much grouping was is in the original AS build.
So I might estimate that if you have 100 overlaps in the built AS, then refit after choosing 5000 random positions, you could end up with ~2,500 + 100 overlaps, meaning your new AS might be 26 times worse traversal performance than before, especially in the center of your scene, under the imaginary assumptions I chose here. In reality it might not be that bad, or it might be even worse than my example. Does this make sense?
Okay, so given that, one thing you could try, if you want, is sorting and corresponding your newly chosen positions so they match 1:1 with the closest sphere that’s being deleted or replaced. If you have 100 overlaps on average before the AS update, and you choose 5% new locations, I think that means you could in theory move each of the 5% of new spheres less than 1 sphere radius? Perhaps you can find a way to do this in less time than the difference between an AS build and an AS update. Keep in mind that if you repeat this process, you will need to rebuild your AS eventually, and if you replaced a sphere multiple times, you would probably want to re-do the sorting process against the built AS, rather than the current updated position of the sphere.
FWIW, I’ve done a video for GTC demonstrating some AS update strategies for animated hair. It might give you a sense for how far things can move before the AS traversal performance starts to degrade. Link to the video in this thread: Optix Dynamic Geometry Unstable Rendering FPS - #2 by dhart