GLSL / OpenGL / C++ / Qt
Terrain chunk rendering
Multithreading for procedural terrain generation
Ray traced sky & day/night simulation
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!
Terrain Chunk Rendering
In our first iteration of the game, I was responsible for terrain rendering. I accomplished this by rendering 16 x 256 x 16 chunks of blocks at a time. I optimized vertex data storage by interleaving the data into one vertex buffer object, therefore minimizing the volume of data transferred between the CPU and the GPU. In order to generate the terrain "chunk", I checked to see if any terrain existed within a certain bounds of the player's position.
In this block of code, I am checking if the right face of a given Minecraft block is adjacent to an empty space. If so, then I need to render that face. This check is performed six times, once for every side of a block.
After I finish iterating through all existing blocks, I have all of the vertex information I need to render the scene. So I can simply push all of the vertex data back into a single vector to be processed and rendered.
Multithreading Procedural Terrain Generation
In order to optimize the terrain rendering, I implemented multithreading. First, I organized the terrain chunk space into terrain zone space, in which a zone consisted of 4 x 4 chunks.
I used a custom worker class called Block Type Worker to spawn a new thread and populate the chunks in a given zone. These chunks were then passed to another worker class called VBO Worker which spawned a new thread and created VBO data for each chunk. In other words, the VBO worker is performing the create() function I had previously made, but now in multiple threads!
Ray Traced Sky Simulation
To create the starry sky, I created a quad that filled the screen nearly at the far clip plane. Next, I made a custom sky shader that calculated color values based on the ray direction of the player's eye.
I added a sun that radiates a pink glow and animated it by applying a rotation function to transform a vector around the X axis. This same transformation was applied to the lambert shader to simulate the sun's illumination. I also interpolated colors between dawn and dusk depending on where the sun was in the sky.