Pass 1: Drawing of the Depth Map

main.cpp

Now we are going to see what does the depth map look like.

in the shader initialisation part of main(), create the depth shader

blinnShader = initShader( "shaders/blinn.vert", "shaders/blinn.frag");
...

texblinnShader = initShader("shaders/texblinn.vert", "shaders/texblinn.frag");
...

// LabA09 Shadow Map
depthShader = initShader("shaders/simpledepth.vert", "shaders/simpledepth.frag");

...

Create the view and projection matrices from the light source

We are using orthographic projections. You need to adjust the view volume, especially the near and far planes to make sure every objects in your scene are included.

viewPos = ...
matView = ... 
matProj = ...

// LabA09 Shadow Map
matLightView = glm::lookAt(lightPos, glm::vec3(0, 0, 0), glm::vec3(0, 1, 0)); 
matLightProj = glm::ortho(-3.0f, 3.0f,-3.0f, 3.0f, -5.0f, 15.0f);

...

Before the event loop, add a call to initRenderToDepthTexture()

In the event loop, replace the drawings of your model/scene

Note: the view and projection matrics to the draw() function are matLightView and matLightProj

Result

You should see a depth map in gray. The following is an example, darker colours represent closer distance to the light source.

Last updated