GPU Terrain Test using Rust & WGPU
Vložit
- čas přidán 6. 04. 2023
- GPU rendered surface nets terrain. Each chunk is composed of 64x64x64 voxels, and the chunks are generated around the player in a volume of 19x19x(4 | 19) chunks. All chunks are drawn using indirect drawing where each IndexedIndirectDraw structure is filled/generated using the meshing compute shaders.
Fully GPU rendered, with little readback to the CPU (only needed for knowing chunk indices withing allocation to be able to free pooled up memory, however, this can be converted to a compute shader for no readback at all).
Each chunk takes approximately 1-2ms to generate it's voxel data, and around 100 micro seconds for everything else (meshing, memory allocation and copying around temp to perm memory). Talking about meshing, the currently algorithm I use is called the "Surface Nets" algorithm, which resembles Dual Contouring but differs from it by not using a QEF. Due to that, I could merge the vertices on the GPU since SN only generates one vertex per "cell", so by using that assumption, I could make use of atomic operations to share vertices between triangles.
As far as the engine goes, the whole graphics API of the engine has been rewritten using WGPU, and multiple internal crates (libraries) have been improved. I have also implemented multithreaded asset loading and multithreadable ECS queries, which allow me to run my frustum culling / matrix update operations in other threads simultaneously.
Shader toy erosion code: www.shadertoy.com/view/MtGcWh
Github Repository: github.com/jedjoud10/cflake-e...
very interesting! amazing job!
Thanks!
Looks cool, well done!
Thanks!
I like the way your terrain is shaped. Looks nice and natural. That shadertoy noise seems useful.
Did you have any plans for a game you might make with this?
Thanks! And yea, that shadertoy erosion noise is pretty useful, especially when mixed in with higher frequency additional noise as well.
At the moment I do have a few ideas for games I might make with this engine, but they're all ideas so far. The engine is still missing a few features like physics and networking that I'd need if I were to make a game with it.
Very cool video
Thanks!
damn, lookin good
Thanks
looking good! Quick question: is the bit mask in the middle window something related to an ECS component storage impl? I've seen some things like that for quicky checking if a component is present in an entity
Yep exactly! It's simply used in my ECS to check if specific entities have specific components, or if I want to query components of a specific type.
@@jed0378 Nice! Great work with the engine. Loved the dithering effect, feels really old school hehe
How many msec takes to compute one chunk (noise + erosion?). I don't know if you've already said it. One option in order to not limit to one chunk per frame chunk generation could be getting compute shader time measurements and heuristics so that you can adapt and dispatch more chunks. Another improve could be prioritazing chunks based on your camera projection (centered chunks first).
Around 1-2ms for noise/density generation and around 0.1ms for mesh generation. And yea you're right, not limiting it to one chunk per frame would be a good thing, I'll implement that when I'm done optimizing and fixing it. Also, the engine already does prioritize chunks that are currently visible and ones that are closest to the camera, though I might want to see if prioritizing chunks that are in the center in the screen (like you said) might help too. Thanks for the advice!
hes so fine 😍😍😍😍😍
😍😍😍😍😍😍😍😍😍😍
i LOVE a man that can code a Terrain generator on Rust!!!
Heya, what all resources did you use to learn the WGPU api?
I mainly used the learn WGPU website ( sotrh.github.io/learn-wgpu/), though I did learn a few things while trying to fiddle around with raw Vulkan (especially how descriptor sets / descriptors work, which are bind groups / bind resources in WGPU terms). I also highly recommend the learn OpenGL website (learnopengl.com/), even though this might seem like a controversial choice (many people dislike it because the PBR math isn't really "correct" or well explained but IMO I've only used it to get me started in graphics development. Other than that it's just googlin' and a bunch of youtube videos online :)
Thank you for the response, I greatly appreciate it! :D I'm currently going through the learn wgpu tutorial and I will check out the learn opengl tutorial once I've finished with LearnWGPU to help solidify concepts, your projects are inspiring! @@jed0378
do you make CSG operations?
Yep, I use the commonly used opSmoothUnion from Inigio Quilez's website to smooth between two types of "biome" noise. Other than that I simply use addition/subtraction to add remove noises from each other.
@@jed0378 Forgive me for not expressing myself clearly. I talked about editing the terrain - creating dents and rocks (add/delete sphere/box brushes)
Oh currently, terrain edits at "runtime" (after the terrain's been generated) are not supported yet, though it wouldn't be too hard if I were to disable the octree and simply modifying the voxel data on the GPU