OpenGL lighting
OpenGL implementation of different light casters and specular maps that follow Phong lighting model
Three Part Implementation
First part demostrates how basic Phong lighting model works, including combination of ambient, diffuse and specular lighting.
- Ambient lighting represents some distant bounced off light. Basically we imagine as all of our objects always have some amount of light to it, it's never complete darkness.
- Diffuse lighting represents the influence or exposure of some surface to the light source. It's basically a dot product calculation of light's direction and surface's normal vector.
- Specular lighting represents the "shininess" of surface's material. It's calculated as a reflection of light's direction across the surface's normal, and depending from which angle we are looking at it, it will show more light in that area.
Phong lighting model
Second part demonstrates how specular maps are implemented in order to achieve different specular reflections depending on the material. In it's most basic concept, we are using one texture to for visual representation, while using the other texture to perform our calculations on.
This way, specular map for wooden part in the following example, can be just a black box, meaning it won't reflect anything, because black is represented as a 0 vector, meaning all of our vector multiplications will be equal to 0.
On the other hand, metalic parts in the following example, can have brighter values in certain areas, meaning our vector multiplications will actually return a brighter value in some cases, visually represented as some hilights.
Specular map demostration
Third part demonstrates various light caster implementation, including:
- Directional light which just represents some large light source far away, like the Sun. All it is under the hood is a directional vector.
- Point light is a light source with given position somewhere in the world, which illuminates in all directions, however, it's light rays fade out over distance.
Trickiest part about this was getting the right attenuation of the light, because in nature, real light doesn't fade out linearly. It's actually really strong near the source, then has a very sudden drop over smaller distance, and then it fades out really slowly over longer distance. So getting this calculation right was a bit of a challenge.
- Spot light is a light source, that unlike point light which illuminates in all directions, actually illuminates only in one specific direction. In this project, it's implemented like a horror game style flashlight shooting from the camera.
All parts of the project combined.
Technologies used
- C/C++
- OpenGL
- GLSL
- Fully developed and built on Linux system