I was trying to generate procedural meshes each frame with compute shaders, but the slowness of reading to CPU struck me, so I solved that by storing vertex data into a texture, so I can have compute generatec dynamic mesh without problems (maybe a few unused triangles)
Keep in mind since this uses compute shaders, will not work on all hardware, and I only tested in two setups: Linux with Intel i5-1245U onboard graphics and Windows with GTX 1650.
In my main project i'm working on (4D Game) I have working alternatives that doesn't use compute shaders, even if they are inefficient it's better to give not the best performance than a error screen.
And finally I want to apologise for your stress trying run untested crappy patched random reddit linked github code.
This demo shows how it is possible to generate millions of vertices of procedural geometry using compute shaders, without requiring a single CPU read.
It works by creating a Texture2DRD texture with a RGBA float as-is format, it means I can store any float values on this texture, the compute shaders then proceed to calculate the torus Signed Distance Field (found on https://iquilezles.org/articles/distfunctions/) over the span of the grid (128*128*128), when a cell is found to contain the surface, it outputs the corresponding quads, writing their vertex positions and normals on the texture (1024*1024). Then a normal .gdshader takes this texture and using texelFetch (to prevent sampling issues) gathers the correct position and normal it should have. the key thing here is: NO CPU READS, since that would degrade the performance to unaceptable amounts.
There are some caveats, first this only works on 4.2 beta 1 because of the only way of doing this without a viewport is using the new Texture2DRD (Also the viewport would not have the floating point format so idk if is feasible either), another problem with this approach is somewhat high memory usage (One texture per mesh like this) and that the mesh needs to have as many vertices as the maximum that will be ever produced to prevent glitching, leaving a lot of vertices that read (0,0,0,0) pixels and just create overhead.
After scraping the entire internet and Godot issues to find how compute shaders work, this is my attempt at Conway's Game of Life. if you want to look at the source code here it is (in C#) https://github.com/erickweil/GodotTests
I'm migrating a slice based 4D Game I was developing in Unity, and two days in managed to get the first shader working and I'm already with a 4D rotating cube.
In all definitions the game VIEW is 3D, but the world and physics isn't, it's like if you could play 2d mario in a 3d world, where the 2d plane he sits in rotate to allow movement in the third axis and see the rest oc the scenario otherwise hidden.
Things that made me think twice:
I choose C# because 90% of my logic isn't Unity dependent at all, so I hope it will be minor refactorings. But webGL builds doesn't work yet when using C#, so I'm limited to Desktop
Because I choose C# and my use case involves generating procedural Mesh Data, I'm worried about performance issues with interop and Marshaling, maybe the 'game mode' would lag only at start but the 'editor mode' will be just too slow (should I lose all hopes in webGL and use Compute shaders and/or C++?)
I found that yet Vector4 is supported, when passing data to ArrayMesh it expects a Godot.Variant, and a array of Vector4 aren't accepted, So I needed to do a c# marshaling hack to convert it to a Span of floats before sending (Almost all other types are accepted as Variant, seems like whoever added Vector4 to the engine just forgot this)
This one is a Unity migration minor issue, components in Vector2,3,4 are capitalised (v.X ) unlike Unity. Also took a bit of googling to find that Godot's Projection is equivalent to Unity's Matrix4x4
I should say if you want to start in game development, just go with a engine, like Unity3D that allows to the same game be on Android, Iphone, Deskto, Mac, HTML5, etc...
The language is c#, but is not that hard to move on.
I was trying to generate procedural meshes each frame with compute shaders, but the slowness of reading to CPU struck me, so I solved that by storing vertex data into a texture, so I can have compute generatec dynamic mesh without problems (maybe a few unused triangles)
Keep in mind since this uses compute shaders, will not work on all hardware, and I only tested in two setups: Linux with Intel i5-1245U onboard graphics and Windows with GTX 1650.
In my main project i'm working on (4D Game) I have working alternatives that doesn't use compute shaders, even if they are inefficient it's better to give not the best performance than a error screen.
And finally I want to apologise for your stress trying run untested crappy patched random reddit linked github code.
I was just experimenting with the .NET SDK thingy and forgot this setting. It should work on 6.0
(Source on https://github.com/erickweil/GodotTests/tree/v4.2-beta1)
This demo shows how it is possible to generate millions of vertices of procedural geometry using compute shaders, without requiring a single CPU read.
It works by creating a Texture2DRD texture with a RGBA float as-is format, it means I can store any float values on this texture, the compute shaders then proceed to calculate the torus Signed Distance Field (found on https://iquilezles.org/articles/distfunctions/) over the span of the grid (128*128*128), when a cell is found to contain the surface, it outputs the corresponding quads, writing their vertex positions and normals on the texture (1024*1024). Then a normal .gdshader takes this texture and using texelFetch (to prevent sampling issues) gathers the correct position and normal it should have. the key thing here is: NO CPU READS, since that would degrade the performance to unaceptable amounts.
There are some caveats, first this only works on 4.2 beta 1 because of the only way of doing this without a viewport is using the new Texture2DRD (Also the viewport would not have the floating point format so idk if is feasible either), another problem with this approach is somewhat high memory usage (One texture per mesh like this) and that the mesh needs to have as many vertices as the maximum that will be ever produced to prevent glitching, leaving a lot of vertices that read (0,0,0,0) pixels and just create overhead.
HP EliteBook G9 Notebook, OS: Ubuntu 22.04.3, RAM: 16GB, CPU: 12th Gen Intel(R) Core(TM) i5-1245U, GPU: Onboard.
After scraping the entire internet and Godot issues to find how compute shaders work, this is my attempt at Conway's Game of Life. if you want to look at the source code here it is (in C#) https://github.com/erickweil/GodotTests
I'm migrating a slice based 4D Game I was developing in Unity, and two days in managed to get the first shader working and I'm already with a 4D rotating cube.
In all definitions the game VIEW is 3D, but the world and physics isn't, it's like if you could play 2d mario in a 3d world, where the 2d plane he sits in rotate to allow movement in the third axis and see the rest oc the scenario otherwise hidden.
Things that made me think twice:
The Godot project I just started working on is on Github on https://github.com/erickweil/Godot4D
I should say if you want to start in game development, just go with a engine, like Unity3D that allows to the same game be on Android, Iphone, Deskto, Mac, HTML5, etc...
The language is c#, but is not that hard to move on.
End of this list.
Back to top