Mini Minecraft: Pandora's Blocks
Mini Minecraft: Pandora's Blocks is a group final project for CIS 4600/5600: Introduction to Computer Graphics. Our theme was based on Avatar 2: The Way of Water! The main challenges I focused on was implementing player physics, multithreading, and creating some additional biomes for our minecraft environment.
C++
GLSL
Qt
Player Physics
For the player physics, I implemented player movement, including flight mode and ground mode, as well as building and breaking blocks. The biggest challenge with player physics was implementing collision detection. For collision detection, I used grid marching to detect whether there was an object in front of the player, within a certain threshold. The player also slides against walls and small objects when colliding with them at an angle, to ensure for smoother gameplay. For building and removing blocks, I used grid marching to cast a ray and see if it intersects any blocks within 3 units. If the player is trying to build and grid maching detects a collision, then it will return the block before the intersection (i.e. the adjacent block).
Multithreading
Because multithreading performs threads of execution in parallel, it allows for the chunks of terrain in minecraft to be loaded in quickly. This step was very important in making sure our minecraft ran smoothly and terrain was generated fast enough to catch up with player movements.
I implemented multithreading by spawning in block data worker threads and vertex buffer object (vbo) worker threads. I used mutexes to lock and unlock threads so that if a thread tries to make changes to a locked thread, it must wait for it to finish execution. This allows us to successfully build terrain zones even if certain actions, such as loading blocks in and giving them block type data, depend on each other.
The above is a demo of what multithreading looked like during an early version of our game. In minecraft, terrains are loaded in using 16x16x16 chunks of blocks that surround the player.
We can see how the blocks get loaded in on the edges as we move.
In the final version of our minecraft, we have a larger block generation radius around the player so tbe section of the terrain that a player might go to will already be loaded in and available. We also use distance fog to help mask the process of terrain loading, in case there are any lags in the generation process.
The demos below show multithreading in action, in our final version!
Additional Biomes
The other portion I worked on for our minecraft was biomes! I created the 'Blue Alps' and 'Coastal Ridges' biome and implemented biome mixing. I used noise functions like Fractal Brownian Noise and Perlin noise to generate the mountains. The generated "random" values helped determine the shape and height of the terrain, to ultimately create different looking biomes.
Blue Alps: Steep blue mountains with white snow caps
Coastal Ridges: Large bodies of water and hills that are submerged in water
To implement biome mixing, I placed all six of our biomes on a grid. I generated values for temperature and moisture levels for each biome using two different noise functions. Both were based on FBM and Perlin noise. I made them different by distorting the noise by creating offset values and then changing the input based on this.
For temperature and moisture, I created threshold values so that if the temperature and moisture level of the player's position falls within the threshold values, I would interpolate the heights among the appropriate surrounding biomes. Otherwise, I would use 100% of the current biome height. Lastly, I used smoothstep to calculate the weights of each biome when interpolating among biomes.