Blogpost DemoGPR5300
1. Introduction
This is a blogpost about the 3D scene demo I had to do for the GPR5300 module at SAE Geneva using OpenGL. I followed some of the tutorials from LearnOpenGL to make my scene : https://learnopengl.com/
2. Cubemaps
For this scene I used the skybox given by LearnOpenGL : https://learnopengl.com/Advanced-OpenGL/Cubemaps
I first made an array of vertices for my skybox :
Then I generate the Vertex Array Object (VAO) and Vertex Buffer Object (VBO) and transfer the datas to the GPU :
Then we take the textures with the right path from my folders and show them in the scene :
OBJ
For my obj I have a model class which takes care of loading it in the scene.
And I call this function in the update. We can also change the positions of our obj.
I paid to get this model and if you’d like to have it too you can find it here :
https://www.cgtrader.com/3d-models/exterior/landscape/snowy-mountain-8k-textures
Framebuffer
For the framebuffer I first made coordinates for the quad vertices.
Then we generate and bind the Framebuffer Object (FBO) and the Renderbuffer Object (RBO) :
We also generate and bind the quad VAO and quad VBO :
We also need to make our shaders, here’s the fragment shader :
and our vertex shader :
Then we call the shaders and everything that we need in the update to be able to use the framebuffer in our scene :
and we know it works because if we put this line instead of the other one in our fragment shader, the scene looks like this :
Directional Light & Normal Map
For the directional light we don’t need any position because it lights the whole scene. Since I had shaders for both my directional light and my normal map, I decided to make a “mix” of the two in the normal map vertex and fragment shaders.
I followed LearnOpenGl tutorials to make the directional light and the normal map :
https://learnopengl.com/Lighting/Light-casters
https://learnopengl.com/Advanced-Lighting/Normal-Mapping
I had first encountered a bug where my normal map texture would show in Render Doc but the whole scene was dark as if there wasn’t any light.
The problem came from this line in the fragment shader with the diffuse light :
Instead of TangentLightPos - TangentFragPos I only needed to change it to -TangentLightPos :
Here’s the normal map + directional light vertex shader :
Here’s the normal map + directional map fragment shader :
And then my scene had a light with some shadows and the normal texture.
Final Look
Here’s the final look with the camera moving in the scene :
Conclusion
To conclude, I honestly liked this module and learning about OpenGL. Unfortunately I couldn’t do as much as I wanted and work on all the other samples because I had to take care of my grandmother whose health worsened these last few months. I will probably keep on trying to work on the samples after this module to keep on learning about OpenGL and computer graphics.
Links
My repository : https://github.com/eleonoradps/DEMOGPR5300