Graphics, C++, OpenGL
April, 2022 - May, 2022
A city generated procedurally in a custom graphics engine. Project created in C++ using OpenGL.
This project consists of the procedural generation and
rendering of a cityusing the EDK3, an educational engine
developed by ESAT University. Along with my colleage
Carmen Martín Moreno,
we developed the graphic core of the engine using OpenGL and GLSL.
The repository of this project is private but temporary access may be
given to anyone interested in its implementation.
Contact me for more information.
I designed the lighting system as a manager object that would manage all the lights of the scene.
I created three light classes (directional light, spot light and point light) that can be placed in the scene and added to the scene hierarchy. These classes can only be instantiated by the LightManager to ensure that every light is tracked by the manager.
When rendering, the lights are passed to the LitMaterial object and their information is uploaded to the GPU when using that material. The camera position is also uploaded to calculate the specular reflection.
The LitMaterial uses a fragment shader that implements the Phong lightning model. Each light type
is calculated separatedly and then added together. The calculation of the value of each light is done taking into account the ambient, diffuse and specular colors of the light as well as the diffuse and specular textures of the material.
Due to the Phong model limitations, the max amount of lights in the scene are limited. As the cost of adding new lights escalates quickly.
When designing and implementing the lights, I wanted them to have the typical halo that
you see in videogames (and in real life). To do so, I had to have a quad in the same position
of the light with the texture of a halo. This quad had to be rotated each frame so that its forward vector was the opposite of the camera's forward vector.
I could not figure out how to do this on the CPU, as it generated many problems due to the architecture of the engine we were working on. As an alternative, I researched how geometry shaders worked (as I had a vague idea of what they did) and decided to try this way.
The final solution that I implemented was that each light had a HaloMaterial with a specific vertex, geometry and fragment shader. For each light, I uploaded their position as a single vertex to the vertex shader. Then, in the geometry shader, I used that point and the forward vector of the camera (passed as a uniform) to generate a quad that faced the camera. Finally, in the fragment shader I setted the halo texture to the quad.
I implemented the fog effect as an attribute of the LightingManager and can be parametrized through the manager. The fog is calculated using the exponential formula for the fog. The final color of the lit fragment shader is a mix between the color of the fog and the calculated color of the fragment.
I implemented all the postprocessing effects of the Engine, which are: