This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

How to efficiently change a few vertices in a big mesh?

DamciosDamcios Posts: 4Member

Hi,

I am trying to make a map editor for my game.
A medium sized map would have around 320k triagnles.

Two ways I found to modify the mesh at runtime are:
1) Get the ArrayMesh from the MeshInstance, modify it, delete the old surface, add the new one and assign the modified ArrayMesh to the MeshInstance.
2) Create a MeshDataTool from the surface, modify the mesh and commit to surface.

In both cases the final step of assigning/commiting the modified mesh takes most of the total time, close to a hundred ms. I tried running the modify methods in separate threads so it won't block/lag the UI, but that leads to weird glitches where the map flashes in and out of existence or the material is removed from the mesh all of a sudden.

Is there a way to do in place changes to meshes at runtime without having to reload the entire mesh every time?


Tags :

Best Answer

  • MegalomaniakMegalomaniak Posts: 2,580
    edited May 2020 Accepted Answer

    You mean update one or two vertices in the GPU memory? That is what Geometry Shaders would be for, but alas we don't have access to them as of yet. Vulkan renderer might enable that, though I'm not sure if we will get that on the initial release.

    In the meanwhile if you need to just move a few vertices you might be able to maybe do that via the vertex shader. But you wont be editing the mesh topology via vertex shaders.

Answers

  • MegalomaniakMegalomaniak Posts: 2,580Admin

    Create a new MeshInstance and don't remove the old MeshInstance until the new one is ready? Just a thought.

  • DamciosDamcios Posts: 4Member

    Thanks, this did indeed help me to get my UI to run smooth, but the whole solution is far from clean imo. I have to do so much work for every simple change. What if I want to change the position of a single vertex, do I really have to go through the process om copying and adding/committing the entire mesh ? Is there no way to just alter one or more vertices without having to reload the entire mesh?
    I'm pretty new to computer graphics but character models move all the time which means (hundreds of) thousands of vertices change position every frame. How come that can happen very smoothly while changing a few vertices manually takes so much effort?

  • MegalomaniakMegalomaniak Posts: 2,580Admin
    edited May 2020 Accepted Answer

    You mean update one or two vertices in the GPU memory? That is what Geometry Shaders would be for, but alas we don't have access to them as of yet. Vulkan renderer might enable that, though I'm not sure if we will get that on the initial release.

    In the meanwhile if you need to just move a few vertices you might be able to maybe do that via the vertex shader. But you wont be editing the mesh topology via vertex shaders.

  • SIsilicon28SIsilicon28 Posts: 693Moderator

    We won't seem to have geometry shaders in 4.0 either. I've checked the current source code, and it doesn't show any sign of a geometry shader.
    https://github.com/godotengine/godot/blob/6a0473bcc23c096ef9ee929632a209761c2668f6/servers/rendering/rendering_device.h#L54

  • MegalomaniakMegalomaniak Posts: 2,580Admin
    edited May 2020

    To be fair, afaik if you have access to compute and tessellation shaders, they can probably do the same that you could do with geometry shaders but faster. So I wouldn't be surprised if we never see geometry shaders at all.

    edit: hmm, interestingly intels HW is better at GS than nvidias or amds according to this, though it's an old article at this point: http://www.joshbarczak.com/blog/?p=667

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.