Given that I have the TerrainShader
class and DefaultShader
class. Also a FBO (Frame Buffer Object) shadow map
The TerrainShader
has all the terrain, light, shadow related calculations. While the DefaultShader
has the generic objects light, shadow related calculations.
I have successfully cast a directional shadow map when I only use DefaultShader
alone with random cube objects and a plane. Now the problem was when I move or use a terrain instead of TerrainShader
, the shadow is not cast in the terrain.
Question: Am I using the FBO the correct way or I am doing it wrong.
Solution Idea (Not yet applied)
- Merge terrain and default shader as one and create a flag if object or terrain will be rendered? (Still not sure if this is correct.)
Pseudocode (Current successful implementation)
- Create shadow map fbo
- Create default shader
- Create depth shader
- bind shadow map fbo
- clear depth
- render cubes & plane using depth shader (mvp)
- unbind shadow map fb
- clear color and depth
- render cubes & plane using default shader
Pseudocode (with Terrain shadow not working)
- Create shadow map fbo
- Create default shader
- Create terrain shader
- Create depth shader
- bind shadow map fbo
- clear depth
- render cubes & plane using depth shader (mvp) and exclude terrain
- unbind shadow map fb
- clear color and depth
- render cubes using default shader
- render terrain using terrain shader