OpenGL would've been fine if you understand the limitations. In OpenGL you can mapBuffer on main thread, fill it on a different thread and pass an event to main thread that unmaps it again. The highest performance approach is probably allocating a large buffer, and using something like glMultiDrawElementsIndirect to render stuff. Can basically implement a custom allocator that way, and render opaque chunks with a single draw call. The thing not clear about OpenGL is that you're writing commands to memory not executing them on the GPU directly. Important to know to avoid freezing.
@@MaxMakesGames OMG! You are shooting yourself in the foot without Git! You MUST use it! Not using Git is one of the painful mistakes early programmers make! Just learn the basics. You can get away with just knowing the add, commit, restore, and maybe some other Git commands.
How do you even store 1B voxels in memory ? Each one has to be at least 4 bytes so that's a minimum of 4Gb and going through that would take a while even with an octree
I feel like bevy is easier than just raw graphics api, but also harder than common game engines like unity or unreal. You still have to do a lot of low-level work but it helps with spawning things and basic features like PBR, transparency, etc and also has an ECS so that helps for managing a lot of entities ( it will be a big help later if I want to make pieces fall to the ground and stuff I bet ). Rust is actually pretty similar to c++ but it has a lot more safety so I don't get memory leaks and crashes like I did in c++, but it's a bit harder to use imo.
What GPU are you running this on? I’m currently trying to render voxels myself and it’d be kinda nice to put the performance you’re getting into perspective. :)
Yes haha but I think using debug mode only caused lag when I had multiple entities ( aka chunks once I added the loading ). Before I added the loading, the whole thing was 1 entity so it probably didn't affect much.
From your experience, would you say that creating inividual triangulated meshes from voxel data first, is much better than sending the voxels to the GPU as simple primitives (quads) using instancing?
@@MaxMakesGames That is really great to hear! What size are the individual meshes you generate from the voxels? E.g. what kind of voxel volume / triangle count do they cover? One mesh for each loaded chunk?
@@tadeohepperle7514 Right now I create 1 mesh per chunk and my chunks are 50x50 but I might reduce the chunk size because it becomes a bit laggy when doing queries for collisions and stuff. At this size the meshes are around 10k vertices I think but it depends on how flat the surface is. Flat means less side faces so less vertices and triangles. I also started generating structures on them so that increases the count a bit because I put them in the same mesh, but I might seperate them to facilitate physics later.
I'm actually not 100% sure how my raycasting works lol I think I found it online and it's been a while so idk where, but here's the code in rust: pub fn raycast_hit_cube_pos_dist(cubepos: Vec3, raycastPos: Vec3, raycastDir: Vec3, dist: f32) -> Vec3{ let halfsize = 0.05; let dirInv = 1.0 / raycastDir; let tMinVec = (cubepos - halfsize - raycastPos) * dirInv; let tMaxVec = (cubepos + halfsize - raycastPos) * dirInv; let t1 = Vec3::min(tMinVec, tMaxVec); let t2 = Vec3::max(tMinVec, tMaxVec); let tNear = f32::max(f32::max(t1.x, t1.y), t1.z); let tFar = f32::min(f32::min(t2.x, t2.y), t2.z); if (tNear > dist || tNear > tFar || tFar < 0.001) { return Vec3::new(-10000.0,-10000.0,-10000.0); } return raycastPos + tNear * raycastDir; } halfsize is half the size of my cubes/voxels so mine are 0.1x0.1 so 0.05 halfsize. it checks from the raycastPos in the raycastDir if cubepos is hit within dist distance. If not it returns a -10000 vector and if so it returns the pos hit ( you could also just make it return false/true if you dont care about pos hit ). I just run that on every cube in the chunk and if there's no hits, move to the next chunk in the aim direction and check again. That's why I think I'll reduce my chunk size because looping 50x50 cubes for no hit is very bad lol. It can prob be optimized too but I hope that helps.
I think it's possible for sure, but rust offers a lot of tools for multithreading like rwlock, arc, etc. that makes it easier to manage multithreading without having errors, crashes, etc due to data race. With c++ you would have to use mutex and stuff like that which would end up locking the thread often ( at least that's what happened to me ) and it's just overall more difficult to manage. Rust will prevent you messing up so it's cool for that, but if you're really careful you could probably do the same thing in c++.
@@MaxMakesGames In C++ you can use OpenMP and put a parallel for loop around the iteration over blocks to update. This is how I do it. The large edits that cross multiple blocks are the ones that cause lag and also the ones that distribute well across threads.
The Rust hype is greatly overplayed tbh. You could have done just as well, just as easily, with C++. Mostly it's just usually not worth switching languages or API's based on popularity contests, and sticking to something that you're familiar with has a greater advantage imo. But I'm not criticizing you - just hoping you don't get stuck in a loop of "stack switching" like sometimes happens to programmers' hobby projects.
The bing AI :) I just open Microsoft Edge and it's there, but idk if you can use it in an other browser. It's cool because it can search online. An other cool option is www.phind.com/ it's similar
@@MaxMakesGames Could I be the moderator? Or could you at least point people to mine? I want there to be an environment where devs can talk to each other about this channel and stuff, I want to verify that you have the correct Bevy settings in Cargo.toml, etc... Also, Discord has a pretty good (annoyingly good) AutoMod.
What the fuck are your expectations? Do you want a single person to somehow create a renderer, physics engine, input and windowing api, and everything like.. LITERALLY from scratch? On top of needing to need deadlines for his content creation? Seriously? He doesn’t need to be Id software to make something without a typical “game engine” and still have it be impressive and entertaining. Where is your game engine from scratch in assembly, that uses no external code? I think rust and vulkan is respectable by a single dev.
@@AllExistence it isn’t a lie? there isn’t 1 way (your way) to interpret the phrase “from scratch”. When he says without a game engine, then that can still be interpreted as from scratch to an extent without him needing to create his own fucking OS for a youtube video.
The nice thing about the prototype stage is that you don't need to be scared of tech debt... Rewrites galore!
Nice seeing you here.
I got terrible memory, saw this video again, saw this comment again and was about to comment “Nice seeing you here.” Again
@@ragdude7323 no way, i literally did the exact same thing for a finalforeach comment on another voxel game dev video :p
OpenGL would've been fine if you understand the limitations. In OpenGL you can mapBuffer on main thread, fill it on a different thread and pass an event to main thread that unmaps it again. The highest performance approach is probably allocating a large buffer, and using something like glMultiDrawElementsIndirect to render stuff. Can basically implement a custom allocator that way, and render opaque chunks with a single draw call.
The thing not clear about OpenGL is that you're writing commands to memory not executing them on the GPU directly. Important to know to avoid freezing.
You could just use vulkan and c++
Very cool! I love Rust and Bevy, it's easy to get started but it can sometimes be difficult.
Really nice videos, I'm making a voxel engine too (just that it's taking me like a few months lol) and I randomly discovered your videos. Great work!
Cool, thanks!
"Max is stupid"
Extremely relatable.
I also remake my whole [insert project here] from scratch on occasion.
Do you use Git for version control? It allows you to rollback if you make mistakes.
I don't use Git right now but I might. And yes I'm using Bevy !
@@MaxMakesGames OMG! You are shooting yourself in the foot without Git! You MUST use it! Not using Git is one of the painful mistakes early programmers make! Just learn the basics. You can get away with just knowing the add, commit, restore, and maybe some other Git commands.
@@MaxMakesGames Shameless plug: I may make a simple Git guide on my channel later.
Step 1. Making a voxel engine from scratch
Step 2. Remaking my voxel engine from scratch
Step 3. Recreating a computer from scratch
To optimize the engine you can use ocular exclusion
Thinking about TNT in minecraft, the performance on your engine is looking really promising so far
In the unity game im making, I somehow got it up to 1 billion voxels rendered, but that is like, totally out of the use cases that i would need
How do you even store 1B voxels in memory ? Each one has to be at least 4 bytes so that's a minimum of 4Gb and going through that would take a while even with an octree
Brilliant! How do you like working with bevy and rust?
I feel like bevy is easier than just raw graphics api, but also harder than common game engines like unity or unreal. You still have to do a lot of low-level work but it helps with spawning things and basic features like PBR, transparency, etc and also has an ECS so that helps for managing a lot of entities ( it will be a big help later if I want to make pieces fall to the ground and stuff I bet ). Rust is actually pretty similar to c++ but it has a lot more safety so I don't get memory leaks and crashes like I did in c++, but it's a bit harder to use imo.
What GPU are you running this on? I’m currently trying to render voxels myself and it’d be kinda nice to put the performance you’re getting into perspective. :)
I have an nvidia geforce RTX 3060 :)
If you only turned on release mode at 8:00, does that mean that the performance tests in the middle of the video were also in debug mode?
Yes haha but I think using debug mode only caused lag when I had multiple entities ( aka chunks once I added the loading ). Before I added the loading, the whole thing was 1 entity so it probably didn't affect much.
From your experience, would you say that creating inividual triangulated meshes from voxel data first, is much better than sending the voxels to the GPU as simple primitives (quads) using instancing?
It's a bit more difficult to implement but not that much and it's a lot better in terms of performance!
@@MaxMakesGames That is really great to hear! What size are the individual meshes you generate from the voxels? E.g. what kind of voxel volume / triangle count do they cover? One mesh for each loaded chunk?
@@tadeohepperle7514 Right now I create 1 mesh per chunk and my chunks are 50x50 but I might reduce the chunk size because it becomes a bit laggy when doing queries for collisions and stuff. At this size the meshes are around 10k vertices I think but it depends on how flat the surface is. Flat means less side faces so less vertices and triangles. I also started generating structures on them so that increases the count a bit because I put them in the same mesh, but I might seperate them to facilitate physics later.
@@MaxMakesGames Thanks! Btw how are you doing collisions and raycasting for picking a block with the cursor?
I'm actually not 100% sure how my raycasting works lol I think I found it online and it's been a while so idk where, but here's the code in rust:
pub fn raycast_hit_cube_pos_dist(cubepos: Vec3, raycastPos: Vec3, raycastDir: Vec3, dist: f32) -> Vec3{
let halfsize = 0.05;
let dirInv = 1.0 / raycastDir;
let tMinVec = (cubepos - halfsize - raycastPos) * dirInv;
let tMaxVec = (cubepos + halfsize - raycastPos) * dirInv;
let t1 = Vec3::min(tMinVec, tMaxVec);
let t2 = Vec3::max(tMinVec, tMaxVec);
let tNear = f32::max(f32::max(t1.x, t1.y), t1.z);
let tFar = f32::min(f32::min(t2.x, t2.y), t2.z);
if (tNear > dist || tNear > tFar || tFar < 0.001) {
return Vec3::new(-10000.0,-10000.0,-10000.0);
}
return raycastPos + tNear * raycastDir;
}
halfsize is half the size of my cubes/voxels so mine are 0.1x0.1 so 0.05 halfsize. it checks from the raycastPos in the raycastDir if cubepos is hit within dist distance. If not it returns a -10000 vector and if so it returns the pos hit ( you could also just make it return false/true if you dont care about pos hit ). I just run that on every cube in the chunk and if there's no hits, move to the next chunk in the aim direction and check again. That's why I think I'll reduce my chunk size because looping 50x50 cubes for no hit is very bad lol. It can prob be optimized too but I hope that helps.
So theres no way to achieve the same with c++ and vulkan instead of opengl ?
I think it's possible for sure, but rust offers a lot of tools for multithreading like rwlock, arc, etc. that makes it easier to manage multithreading without having errors, crashes, etc due to data race. With c++ you would have to use mutex and stuff like that which would end up locking the thread often ( at least that's what happened to me ) and it's just overall more difficult to manage. Rust will prevent you messing up so it's cool for that, but if you're really careful you could probably do the same thing in c++.
ofc there is but what's even the point of dev if you don't rewrite shit in rust?
@@MaxMakesGames In C++ you can use OpenMP and put a parallel for loop around the iteration over blocks to update. This is how I do it. The large edits that cross multiple blocks are the ones that cause lag and also the ones that distribute well across threads.
I can assure you opengl and c++ were not your issues haha...
You are right actually it wasn't :P
Why did you say “my videos suck” on discord, there really good
The Rust hype is greatly overplayed tbh.
You could have done just as well, just as easily, with C++.
Mostly it's just usually not worth switching languages or API's based on popularity contests, and sticking to something that you're familiar with has a greater advantage imo.
But I'm not criticizing you - just hoping you don't get stuck in a loop of "stack switching" like sometimes happens to programmers' hobby projects.
What AI did you use? 2:53
The bing AI :)
I just open Microsoft Edge and it's there, but idk if you can use it in an other browser. It's cool because it can search online. An other cool option is www.phind.com/ it's similar
If mineceaft Java exists, YOU DONT NEED OTHER Languages. If they cab do it, so can you.
@@ImGelling Minecraft java is terribly inefficient tho... Why do you think they made a new one?
@@MaxMakesGames this is the point. If they made such a banger with so little, just go with the flow
pigboss x max collab? sus.
Wait until I add a pig boss to my game before you :)
Do you have a Discord server?
No sorry I don't because it takes a lot of time to manage and everything. I prefer to spend my time on my projects and videos
@@MaxMakesGames Could I be the moderator? Or could you at least point people to mine? I want there to be an environment where devs can talk to each other about this channel and stuff, I want to verify that you have the correct Bevy settings in Cargo.toml, etc... Also, Discord has a pretty good (annoyingly good) AutoMod.
Not really related to the video, but are you from Quebec ? xd
Yeah 😎
@@MaxMakesGames damn thats cool, i haven't seen any youtuber from there make coding/gamedev videos before
Make this open source or make a tutorial with source code
@@AdamCodes2 It's too big for a tutorial and maintaining code quality for open source would require a lot of work :(
@@MaxMakesGames ok it's alright but amazing game
Do you speak french?
oui bien sûr :)
ça fait du bien de pas etre le seule baguette a regarder ce genre de vidéos mdr@@MaxMakesGames
not as impressive since you used an engine 😤anyways, the shadows finally look good though.
NOT from scratch.
What the fuck are your expectations?
Do you want a single person to somehow create a renderer, physics engine, input and windowing api, and everything like.. LITERALLY from scratch? On top of needing to need deadlines for his content creation?
Seriously? He doesn’t need to be Id software to make something without a typical “game engine” and still have it be impressive and entertaining.
Where is your game engine from scratch in assembly, that uses no external code?
I think rust and vulkan is respectable by a single dev.
@@PeterKilian Don't fucking lie then.
@@AllExistence it isn’t a lie? there isn’t 1 way (your way) to interpret the phrase “from scratch”.
When he says without a game engine, then that can still be interpreted as from scratch to an extent without him needing to create his own fucking OS for a youtube video.
Maybe get him to build the computer from scratch too with a hammer and nails he built from scratch!