Light and Shadows – Tech Demo
Languages: C++, GLSL
API: OpenGL 3.3
Tools and resources: GLFW, GLEW, Assimp, GLM
Implementation:
The algorithm works in two
different phases:
1. The first phase is the rendering to the depth map. The algorithm cycles through each face of the depth map and fills it like a 2D depth texture. Then for each light source, a virtual camera is used to be able to render the scene from the light point of view. For this, a unique Projection matrix is built having a 90 degree field of view, and for each direction the light is facing, a custom View matrix.
The rendering in this step uses a very basic vertex shader which only does the transformations according to the virtual camera and a pixel shader which does nothing because the filling of the depth buffer is done automatically after calling glEnable(GL_DEPTH_TEST).
2. The second phase and the most demanding one is the actual rendering. This is done in a single pass, the pixel shader being responsible for sampling the depth cube map. Because the sampled value is a depth value in [0, 1] interval, the vector from the point light to the pixel currently being processed needs to be converted so an actual comparison can be possible. In order to obtain this, the vector needs to be projected using the projection matrix of the virtual camera and converted to normalized device coordinates. After the comparison is done, the pixel can be decided if it is in shadow or not (A Survey on Methods for Omnidirectional Shadow Rendering. 2011).
To achieve a greater realism of the scene, a PCF method was implemented. It first transforms the vector direction into a texel position. Then it takes samples from around the obtained texel, translates them into a more suitable range, and the blends between the selected texels.
Cube
face size: 1024
Filter:
PCF – soft shadows
Cube
face size: 1024
Filter:
No – hard shadows
Cube
face size: 256
Filter:
No – hard shadows
Cube
face size: 256
Filter:
PCF – soft shadows
No comments:
Post a Comment