Demo Scene GPR5300

Context

This post is about a 3D scene I had to make for my GPR5300 class at SAE Institute Geneva. I used OpenGL for this scene, as well as C++. The tutorial LearnOpenGL has been a great help throughout this project.

Skybox

The first thing I did was make a skybox using a cubemap.

To do this, I made an array of vertices to place my skybox before loading and adding the textures.

image

As you can see, there are different faces for the skybox. The only problem when creating a skybox is making sure you load the faces in the right order, because if you don’t, you might end up with faces in the wrong place and the illusion of the skybox is broken.

Plane and Tree

Secondly, I decided to do a simple flat plane. For that, as for the skybox, I had to create the vertices for it. From that, I loaded the texture for it, applying it to the whole plane and rendered it on the scene.

plane

The tree, unlike the plane, was a .obj model. For that, I had to load the obj and find and load the materials and textures for it before rendering it in the scene.

treeAndPlane

And when both of these are rendered, the program renders the skybox behind.

treeAndPlaneAndSkybox

Shadow Mapping

Another technique I used was Shadow Mapping. Shadow Mapping is the technique to create shadows of objects when illuminated.

image

The idea is to have a light (in my project, I used a directional light) and, from the point of view of the light we draw the scene. We get the depth map that will be useful to place shadows.

shadowMap

With this depth map, we can do another rendering pass to render the objects and calculate the light and shadows.

treeAndPlaneAndSkybox_LI

image

The thing that can happen when using Shadow Mapping is called Shadow acne:

image

What happens is that sometimes, multiple fragments can sample from the same value from the depth map, creating these lines.To remedy that, in the shader, we use a bias to offset the depth map to avoid this.

image

Conclusion

Learning about graphics was really interesting and way more complicated than it seems on the surface. I would have loved to do more on my project, but due to personal reasons, I was short on time. But I’ll certainly keep learning about graphics and OpenGL in the future.

DemoScene