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 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)
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.
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.
(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.
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 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)
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.
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.