Set MultiMesh visible instance count

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By magicalogic

I am using multimesh to render a lot of grass and everything is working well. The performance is acceptable but I want to have some kind of lod system where when you are far from the grass the visible instances of the multi mesh are lowered.

There are two ways to do that. One is set MultiMesh instance count to a lower number and the other is to set MultiMesh visible instance count to a lower number.

I want to use the latter as it does not force update of the buffer. The problem is if I just set MultiMesh visible instance count to a number, the MultiMesh does not update.

I don’t want to update instance count because it will update the buffer. The reason for that is I am setting the grass strands positions to random locations and I don’t want their locations to be updated when I hide some instances. I just want to hide some strands without rebuilding the MultiMesh.

Any help will be appreciated.

:bust_in_silhouette: Reply From: Inces

None of these will help to make this system, because reducing any instance count will start removing instances from recently created instances, so it will not reduce mesh density. You may need to use instance_custom_data and set ALPHA of given instance to 0 using its shader. You will have to keep track of mesh indexes, and set these indexes invisible following some calculation ( for example every 3rd index, and when You are even more far from the grass - every 2nd index )

Actually godot 4 currently has a bug that’s why visible_instance_count does nothing.
But thanks for your answer.

magicalogic | 2022-10-23 16:34