Hi I’m making a Minecraft clone yeah one more Minecraft clone but I promise it won’t be another Minecraft chip copy I want to make a unique game a mix between sandbox survival RPG Rog like game something like that I decided to delete my previous project which I made with Unity for obvious reasons and I’m starting from scratch making my own box engine using opk which is a lowlevel wrapper of opengl in C let’s start from the beginning Minecraft worlds are made out of cubes so we first must render a cube in order to do that we must render six Faces each face is a quad and we can see a quad as two triangles like this we send to the GPU the vertex positions and how they combine together to make a triangle but we want cubes that get affected by lights and that have textures just like mcraft has to do that We also must send to the GPU a normal Vector for each vertex and the texture coordinate you can see a normal Vector has the direction of light when being reflected from the surface putting that together and writing a basic Shader we get a cube I said a cube there we go but A Minecraft world has millions and millions of blocks let’s then do the same but millions of times pretty easy right well not really rendering lots of Cubes separately is not really efficient because doing a lot of draw calls is really bad for performance we have to do It a little bit more cleverly so we will divide the world in chunks those that have played Minecraft before will be familiar with the concept of Chun but for the people that don’t know a Chun is a group of blocks so the world becomes a group of chunks this still doesn’t fix The issue of course because millions of blocks are being rendered anyways but the player can really see the ones that are far away so we don’t need to render them what we will do is instead of rendering all the chunks of a world we will only render the ones around the Player this way we get an infinite world without blowing out the computer but we have to do a lot of more optimizations in order to make the game be performant as you can see if we go inside the chunks we can see that all the faces of each block are being Rendered even though we cannot see all of them when we are playing because they are cluded by neing opaque blocks so we will check before adding every to the mesh if there is a non-transparent block besides this reduces a lot of the non-important information sent to the U Now as you can see our chunks are still visible completely but without having nonvisible faces rendered now there are still some problems to fix one of them is the RAM usage we are currently using 7 GB which is a lot that’s because it chunk is 32x 256x 32 blocks and what what we are doing now is to store all the blocks in a three-dimensional array but this is not the best way as the chunks have a lot of air blocks above the terrain which is occupying unnecessary space in memory we can see An AIR block like an empty block and we don’t want these empty blocks to occupy that much memory so what we will do is to split the chunks in sub chunks of 32 by 32 by 32 blocks now if all the blocks of a sub Chun are the same type you only Have to save that block once instead of 32x 32x 32 times this way we reduce that many bytes to two bytes only now we can take it a step further and split those OP CHS into y layers and we will do the same to these layers if a layer is Filled out with the same block type we’ll store only one block ID instead of a whole array of 32x 32 block IDs and for the layers that contain multiple different blocks we will store them in a one-dimensional array of 32x 32 two slots notice that I’m storing it in a Onedimensional array instead of a two-dimensional array because the access to onedimensional array is much faster than multi-dimensional arrays in languages like C and Java I won’t explain why in detail but you can find the link in description of a stack Overflow post if you are curious about it to calculate the correspondent index Of a 2d coordinate we just have to shift five bits to the left the set coordinate and then add the x coordinate value we shifted five bits to the left because a number from0 to 31 can be written in five bits after applying all of these I Just mentioned we get exactly the same scene as you can see but we reduced the RAM memory from more than 7 gbes to roughly 100 mbes which is around a 98% reduction of memory for the same result but the world looks so boring don’t you think let’s add some really basic Procedural generation so we can see a more accurate performance of the game and not in such perfect conditions as you can see we lost some FPS now we still have a problem to solve for this video if we start playing around and loading new chunks we can see That the vram keeps growing a lot but we are always seeing the same amount of chunks to fix that we will create a pool of meshes when un loading a Chun we will add the mesh to a pool and then when we load a new Chun instead of creating a New mesh we’ll get one from the pool this way we don’t store useless memory of uploaded chunks and we will only have in V Ram the space that we really need to render the world that we are seeing now we can see that the vram doesn’t grow that much like before you create New meshes if the meshes in the pool are not big enough for that specific chunk there are lots of improvements to do and other optimizations but that will be for future videos here you can see the CP U RAM and GPU usages which can be really loud a lot Still but for now I think it’s pretty good just a little clarification I will maintain the style and the goal or scope of my previous project but this time using a boxel engine as I have to make my own boxel engine it will take a bit More time than expected but I think it will be worth it at the end as I can achieve more performance and also I’m not dependent of the decisions of others and finally I want to thank you for your support in my previous videos and I want To say that I have all of your ideas and opinions in mind in order to make the best game possible please consider subscribing to my channel and following me on Twitch because I will be posting updates more frequently and yeah see you in the next video Video Information
This video, titled ‘I Remade Minecraft, again… | Devlog #1’, was uploaded by Haukrr on 2023-10-29 16:00:38. It has garnered 10800 views and 536 likes. The duration of the video is 00:06:57 or 417 seconds.
Hello everyone! I have started a voxel engine from scratch to make my game on :). Hope you like this new series of devlogs where I will be focusing first on the actual engine and, later on, I will start working on the features of the game.
Any suggestions are appreciated :).
Twitter: https://twitter.com/haukrr_dev
Link I mentioned: https://blog.tedd.no/2021/10/07/why-c-multidimensional-arrays-are-slow/