Approaching DARKNESS — Shadow Mapping

A scene without shadow is super unrealistic. How we can add some shadows?

Are you in shadow? My dear pixel

We connect a line from the light source to the point in the world. We compare two distances

  • D1 = between light to the point
  • D2 = between the light and the nearest hit.

If D1 < D2, then this point is in shadow!

Shadow map in need!

How to get D1?

This one is pretty easy — distance between two points in 3D space.

How to get D2?

We put a camera at the light source, and render an image of the scene from there! We only need depth information of this image. And it will be used for rendering shadow. So we call it Shadow Map. The depth value in the shadow map is D2.

Headache 3D math 🤯

We need to transform a single location in world between

  • camera view coordinates system
  • light view coordinates system

We need the sample location in shadow map, for a pixel in camera view coordinates system.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store