ssloy/tinyrenderer

Different Projection matrices for shadow mapping(Lesson 7)

XiaofanLinUS opened this issue · 2 comments

I see that you use orthogonal projection matrix to create shadow map.

However, I am curious if it is possible to use perspective matrix instead. I am not sure if my tuition is right. For directional light like sun, orthogonal projection matrix is used since the light rays are parallel. But for the point light, since light converges to a single point, it is better to use perspective matrix?

If it is possible for point light to use perspective projection to create shadow map. How are the parameters in the perspective matrix adjusted to match a proper point light condition. Thanks.

Sincerely,
Xiaofan

ssloy commented

Well, it is exactly the same as for the camera:

  1. you set up the view direction with the code that looks like this:

    void lookat(const vec3 eye, const vec3 center, const vec3 up) { // check https://github.com/ssloy/tinyrenderer/wiki/Lesson-5-Moving-the-camera

  2. you set the distance to the light via the projection matrix

    void projection(const double f) { // check https://en.wikipedia.org/wiki/Camera_matrix