It’s time to improve the world generation in my Minecraft clone this is what water looks like in my Minecraft cologne at the moment as you can see it’s pretty opaque because it’s rendered just like the other blocks let’s change that this is what happens when we enable transparency But there’s a problem with this as you can see opengl doesn’t like it when transparent things are in the same mesh it’s opaque things the depth is messed up and so you get strange artifacts like this by separating the chunk into different meshes for opaque and transparent blocks We can avoid this artifacting entirely but now that we’ve got basic water rendering working it’s time to make it look better I start off by applying a noise texture to the water mapped to World space and modifying the vertex Shader so that there would be a wave Effect by using the noise textures and input to the fragment Shader I managed to make a wave pattern up close but when zooming out it didn’t quite look as good it was then I realized I should use a fresnel effect the fresnel effect means that if you’re looking at a Surface from the side it will be more reflective than it would be looking directly at it we can calculate the fresnel factor by taking the normalized difference between the camera position and the wall position and by applying the dot product with a normal Direction taking the fresnel factor we can use it To mix between two colors looking down a transparent lighter blue and looking at the side a deeper more opaque blue this improves how the water looks it doesn’t require screen space reflection which although may look good it is expensive to process when I Implement a proper Skybox and lighting I will revisit the Water to give the illusion of reflecting the sky but for now I am satisfied with how the water looks so now it’s time to work on infinite World Generation but before we talk about World Generation we need to talk about parallel threads when you run a program it starts off in a single Thread which means it uses one CPU core at a time modern CPUs have multiple cores so we can take advantage of that with more threads but you can’t just tell the program to have more threads you need to decide when and where yourself since if you do not take care As to how the program will run into bugs known as race conditions in my game I’ve spit off the program into three threads the main thread the world generation thread and the mesh generation thread World Generation and mesh generation are ideal for threading because of two reasons one they take long to complete And two they do not need to finish a task in the same frame when the program begins the world generation thread is started up in tools to generate chunks when each chunk is finished generating the is-generated Boolean flag is set to true and the surrounding chunks are set To remesh when adding a jump to the world which is memory shared with the main thread uses a synchronized keyword against the map of regions meaning that the main thread has to wait for a region to be added removed fully before iterating through them while rendering meanwhile the main thread looks at the List of generated chunks they can see and passes them on to the mesh generation thread the mesh generation thread holds a set of chunks to be meshed and synchronizes on this while adding or iterating through the set a general rule of thumb is that if two threads acts as the same collection you Should synchronize on it otherwise the iterator will mess up when a chunk is done being meshed it is added to a collection which the main thread tells opengl to send the mesh to the GPU this multi-threading system works to allow the world to generate without harming The frame rate however we can improve on this using Java’s executor service which is a single pool of threads we can send multiple types of tasks to this would mean that threads will not be idle as long as that there is work to be done for example at the moment if all visible Meshes are finished but the world is not done generated the program ends with an idle thread for mesh generation that isn’t allowed to work on generating the world this is a refactor that I should take on in the future to optimize it further the first step to implementing Infinite World Generation is to make sure that the chunks are generated as player moves and unloads chunks far away when unloading chunks you must dispose of the mesh properly or there will be a vram memory leak and the program will eventually crash then I applied Simplex noise on the terrain setting water to Generate below a given level 2D noise wasn’t satisfied enough so much like Minecraft I am experimented with 3D noise and eventually I went with that after generating the 3D noise making sure to store the highest block in each chunk column I set the surface layers of Grass and sand then I adjusted the noise function to have more density lower in the world and less density high in the world creating mountains and valleys in the process by taking the minimum of two Simplex noise functions mountain ridges were created as a result next I Generated trees at zero zero each chunk cone but I ran into a bug where the chunks next to a generated tree would be missing this was because trunks are not generated in a particular order setting blocks and adjacent chunks caused it to think that they were already generated So they were skipped entirely this was a simple fix and now I had trees decorating chunks finally I set trees to generate heat using a 2d White Noise where a tree would be placed one percent of the time that includes everything I’ve done so far so now it’s time to Answer your comments why job Java used to be slow 20 years ago but that’s no longer the case I’m quite familiar with Java whereas I know for a fact I have much to learn in C plus so programming a large project in a language you aren’t Fluent in will lead to Tech debt and I don’t fancy dealing with that a year or two from now another part of my motivation was seeing the vast difference between bedrock and Minecraft Java Edition and wanting to prove that at least similar performance can be achieved doesn’t Minecraft already have Optimizations my video was targeted towards voxel game developers who I often see run its performance issues very quickly since rendering millions of blocks is no small task I honestly didn’t think it would get such a wide reception most of the optimizations from the last video are already implemented In Minecraft but the Java Edition has clear performance issues these issues are not because Java is slow nor because Mojang’s devs aren’t dumb or lazy they are not but rather due to Tech debt that has accumulated over the years they are actively trying to improve it and I believe recently they rewrote some Lighting engine a huge performance bottleneck Bedrock Edition was written from the ground up from scratch originally for phones as the Pocket Edition so no wonder it runs well Java editions issues mostly derived from having too many draw calls and inefficient updates you can check out mods that try to improve this such as Sodium and lithium and as for people running servers I’m sure you’re already running paper MC can you make this a mod check out the mods I mentioned before they use the same Concepts my intention is to make a new game entirely so I won’t be modding Minecraft for now can You make this open source it’s too early to tell what I want to do with this project I really like aspirite’s model aspirite costs money but the source is available so if you can compile it you can have it for free make an open source would help an active modding support Scene so I should strongly consider in the future in the meantime if you want to sink your teeth into source code now you can check out mindtest which is an open source Minecraft clone you should check out vintage story I’ll definitely look into it but from I can tell it has A gorgeous soundtrack so it has my approval there you should add level of detail personally I’m not a fan of level of detail but it seems you guys are so I guess that’s something to look into the future after I’m satisfied with the block rendering logic I’ve also tried OCT trees and run lengths and Coatings but unfortunately it somehow wasn’t as efficient as a byte array or layered chunks while being slower that doesn’t mean the algorithm is bad it’s likely that my implications weren’t optimized right I can revisit it in the future if need be and of course there are your Suggestions which are too many to counter display while it’s too early to decide what the true theme of the game is your suggestions did help me narrow down a few things the one block at a time philosophy has to go and the end fight is unsatisfying a lot of you want automation the Monsters need to be more of a challenge Transportation needs more emphasis and the inventory needs overhauling entirely some of you wanted realistic water physics and to which I say have mercy on your poor computer in the next video I’ll be making vram optimizations and implementing a lighting system so if You’d like to see them stay tuned take care and I’ll see you next time Video Information
This video, titled ‘Adding Infinite World Generation To My Minecraft Clone’, was uploaded by FinalForEach on 2023-08-28 04:37:32. It has garnered 82194 views and 9622 likes. The duration of the video is 00:08:21 or 501 seconds.
In this devlog of remaking minecraft in java, I add infinite world generation, improve on the water graphics, and I also explain multithreading.
Music used: Radiant Historia – Perfect Chronology Super Mario 64 Music – File Select Route 216 Midday) Pokémon Diamond & Pearl Pokemon Black & White – Undella Town (Winter)
Useful resources: LibGDX: https://libgdx.com/ Java’s ExecutorService: https://www.baeldung.com/java-executor-service-tutorial