ChatGPT makes Voxel Engine with Rust

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today we will make a voxel engine using chat GPT now I'll be making a voxel game for longer than a year now using the vast Pokemon language and the baby game engine and my question is is chat GPT here to steal my job will it nullify all the work I've done up until now let's find out [Music] a unique amazing voxel game don't bother showing me the code just make me the game compile it and send me the exit file thank you love 1010. thank you sugar Yeah Boy let's get those sauces out now okay this is actually how it's going to work if voxel engine has a lot of moving Parts first there's the voxel data creation the mesh generation and managing unloading and loading actual chunks and not only that you can make a voxel engine the easy way or the hard way you probably want multi-threading which is a huge Topic in itself and there are many ways you can write the meshing algorithm there are actually four different ways the stupid way the cooling way the greedy meshing way and the optimized meshing way because all of these parts in themselves are really large I don't expect chat TPT to compile all of these different things together so what I'm gonna have to do is ask for specific code pieces hopefully I can take the code and then patch it together alright let's make a new rust project and then I'm gonna include the Bevy game engine to make my life a little bit easier write me a 3D hello world program for rust using the baby game engine ah to display a 3D cube perfect it actually knows how to write baby code so that's a good sign and let's copy that go into our main file will this compile but while it's building we might as well ask for some more code give me a hashmap with the shank position as key and the value is a collection of voxel data we got exactly what we needed and shot GPT managed to figure out probably because I said shank that I want to use integers as positions it did however put it into a tuple which is fine but I would prefer to use Bevis Ibex 3 data type don't use a tuple use an ipic3 please awesome it changed the data type except for some research chat gbt decided to change how we store our voxel data previously we had a vector of voxels and now all of a sudden we've wrapped the vector of voxels into a chunk struct this random change of data types will unfortunately become a reoccurring pain in my brain data representation done let's generate some voxels make me a function to generate some shank voxel data we will have a 32 by 32 by 32 voxels per shank whoopsie the Vox leader doesn't actually represent anything so but it is solid Boolean to the voxel struct this solid will be set with the noise function wait baby has pearly noise I didn't even know that oh it's solid okay generate voxel data I don't care about this show me the voxel data okay here we go here we go okay what this is a basic from what I've heard shut up is trained on data that is like a year old or something so what we are seeing here is actually old Bevy code we don't need to call system you have to do this previously in Buffy but not now so let's see if it compiles now there's no such function new Maybe this should not be a reference to commands cannot borrow commands because it's not mutable and it compels amazing we have a black screen uh because we don't have a camera oh my let's just go ahead and do this in example add camera the lights okay here we go amazing let's add all of this amazing voxel code generate voxel data here's our voxel definitions right Bevy does not have a noise include don't use Bevis noise Library which doesn't exist and use bracket noise instead oh Splendid that is include the library because we can't render the voxels yet I decided to debug the voxel data by printing out the state of the voxels we should see a variety of voxels where is solid is both true and false but for some reason all of them were false I tweaked around with the frequency of the noise and now we have some data that looks good now we are ready to render our voxel data make me a function that takes a shank map and generates a mesh the return value should be a vector of vertices and indices it was cool to see that chatibility remember that we are dealing with 32 by 32 Shanks this code iterates all the voxel data it even knows how to convert the XY set positions to an index and if a block is solid a cube mesh will be appended to the vertices Vector now I didn't get all the code I asked for it stopped in the middle of writing it out yes seem to have stopped before showing me all the code can you continue please I got the code copy pasta here we go we have mesh generation code so now all we need to do is puzzle these pieces together generate the mesh insert the vertices replace the old cube with this newly created mesh will this actually work foreign that does not look correct and we can't see everything we need a camera controller right rust code for a fly camera that we plug in looking good speed sensitivity wait what why do we have two queries okay we get some more Direction This is nonsensical code I had to manually fix some code errors but we got a flight camera let's see if it works oh look we got a camera but it it's uh oh this camera is so bad Shut GPT this flight camera app was so garbage that I eventually imported some code for my other voxel project because it has a fly camera that works perfectly fine why position is one that's good bottom face zero left face zero right face it looks correct it must be something wrong with with the cube indices the cube indices does not look correct why the issue is with the winding order of the vertices in each face figured out exactly what is wrong it's probably generated the indices in the wrong order okay let's try this out yeah it's still wrong remake they generate key vertices function where the winding order is counterclockwise oh no it changed the function input here it's sending in the back three and now it has this pain in my brain we make the generate kubernetes function with the counterclockwise winding order don't you dare change the input start index vertex offset okay it just became Dumber this is beautiful rust code we make a vector and then we remap all of the values by adding the start index so we don't need to add the offset every single place place right by the rest code you're right using map is a cleaner way to add vertex of a straight index here's an updated version why does it store the same value all right thank you let's see if the indices are correct of course it's not uh yeah I I had to take the matter into my own hands because the vertices and indices were complete bogus I had to draw a cube write out the index numbers and figure out all the numbers by myself this took me like 10 minutes not a lot of fun thank you pity the mesh is now correct but you might have noticed that the rendering looks super weird and that is completely my fault I forgot to add normals to the mesh which made the lighting calculations completely messed up I added a normal to all vertices but I made them all point in the same direction which is why it still looks a little bit weird this generation done if you remember this is the first method I mentioned the stupid way the cooling way yeah this is the stupid way spawning cubes everywhere is very bad for performance so next I wanted to see if I could implement the second method which can massively reduce the mesh data the cooling method this is actually the same method I used for my voxel game I don't even have greedy bashing it's performant enough but I'm gonna explore that in the future anyway now this method increases the mesh Innovation code complexity by a lot we now need to sample adjacent voxels and if we're at the edge of a chunk we'll need to find the adjacent chunk of voxel data the algorithm is not that easy to explain either so I will not even attempt that sorry now it quickly became obvious that implemented this method with chatty BT would not be a fun experience especially considering work with large amount of code shot TPT would randomly change data types and many times it will get important details wrong unfortunately we are going to have to stick with this stupid method I wanted to enter a great privacy PPP or Shader to make it look nice and pretty chatty PT could actually give us wdsl Shader code which was cool but once again this is old wgsl code I also need to update the syntax which actually worked but in the end I had to manually Implement Bevis PBR Shader because integrating Shader code like this was not a thing in Bevy previously now it actually looks decent look on our little chunky Go amazing there's only two things left to do number one subscribe to 10 10. number two let's make the world infinite by loading and unloading chunks write some Rust code whose purpose is to Signal when the shank needs to be loaded or unloaded Shanks are loaded when in range of a certain player position the code was actually pretty decent but of course I had to do some minor tweaks here and there I then integrated this shank loading code into the Bevy entity component system and it actually worked the first time I tried it but of course we get a massive frame rate drop when the mesh is created of course loading 9 chunks the same frame without multi-threading yeah that's going to lag this is the final result I would call this the humble beginnings of a voxel engine nothing mind-blowing but pretty cool nonetheless I could obviously improve this a lot but what would be the point considering I'm already making a boxer game that is Miles Ahead in its development I have plenty of videos on this project hey why don't you check it out I believe utilizing chat CPT to further improve this voxel engine would be pretty hard I mean of course I can ask it for guidance on how to implement filter threading but there's no way Shad GPT is going to take all my code and Implement multi-threading just like that work working with large amount of code with the shot GPT it's not a good experience at the moment sometimes it gets details wrong sometimes it changes the data structure or change name of variables the biggest value of shatypt at the moment seems to be asking for guidance in specific topics for example I asked it how do you optimize the voxel Engine with rust it gives some good ideas and even things I've never heard about like store data in a way that minimizes cache misses such as using a Morton ordering for the voxel grid I've never heard of that that might be relevant to my current project I had to ask how does Morton ordering optimize cache misses for voxel grid this method provides a way to reduce cache misses by ensuring that data points that are close in multi-dimensional space are also close in the linear array okay that sounds cool oh look at that here's an article talking about Morton ordering for shank voxel data isn't that amazing a quick question to shattipity and I've learned of a method that might improve performance that's where I'm gonna end this video but to wrap it up I'm gonna need the help of chat TPT make a short wrap for a video outro that is about why they should subscribe to my shadow where I talk about fast programming in voxel engines explodes [Music] a weird lyrics but okay
Info
Channel: Tantan
Views: 88,662
Rating: undefined out of 5
Keywords: rust, gamedev, ai, chatgpt, artificial intelligence, voxel, voxel engine, rustlang, programming
Id: Zs6WNzUjki4
Channel Id: undefined
Length: 12min 19sec (739 seconds)
Published: Fri Feb 24 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.