GPU Terrain Test using Rust & WGPU

Sdílet
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...

Komentáře • 27

  • @3DProgramming
    @3DProgramming Před rokem +2

    very interesting! amazing job!

  • @thekiweed9929
    @thekiweed9929 Před rokem

    Looks cool, well done!

  • @delphicdescant
    @delphicdescant Před rokem +2

    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?

    • @jed0378
      @jed0378  Před rokem

      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.

  • @sebbl580
    @sebbl580 Před rokem

    Very cool video

  • @Neutral-uv1vm
    @Neutral-uv1vm Před rokem

    damn, lookin good

  • @psychechip
    @psychechip Před 5 měsíci

    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

    • @jed0378
      @jed0378  Před 5 měsíci +1

      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.

    • @psychechip
      @psychechip Před 5 měsíci

      @@jed0378 Nice! Great work with the engine. Loved the dithering effect, feels really old school hehe

  • @jsierra88
    @jsierra88 Před rokem +2

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

    • @jed0378
      @jed0378  Před rokem +2

      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!

  • @the_4116
    @the_4116 Před rokem +2

    hes so fine 😍😍😍😍😍

    • @jed0378
      @jed0378  Před rokem

      😍😍😍😍😍😍😍😍😍😍

    • @vxrco
      @vxrco Před rokem +1

      i LOVE a man that can code a Terrain generator on Rust!!!

  • @skjaldr7173
    @skjaldr7173 Před 7 měsíci

    Heya, what all resources did you use to learn the WGPU api?

    • @jed0378
      @jed0378  Před 7 měsíci

      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 :)

    • @skjaldr7173
      @skjaldr7173 Před 7 měsíci

      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

  • @MrProton2
    @MrProton2 Před rokem +1

    do you make CSG operations?

    • @jed0378
      @jed0378  Před rokem

      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.

    • @MrProton2
      @MrProton2 Před rokem

      @@jed0378 Forgive me for not expressing myself clearly. I talked about editing the terrain - creating dents and rocks (add/delete sphere/box brushes)

    • @jed0378
      @jed0378  Před 10 měsíci

      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