Thursday, May 2, 2013

Graphics Assignment 12

This week's assignment was on Shadows. Shadows only work for opaque entities. To make the entities in your scene cast shadows you first need directional light. We use directional light for shadows because unlike a point light, directional light doesn't much change with the position of the light. To cast a shadow we need directional light's position and then conceptually like we do a ray cast, we create a shadow map of the scene from the light's position. It is the same as creating the view Depth map but from light's perspective. So, Instead of passing the world_to_view transform and view_to_projected transform matrices, we pass  world_to_light transform and light_to_projected transform matrices. Thus we get depth map from light's perspective(shadow Map).

   While drawing the opaque bucket, we calculate the object's position in light space and also light_to_projected space. We pass these values to fragment shader as textcoords. In fragment shader we pass the previously created shadow map as sampler2D. We W divide the projected space(from light) and get the coordinates from -1 to 1, to 0 to 1.We sample the shadow map at this value and take the x coordinate as it contains the depth. This gives us the previous depth. We compare the previous depth with new depth, that is z coordinate of object in light space. If the previous depth value is greater than the new depth value then that pixel is not in shadow otherwise it is in shadow.

PIX of shadow map from projected(light's) space:



No comments:

Post a Comment