Blazingly Fast Greedy Mesher - Voxel Engine Optimizations

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 พ.ค. 2024
  • This greedy mesher is blazingly fast. Written with Rust and Bevy, using clever bitwise operations we can generate chunk meshes, an average of 0.000195 per 32x32x32 mesh!!!
    This mesher blows most culled meshers out of the water, and I want to teach you the "secrets" of how to implement this for own voxel engine.
    There are 2 algorithms we'll explore:
    Binary greedy meshing AND binary face culling.
    IT'S OPEN SOURCE!
    github.com/TanTanDev/binary_g...
    Resources:
    Greedy Meshing Voxels Fast - Optimism in Design Handmade Seattle 2022: • Greedy Meshing Voxels ...
    C++ binary greedy mesher repository: github.com/cgerikj/binary-gre...
    Simplified greedy mesher article: vercidium.com/blog/voxel-worl...
    My discord group:
    / discord
    Want to support me?
    ⁍ Patreon: / tantandev
    ⁍ Monero: 43Ktj1Bd4Nkaj4fdx6nPvBZkJewcPjxPB9nafnepM7SdGtcU6rhpxyLiV9w3k92rE1UqHTr4BNqe2ScsK1eEENvZDC3W1ur
    0:00 blazingly fast
    0:30 but why?
    2:56 greedy meshing algorithm
    4:23 indexing?
    4:52 binary data
    5:43 code: binary greedy meshing
    7:44 chunk slicing
    10:14 why it's slow
    11:24 WORLDS FASTEST binary greedy mesher
    19:43 why it's fast
    21:01 interesting findings
    22:22 resources
    #rustlang #gamedev #programming
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 282

  • @MrSofazocker
    @MrSofazocker 16 วันที่ผ่านมา +457

    You just casually made a spatially mapped datamodel lol

    • @daddy7860
      @daddy7860 16 วันที่ผ่านมา +37

      What part of this video was casual lol

    • @notthetruedm
      @notthetruedm 16 วันที่ผ่านมา +78

      @@daddy7860 The way he explained it felt like a friend explaining something to me rather than a teacher explaining.

    • @Pockeywn
      @Pockeywn 14 วันที่ผ่านมา +11

      yep. just to remake minecraft. this is what people do on the internet.. its awesome.

    • @yaboiminecraff
      @yaboiminecraff 13 วันที่ผ่านมา +3

      ​@@notthetruedm the best way to learn

  • @cosmo9762
    @cosmo9762 16 วันที่ผ่านมา +465

    Hi! I wrote the "Binary greedy meshing" algorithm. Very cool to see this video on my youtube frontpage today, I love your video and explanations :)

    • @samuelcollier1764
      @samuelcollier1764 16 วันที่ผ่านมา +23

      glad to see people are finally seeing this now! It definitely deserves more attention

    • @nicholasfinch4087
      @nicholasfinch4087 15 วันที่ผ่านมา +38

      I was skeptical at first, but after some digging, damn you really are the guy that wrote the mesh algorithm 4 years ago. Nice!

  • @redfatcatz
    @redfatcatz 16 วันที่ผ่านมา +279

    Thanks for the video, I can advise you not to make a greedy mesh for each type of block, but to make for all complete solid blocks, and then transfer to the GPU data structure with the help of which you can calculate the block type and texture by pixel position, it will simplify the mesh many times as well as the algorithm itself.

    • @tommycard4569
      @tommycard4569 16 วันที่ผ่านมา +6

      ah, this makes sense

    • @CaptTerrific
      @CaptTerrific 16 วันที่ผ่านมา +32

      I'd love to see the speed comparison on that, sounds promising!!

    • @charltonrodda
      @charltonrodda 16 วันที่ผ่านมา +6

      Is it really faster to do that lookup in the fragment shader than it is to store it in the vertex data or look it up in the vertex shader?

    • @raffimolero64
      @raffimolero64 15 วันที่ผ่านมา +18

      @@CaptTerrific Saves a hashmap entry access for every voxel. bets on 4x speed.

    • @TheSliderW
      @TheSliderW 13 วันที่ผ่านมา +1

      Same for lighting and ambient occlusion

  • @notthetruedm
    @notthetruedm 16 วันที่ผ่านมา +47

    When you explained the part in 14:40, where you explained how to find the faces looking right just by modify an interger, I was so surprise at how simple it is an yet amazingly complex

    • @110110010
      @110110010 10 วันที่ผ่านมา +4

      My thought right there was "oh, is this edge detection?" It was a really intuitive explanation

  • @CSPciccionsstibilepippons
    @CSPciccionsstibilepippons 14 วันที่ผ่านมา +18

    Found a way to make it even faster: you are initializing the 2 initial vectors with chunk_size_p³, but it can also be done with chunk_size_p² because the 3rd dimension is in the bits. this way you can use arrays because there is no longer a stack overflow

  • @Siphonife
    @Siphonife 16 วันที่ผ่านมา +21

    I now fully understand the concepts used to achieve such high performance. I also fully understand that if I were to try to write it. Every line of code would have an off-by-one error.

  • @user-ms6cc6ft3k
    @user-ms6cc6ft3k 16 วันที่ผ่านมา +57

    You can speed up the data setup part by using stack arrays instead of using "Vec"s

    • @minecraftermad
      @minecraftermad 16 วันที่ผ่านมา +12

      oh yeah definitely since the array size is a known value, and doesn't need to be resized. and is small enough to fit into stack.

    • @0x4849
      @0x4849 16 วันที่ผ่านมา +10

      CHUNK_SIZE_P3 = 34*34*34, so the size of axis_cols is 3*34*34*34*64 = 7,546,368 bits. Additionally, we need twice that for col_face_masks, giving ~2.83MB. Honestly, I don't know whether this will fit on the stack or not. Maybe someone else can provide additional information?

    • @lengors7327
      @lengors7327 16 วันที่ผ่านมา

      ​@@0x4849 I believe max stack size can be changed when compiling, but the default is usually not very large.
      I would instead preallocate the vector once and then always use that one instance

    • @user-ms6cc6ft3k
      @user-ms6cc6ft3k 16 วันที่ผ่านมา

      @@0x4849 I had a program where I had an array of 5 Mb. So 2.83MB should be feasible. Also, the memory can be static. We really just need to benchmark the approaches and choose the best one

    • @user-ms6cc6ft3k
      @user-ms6cc6ft3k 16 วันที่ผ่านมา +5

      2.83mb should be feasible. I had a program that used 5mb for a stack array 😅. The memory can also be shared between calls whatever it's stack or heap based. Different approaches should be benched and there should be a room for improvement

  • @PikkelP
    @PikkelP 16 วันที่ผ่านมา +42

    this is insane! i have my own culled and greedy meshing implementations and i know they're not the fastest, but i'd never have thought it could get THIS fast. you could literally remesh every chunk every frame with this and still get good fps, which is mind-boggling. good job with the explanations, too.

  • @nanda_gamedev
    @nanda_gamedev 16 วันที่ผ่านมา +52

    Oh my god I wish i had this video like 2 months ago when i was trying to write a greedy mesher. Thank you so much for this resource! Will definetly save it for the future!!

  • @14corman46
    @14corman46 10 วันที่ผ่านมา +3

    This is incredible! I did something extremely close to this for counting strings within DNA sequences and got immense speedup. Binary manipulation is insanely speedy if you can comprehend it. Great job figuring this out and explaining it.

  • @jeanlouis5619
    @jeanlouis5619 16 วันที่ผ่านมา +51

    Looking at this made me realise that I clearly need to lurn bitwise manipulation

    • @DanKaschel
      @DanKaschel 16 วันที่ผ่านมา +9

      It's actually genuinely fun if you like puzzles. A lot of it is figuring out how to visualize it so you can figure out what's going on because the final product is always undecipherable (at least for me).

    • @DreadKyller
      @DreadKyller 15 วันที่ผ่านมา +7

      It's honestly amazing how many usecases there are for bitwise operations, I think at least some understanding, even if only basic, should be a core skill of any serious developer.

  • @Unbreathable
    @Unbreathable 16 วันที่ผ่านมา +23

    This video is honestly so well explained and even though I don't know anything about voxel engines or game development I was able to understand it. This is probably one of the best resources for making a voxel engine. If I ever make one, I'll probably take a look at this again, thanks for your amazing work!

  • @theStumblinbear
    @theStumblinbear 16 วันที่ผ่านมา +10

    Use an array for the data instead of a vector (since you know exactly how many entries it will contain) and it should have essentially zero allocation time since it'll be allocated on the stack instead of the heap

    • @Tantandev
      @Tantandev  8 วันที่ผ่านมา +5

      It doesn't fit on the stack on linux it's to large!
      But here is the funny thing... Someone noticed I'm allocating WAY more memory than was actually used.
      And now it does fit on the stack :) So I've changed it.
      The performance difference was only minimal though.

  • @mek101whatif7
    @mek101whatif7 16 วันที่ผ่านมา +21

    Now do it with SIMD

    • @angeldude101
      @angeldude101 8 วันที่ผ่านมา +1

      At least on x86, bitwise operations like count trailing/leading zeros are only available on the more recent AVX-512 processors, so adding SIMD might make it faster of their friend's CPU, but could actually make it slower in parts on their own. There are probably some places where it'd be beneficial anyways though.

    • @GeorgeTsiros
      @GeorgeTsiros 2 วันที่ผ่านมา

      @@angeldude101 you sure about that? Let me check... FELIIIIIX, WE NEED YOUR SITE AGAIN

  • @FM-kl7oc
    @FM-kl7oc 16 วันที่ผ่านมา +8

    If your friends CPU has significantly larger L2 or L3 cache, the performance difference could perhaps be cache misses? Aligning data for CPU cache optimization is another beast to tackle though 😅

    • @AmaroqStarwind
      @AmaroqStarwind 2 วันที่ผ่านมา

      I think it's possible to enable larger memory pages in some compilers.

  • @Gin2761
    @Gin2761 16 วันที่ผ่านมา +10

    I'm making a game that has voxels and I implemented this also using Rust and something very similar to the slow approach. This video came out with such a great timing.
    Thanks for sharing this.
    Maybe it can be even faster if SIMD or parallelization are included? 😁

  • @HoloTheDrunk
    @HoloTheDrunk 16 วันที่ผ่านมา +3

    Thank you Tantan for somehow releasing a video on the exact topic I was worried about for my next project, very cool.

  • @p1tayaa
    @p1tayaa 16 วันที่ผ่านมา +3

    Man amazing video. You made it sound so hard but I feel like I grasp all of it pretty well. The visuals make it soo much easy to follow, hats off to your work.

  • @bosine9431
    @bosine9431 16 วันที่ผ่านมา +8

    Just want you to kmow that this video was so good that at 11:27 there was a solid 5 seconds where I actually scrambled to rewind the video to try to desperately see the code

  • @GeorgeTsiros
    @GeorgeTsiros 2 วันที่ผ่านมา

    i love everything about this
    your awkward presentation, the handdrawn sketches, the weird pronounciation, the focus on speed, your manbun, your long hair that makes you look like a metalhead, the jokes, the effort you made, everything, everything in this video is just *right* .

  • @sturdyfool103
    @sturdyfool103 16 วันที่ผ่านมา +3

    I haven’t tried greedy meshing but I’ve seen some demos of greedy meshes where it doesn’t care about block type, it constructs the triangles while remembering where the different block types are, so it’s possible to make the greedy meshes not slow down when you increase the block type count

  • @bassguitarbill
    @bassguitarbill 16 วันที่ผ่านมา +7

    This is some Big Brain Calculation right here, great video Tantan!

  • @Iridescence
    @Iridescence 16 วันที่ผ่านมา +2

    Great video! I wrote a basic algorithm for doing this on culled meshes, but I'm glad to see it's possible with greedy meshes too!

  • @thaddaeusmarkle1665
    @thaddaeusmarkle1665 14 วันที่ผ่านมา

    Wow man, mad props. That was some heavy stuff and yiu actually explained it extremely well. Thanks, and keep up the good work!

  • @gregbigwood4532
    @gregbigwood4532 16 วันที่ผ่านมา +2

    phenomenal video explaining this. you are very good at explaning these topics

  • @zy-blade
    @zy-blade 16 วันที่ผ่านมา +3

    What a coincidence, I currently need a good voxel algorithm for my project :D Will definitely look into it! thanks

  • @Teflora
    @Teflora 16 วันที่ผ่านมา

    You succeeded very well in explaining something complex in a simple manner! Well done!

  • @konkitoman
    @konkitoman 16 วันที่ผ่านมา +2

    Now i understood why this video take a while to be made!
    This was a really good video!

  • @heryu2630
    @heryu2630 9 วันที่ผ่านมา

    It's like a gift for me.
    It was a problem no matter how much I optimized it before
    but now I have no problem loading and rendering faster than before. thanks for your video

  • @Cluxiu
    @Cluxiu 12 วันที่ผ่านมา +1

    I came from Dani's video, and I'm glad I did :) Great video!

  • @admexir
    @admexir 11 วันที่ผ่านมา +1

    I like how you mostly pronounce "Chunk" as "Shunk", always made me smile :D

  • @a1r592
    @a1r592 15 วันที่ผ่านมา +1

    You explained this really well! Thanks!

  • @Kevroa1
    @Kevroa1 16 วันที่ผ่านมา

    WOW you did a really phenomenal job at explaining your algorithm

  • @lukejagg
    @lukejagg 8 วันที่ผ่านมา

    Woah, love the bit shift and negation. That's a great way to generate the culling indices instead of iterating through every single block.

  • @katech6020
    @katech6020 14 วันที่ผ่านมา +2

    I would love to see a full bevy tutorial on your channel

  • @blinkblade6962
    @blinkblade6962 12 วันที่ผ่านมา +1

    Loved the Flight of the Conchords reference

  • @LuciFur-wz8rc
    @LuciFur-wz8rc 14 วันที่ผ่านมา

    The brings back memories. I recognized some code I wrote about 15 years ago after being blown away by Minecraft. The & operation on the shifted bits specifically. The merging of the meshes was clever and much better than what I ever came up with. I put it all in a fancy octree though so I only rendered on-screen chunks. I hit a brick wall getting the lighting to work on merged meshes and it all fell apart once I had more than, say, 6 block types. Your code will do so too. But it's a great exercise and good job. A more modern way would no doubt be raycasting, there are many more triangles than pixels on the screen if you scale things up and it parallelizes better. Nice video, keep them coming!

  • @eugenech.2450
    @eugenech.2450 3 วันที่ผ่านมา

    I dont watch your videos (but still subscribed (I want to learn rust&bevy some day)), but every time I see your videos it feels like a new scientific experiment.

  • @eboatwright_
    @eboatwright_ 16 วันที่ผ่านมา

    You love to see it! I've also been optimizing the Rust code of my Chess engine, although this seems exponentially more complicated 😅

  • @RyanSPetersonGames
    @RyanSPetersonGames 11 วันที่ผ่านมา

    This is so cool and such a good explanation.

  • @diontryban5645
    @diontryban5645 15 วันที่ผ่านมา

    This is awesome! I'm looking forward to attempting to implement this myself. I'd love it if you would cover ambient occlusion in the future or at least provide some resources for where you learned about it

  • @beppvis
    @beppvis 15 วันที่ผ่านมา

    Less go. great video as always sensei

  • @sotojared22
    @sotojared22 13 วันที่ผ่านมา

    Thanks to practicing image manipulation in JS, this was surprisingly easy to understand and clicked right away for me. 1D data models and traversal is not simple, so I understand your pain.

  • @DanKaschel
    @DanKaschel 16 วันที่ผ่านมา +4

    Love this. I remember building a 2048 AI and going from loop-type grid transformations to bitwise operations. Bitwise stuff is hard to grok but there are sooo many orders of magnitude of improvement and it's so satisfying :)

    • @magfal
      @magfal 15 วันที่ผ่านมา

      I love how other SQL devs look at me when I explain my stored procs that utilize bitmap logic to be a million times faster than the naive approach to the same problem.

    • @DanKaschel
      @DanKaschel 15 วันที่ผ่านมา

      @@magfal umm. I think I'd do the same if a colleague said they were using bit manipulation in a stored proc

    • @magfal
      @magfal 15 วันที่ผ่านมา

      @@DanKaschel
      Calculating using the bitwise code and returning the final result set in postgres put less load on the postgres server than serving the data it's based on to application code, which then had to run the calculations.
      This is true quite often for OLAP style workloads.

    • @DanKaschel
      @DanKaschel 12 วันที่ผ่านมา

      @@magfal that is true, but it'd have to be pretty niche before performance trumped maintainability

    • @magfal
      @magfal 12 วันที่ผ่านมา

      @@DanKaschel a 10 line comment was enough for my colleague to understand and confidently make adjustments for a new requirment.
      Bitwise code isn't magic or that hard to do when you know the incoming data, the result, the intended behavior and you've got the code in front of you.
      And to go from a batch job ran once a month to an on demand real time task is quite important when the report directly generates revenue for it's users with more benefit being reaped the fresher the data being presented is.

  • @Skeffles
    @Skeffles 12 วันที่ผ่านมา

    Amazing to see the level of performance you can get out of using the binary representation and this has me wondering if I can use any in my own projects. I suspect I will need something similar to create an AI navmesh in the near future.
    Fantastic video once again TanTan!

  • @meanmole3212
    @meanmole3212 14 วันที่ผ่านมา +1

    That is cool revelation and use of bits.

  • @uncertawn
    @uncertawn 16 วันที่ผ่านมา +1

    this videos singlehandedly makes me wanna try to make a 3D game from scratch

  • @oglothenerd
    @oglothenerd 16 วันที่ผ่านมา +1

    Yes! He's back! Let's goooo!

  • @sentinelav
    @sentinelav 11 วันที่ผ่านมา

    You're using bitwise operations to calculate binary derivatives. That's dope :')

  • @Randalandradenunes
    @Randalandradenunes 16 วันที่ผ่านมา +1

    Let's gooooooooooo...I love this series

  • @arkin0x
    @arkin0x 12 วันที่ผ่านมา

    Funny and fascinating! Thank you!

  • @LeBopperoni
    @LeBopperoni 16 วันที่ผ่านมา

    Lmao I wrote an algorithm yesterday for greedy meshing which does a bunch of neighbour checks for each block and then creates a bit mask from that.
    Definitely stealing the bitshifted comparison optimisation. This must be the most amazingly timed video I've ever seen.

  • @macawls
    @macawls 16 วันที่ผ่านมา +9

    BLAZINGLY FAST

  • @OctagonalSquare
    @OctagonalSquare 13 วันที่ผ่านมา

    15:04 this was the point I verbally said “this guys psychotic” but in a good way. This is a crazy way to think about this data but it makes so much sense! Good work man!

  • @charetjc
    @charetjc 15 วันที่ผ่านมา

    Excellent video. The animations are easy to follow along with. Thanks for sharing.
    I'm curious about the method you used to profile your code to determine the execution time of various sections. I didn't see any particular video in your catalog that seemed to cover this, so perhaps a "How Tantan profiles his Rust code" could be an idea for another video.

  • @fuzzy-02
    @fuzzy-02 15 วันที่ผ่านมา

    This is... beautiful

  • @scotthooper6460
    @scotthooper6460 3 วันที่ผ่านมา

    You can go farther. In my greedy mesher I store both block and ambient-occlusion lighting in textures, as bytes, using a bin-packing algorithm. One 2kx2k texture has always been enough, but I also added the ability to track which is needed by each chunk in case I needed many.
    This is particularly useful in city-like terrain where the geometry has a lot of flat faces made up of different types of blocks.

  • @rinoturtle738
    @rinoturtle738 16 วันที่ผ่านมา +1

    Thak You! That video and research are so usefull!
    After watching your video, my greedy mesher looks so sloooooow :c

  • @downey2294
    @downey2294 9 วันที่ผ่านมา +1

    1:03 missed opportunity for the vsauce intro ost

  • @iyxan2340
    @iyxan2340 15 วันที่ผ่านมา

    damn i always had wanted to play around with bitwise manipulations, really cool video

  • @sanderbos4243
    @sanderbos4243 16 วันที่ผ่านมา

    Amazing video!

  • @AmitBen
    @AmitBen 16 วันที่ผ่านมา +1

    Amazing work, You can make this dramatically faster using SIMD now that its a bitwise op game

  • @DreadKyller
    @DreadKyller 15 วันที่ผ่านมา

    Several people have mentioned looking into SIMD optimization, but a few other ideas:
    1) Using a fixed sized allocation instead of a Vec since the size is known. Not sure whether the entire arrays would fit on the stack but if so that may provide several speed improvements over a Vec on the heap.
    2) It might be possible to combine both positive and negative edge detection into a single operation by using an XOR, but would require a slightly different method of iterating over them to pass into the greedy meshing.
    3) Your structure for axis_cols has the data for each grid separated, a format similar as such: (y1, y2, y3, y4... x1, x2, x3, x4... z1, z2, z3, z4...) this means when setting the values you're writing into separate parts of the vec that might be far enough from each other to cause frequent cache misses. A layout where the three axis all are interwoven beside beside each others might be faster, such as (y1, x1, z1, y2, x2, z2, y3, x3, z3, y4, x4, z4...)
    4) It would require a bit of rework but this seems very reasonably practical for a compute shader.
    5) Would take a fair amount of work, but rethinking how you store the actual voxel data in general may make it faster to convert.
    6) Again it would be a change in direction, but there are approaches people have taken where you can greedy mesh any flat surface, regardless of different types of blocks. The way that achieve this is usually to pack the color data for the chunk into a 3D texture and use it in the material/shader for the chunk mesh, then, rather than each triangle having a color, the fragment shader can use world coordinates to query from the color data as a 3D texture at the position of the face. Allowing a single triangle to have multiple colors on it. This makes the fragment shader slightly more complex, but in most examples of people using this technique it tends to improve performance in both rendering and construction because it can result in a massive reduction of polygons, especially as you add more and more materials.

  • @fanzaii
    @fanzaii 16 วันที่ผ่านมา

    Impressive, very nice!

  • @NoVIcE_Source
    @NoVIcE_Source 16 วันที่ผ่านมา

    wow, this is actually inspiring

  • @Xaymar
    @Xaymar 14 วันที่ผ่านมา +1

    Nice technique. Possible considerations for the future:
    - With SIMD you can implement masking for each block type without having to split them into different array. Though it does mean a hard limit on the block types and chunk size.
    - I'm pretty sure SIMD could be used to "instantly" (

    • @danmerillat
      @danmerillat 11 วันที่ผ่านมา

      ARM has a lot of SIMD instructions as well, if you find a common subset that gives you the operations you need and use the compiler's __builtin support you can do it for both platforms without any inline assembly.

    • @angeldude101
      @angeldude101 8 วันที่ผ่านมา

      Rust has a portable standard SIMD library, but it's considered unstable and requires the nightly compiler to use. In my experience though, it is very pleasant to use as-is, so it could be worth trying, at least behind a feature gate.

  • @purplepixeleater
    @purplepixeleater 16 วันที่ผ่านมา

    Thanks from a godot developer (csharp) this is very useful there as well since bitwise operations work very similarly and especially with multimesh instancing! Cheers :)

    • @DreadKyller
      @DreadKyller 15 วันที่ผ่านมา +1

      bitwise operators are basically universal, they aren't language specific, you can do them in every language I know of. So very useful and easily transferable skill to know.

  • @grillad5
    @grillad5 16 วันที่ผ่านมา

    So nice, a new vid!!!!

  • @danmerillat
    @danmerillat 11 วันที่ผ่านมา

    One final thought, if you use 30x30 chunks you can fit the left/right neighbors into a 32bit int rather than expanding to 64. It'd halve your memory bandwidth requirements at minimum and if you use SIMD it will let you double the number of calculations performed per cycle.

  • @btarg1
    @btarg1 16 วันที่ผ่านมา

    This voxel engine looks incredibly advanced and would make a brilliant base for games! For future videos I'd love to see you implement a scripting language into an existing Rust project like Lua or Angelscript.

  • @zennii
    @zennii 16 วันที่ผ่านมา +2

    Coincidentally I just implemented nearly the same thing a week ago, though I support octree blocks so it's a bit more involved, but cool to compare implementations. I made use of xor to detect my faces, never thought of just flipping the neighbor... My meshing ended up about 50% faster somehow after implementing it, even though it feels like more work is being done

    • @infinitasium
      @infinitasium 15 วันที่ผ่านมา +1

      The expression he did for his mesher is actually one half of an xor (A xor B = A*(!B) + (!A)*B), and since CPUs have built-in support for all binary operations, your algorithm does the work at once instead of going through it twice by choosing the two paths at once. The only caveat here being two bits are on instead of one, but that difference is irrelevant as they are guaranteed to be next to each other.

    • @zennii
      @zennii 15 วันที่ผ่านมา

      Interestingly I tried switching my system to just flipping bits instead of xor, I was already flipping the bits for another part so surely it should be free gains. Weirdly, it ended up very slightly slower which is perplexing. I don't think it's worth diving into it enough to find out why or what changes the compiler has here, but thought I'd note what I found...

  • @enrique6693
    @enrique6693 14 วันที่ผ่านมา +1

    3:00 as I always say "paint is the most important software for software developers"

  • @user-wr3dz2op1t
    @user-wr3dz2op1t 16 วันที่ผ่านมา +1

    Отличное видео !!!

  • @realdlps
    @realdlps 16 วันที่ผ่านมา +2

    God damn bitwise wizards, I really have to learn how to use that stuff, because in theory I understand it, but I don't know how to use it

  • @NabekenProG87
    @NabekenProG87 16 วันที่ผ่านมา +3

    I wonder if the data layout could be improved as it looked like you use sequences of array indices that are far apart from another. Depending on how large the data is, this could theoretically lead to cache misses as not the entire array is loaded into the cache at the same time. But it's only 0.8% of runtime and the Compiler probably already optimizes this. But if there was a slowdown caused by cache misses, improving the data layout could speed up the code a lot

  • @klevisimeri607
    @klevisimeri607 15 วันที่ผ่านมา

    Amazing!

  • @BooleanDisorder
    @BooleanDisorder 15 วันที่ผ่านมา

    Jag vet vad girig betyder. 😮

  • @CottidaeSEA
    @CottidaeSEA 2 วันที่ผ่านมา

    My first idea was to just bitmask. If you have a 1x4 area and want to check the area next to it, it'd be far faster and cheaper to just get the area next to it, use the first one as a bit mask over it and if there are no differences then it's all good and you can proceed. If it isn't, you can check where the differences begin and then you can discard from the conflicting side and then keep going.
    Okay, seems like that's pretty much exactly what's done.

  • @foxcirc
    @foxcirc 15 วันที่ผ่านมา

    this is great

  • @user-dm7sk5wf5w
    @user-dm7sk5wf5w 3 วันที่ผ่านมา

    Very cool. I bet you can double the performance with some tweaks to how you manage memory. I see a lot allocations happening in loops when you could make 1 allocation outside the loop and reuse the variable for each cycle of the loop.

  • @diegoaugusto1561
    @diegoaugusto1561 10 วันที่ผ่านมา

    a tip go further decrease the data creation time: You're always creating and releasing memory with those Vec's. You should find a way to allocate memory once and reuse it instead. Also, don't use the stack because it can heavily limit you.

  • @devpenguin0
    @devpenguin0 10 วันที่ผ่านมา

    I tried out the mesher in my own project with a different chunk storage scheme. I ran benchmarks on my project and got around 500 µs (microseconds) per chunk. When I ran your benchmark I was getting around 32 µs. Initially I thought it was just inefficiencies in retrieving voxel data since I'm using palette based compression. After some more testing I found that if I use your chunk generation code the benchmark result was around 50 µs. Turns out there's only a few solid voxels in the benchmark chunk which is why it runs much faster. The first chunk I tested/benchmarked had solid voxels in a sphere shape. Still my voxel retrievel from the chunk is significantly slower then simply indexing into a Vec. Mainly because I use bitpacking for the indices.

  • @tommycard4569
    @tommycard4569 16 วันที่ผ่านมา +2

    Brilliant! how does splitting data by block type affect the memory footprint as more types are added tho? Is there an optimal sized chunk to limit the unique block types that can occur within each versus the number of iterations to cover every chunk?

  • @simonhartley9158
    @simonhartley9158 16 วันที่ผ่านมา +1

    Really cool. I wonder how this would relate to the optimizations that Vercidium uses to get voxel rendering running at a claimed 12000 fps.

  • @mobslicer1529
    @mobslicer1529 13 วันที่ผ่านมา +4

    when i see "blazingly" i know it's rust already.

  • @UnifiedCode
    @UnifiedCode 16 วันที่ผ่านมา +7

    Mine is faster
    I dont use any meshes just face information and send that to the gpu
    Then with a shader you can procedurally make vertices and triangles

  • @Siphonife
    @Siphonife 16 วันที่ผ่านมา +3

    Now write it in SIMD using WIDE bit registers. imagine what you could do with 4x256 bits :P

    • @DreadKyller
      @DreadKyller 15 วันที่ผ่านมา

      My goodness I don't think the world is prepared for that much power...

  • @TimDrogin
    @TimDrogin 15 วันที่ผ่านมา

    Epic games had a wonderful talk about nanite, and the part that blowed my mind is: Gpu’s are very slow at rendering extremely small triangles. So what they did? They just wrote a SOFTWARE RASTERIZER, that is faster than the hardware one I think when the size of a triangle is less then 40*40 pixels. The difference is really impactfull, and they showed the code and implementation for everybody to use it!

  • @mme725
    @mme725 11 วันที่ผ่านมา

    16:30 🤯whooooa, kudos on visualizing that! That really clicked well! 👏
    Also this is a bit of a loop-unrolling idea, not sure if the unexplained ambient occlusion part defeats it, but instead of iterating over the 6 axis separately could you iterate over just the 3 (X, Y, Z, no reverse) and do the reverse calculations in the same portion handling the same axis? So grouping X and XReverse into the same iteration.
    Honestly it's a shot in the dark, and it's also not even a major fraction of the computation time anymore even if it did somehow manage to shave any time, but figured I'd contribute something while I'm here 😅

  • @RealCrafter645
    @RealCrafter645 16 วันที่ผ่านมา

    HES BACK

  • @olbld
    @olbld 15 วันที่ผ่านมา

    Wow! 🚀✨
    This video is not just training, it's inspiration. Inspiration for all of us to keep striving to do better, faster and more efficiently. Inspiration to keep exploring, learning and growing. 🌟🚀
    Thank you for this amazing experience! 💖🌐

    • @olbld
      @olbld 15 วันที่ผ่านมา

      Working with bitwise manipulation in the mesh algorithm was particularly interesting and opened up a new world of optimizations for me! I'm afraid my friends are going to have a tough time listening to the next week just about them! 😁
      Really enjoyed the learning process) Hope this helps other developers. Great video!

  • @ToonedMinecraft
    @ToonedMinecraft 13 วันที่ผ่านมา +1

    This was so clearly explained! You finally made me understand a usecase for bit-shifting!

  • @VegetableJuiceFTW
    @VegetableJuiceFTW 15 วันที่ผ่านมา

    Fun fact, you can further reduce polygon count by allowing polygons cross (each other in) the same block type or culled space.
    z-fighting is not an issue as it is the same texture or not visible. I have demo and thesis on this.
    The following "donut" example requires only a single polygon :D
    01110
    01x10
    01110

    • @DreadKyller
      @DreadKyller 15 วันที่ผ่านมา +1

      While Z-fighting isn't an issue, you still then may have to deal with overdraw.

    • @VegetableJuiceFTW
      @VegetableJuiceFTW 14 วันที่ผ่านมา

      @@DreadKyller yup, it's a tradeoff.

  • @ShinigamiZone
    @ShinigamiZone 16 วันที่ผ่านมา

    Pure beauty

  • @augustvctjuh8423
    @augustvctjuh8423 11 วันที่ผ่านมา

    The plural of axis is axes, fyi 😉😉. Also I was kinda mindblown with the bitshift inverse AND trick, nice one

  • @nathanfranck5822
    @nathanfranck5822 16 วันที่ผ่านมา +1

    Very very cool - gonna start on fire if you add more than 20 block types tho 😅

  • @SillyOrb
    @SillyOrb 15 วันที่ผ่านมา

    Even before the OLC console game engine, back when computers didn't have bitmap graphics modes, all there was were "console" / terminal / text mode "graphics." You might be familiar with a game from that time called "Rogue," which is the "rogue" in "rougelike." :)
    What came before Fortnite? Gears of War. Before it? Unreal. What started it all? ZZT, a text mode DOS game from 1991. :D

  • @aaatsa27
    @aaatsa27 8 วันที่ผ่านมา

    I watched this video and barely understood any of it, but it was a good watch

  • @superblaubeere27
    @superblaubeere27 15 วันที่ผ่านมา

    I think this can be made even faster using SIMD-instructions. Most of these problems are similar to problems in parsing where I know that those instructions can make a big difference. Especially in that data preparation step.

  • @bob450v4
    @bob450v4 16 วันที่ผ่านมา

    Nice 🔥