f3d icon indicating copy to clipboard operation
f3d copied to clipboard

Add CPU gaussian sorting

Open Meakk opened this issue 1 year ago • 12 comments

Is your feature request related to a problem? Please describe. When changing the camera orientation, it is required to sort the gaussians by depth in order to have a correct result. Sorting is currently executed on the GPU using compute shaders.
However it's not supported on macOS and the GPU sorting can be slow on low-end GPUs. Let's consider CPU sorting using vtkDepthSortPolyData

Gaussians visualization is done in vtkext\private\module\vtkF3DPointSplatMapper.cxx file, and sorting shader is executed in the method vtkF3DSplatMapperHelper::SortSplats

We probably need to rename the method to SortSplatsGPU and add a new SortSplatsCPU function. The CPU function could be enable on macOS only for now, but it would be useful to have a way to let the user select which backend to use.

Meakk avatar Dec 18 '24 08:12 Meakk

I would like to work on this issue. @Meakk can you provide a bit more context in which scenarios this sorting is happening?

exbluesbreaker avatar Apr 25 '25 22:04 exbluesbreaker

Just visualize any splat file with gaussian splatting, eg:

 ./bin/f3d  ../src/testing/data/small.splat --point-sprites --point-sprites-type=gaussian --scalar-coloring --coloring-array=color --coloring-component=-2 --up=-Y

mwestphal avatar Apr 26 '25 04:04 mwestphal

https://github.com/f3d-app/f3d/blob/9994d18147bcad77d351c3ce936d8f1ecb0043cd/vtkext/private/module/vtkF3DPointSplatMapper.cxx#L92 The gaussians are sorted by depth in camera direction in order to have proper alpha blending.
It's done in a compute shader using a bitonic sort for performance reason. Unfortunately it doesn't work on macOS, and OpenGL ES backends (web and android), so we need a fallback cpu method even if it's slower.

Meakk avatar Apr 26 '25 15:04 Meakk

@mwestphal @Meakk thanks a lot, I think it should be sufficient, I will start on implementation in near time

exbluesbreaker avatar Apr 26 '25 17:04 exbluesbreaker

Hi @exbluesbreaker

As far as I understand you may not have time to work on this, should I unassign it ? :)

mwestphal avatar Jun 18 '25 06:06 mwestphal

Hi @exbluesbreaker

As far as I understand you may not have time to work on this, should I unassign it ? :)

Yes, I think is better to unassign. Apart from me currently being too busy to work on issues, this particular issues definitely required some refinement of OpenGL/computer graphics behavior to understand processing here from my side. So somebody more knowledable is a better candidate to work on it.

exbluesbreaker avatar Jun 18 '25 07:06 exbluesbreaker

No worries on that regard, feel free to comment on it whenever you want to pick it up again :)

mwestphal avatar Jun 18 '25 07:06 mwestphal

@exbluesbreaker are you still interested in this one? I would like to take a look into this issue if you are not interested in this one anymore

AoGao-Kedoka avatar Jun 25 '25 20:06 AoGao-Kedoka

@exbluesbreaker are you still interested in this one? I would like to take a look into this issue if you are not interested in this one anymore

You will need VTK 9.5.0 for this one I'm afraid.

mwestphal avatar Jun 25 '25 20:06 mwestphal

@exbluesbreaker are you still interested in this one? I would like to take a look into this issue if you are not interested in this one anymore

You will need VTK 9.5.0 for this one I'm afraid.

interesting topic though. I'll try to find another one then :(

AoGao-Kedoka avatar Jun 25 '25 20:06 AoGao-Kedoka

@exbluesbreaker are you still interested in this one? I would like to take a look into this issue if you are not interested in this one anymore

You will need VTK 9.5.0 for this one I'm afraid.

interesting topic though. I'll try to find another one then :(

You can take it over. I am currently too busy to contribute, and this particular issue wasn't the best choice for me anyway

exbluesbreaker avatar Jun 26 '25 11:06 exbluesbreaker

FYI I implemented a version of CPU based splat sorting here: https://github.com/f3d-app/f3d/pull/2593

It works for me, and maybe it can be useful to the anyone else experiencing this issue.

avaer avatar Nov 05 '25 21:11 avaer