Back

Mini Minecraft

April 2020

project code opengl cpp

I worked in a team of 3 to build a miniature version of Minecraft for the final project in our Introduction to Computer Graphics class. Despite having to work in three different time zones due to the Covid-19 crisis, we were able to complete an intergalactic themed Minecraft world!

Efficient Chunk Creation

One of my primary contributions was optimizing the chunk creation system. In Minecraft-style games, the world is divided into chunks—16x256x16 blocks that are loaded and unloaded as the player moves. Efficiently managing these chunks is critical for smooth gameplay.

The chunk creation pipeline involves three main steps:

  1. Block data generation — Determine which block types exist at each position using noise functions for terrain height, caves, and biome distribution.
  2. Mesh construction — Build the renderable geometry by only creating faces between solid and transparent blocks (culling hidden faces).
  3. VBO creation — Upload the mesh data to the GPU for rendering.

Multithreading

To prevent frame drops when loading new chunks, I implemented a multithreaded system that offloads the expensive block data generation and mesh construction to worker threads. Only the final VBO creation step—which requires OpenGL context—runs on the main thread.

This approach keeps the main rendering loop responsive while chunks are being prepared in the background. As the player explores, new terrain seamlessly appears without noticeable stuttering.

Procedural Sky

I also implemented a procedural sky system with a full day/night cycle. Rather than using a static skybox, the sky colors are computed in the fragment shader based on the sun’s position, creating smooth transitions between dawn, day, dusk, and night.

The sky shader uses:

  • Rayleigh scattering — Simulates how sunlight scatters through the atmosphere, creating blue skies and orange sunsets.
  • Sun disc rendering — A bright circular gradient that tracks across the sky.
  • Color palette interpolation — Blends between predefined color palettes for different times of day.