ssloy / tinyrenderer

A brief computer graphics / rendering course
https://github.com/ssloy/tinyrenderer/wiki
Other
20.73k stars 1.99k forks source link

Different Projection matrices for shadow mapping(Lesson 7) #108

Closed XiaofanLinUS closed 2 years ago

XiaofanLinUS commented 2 years ago

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 2 years ago

Well, it is exactly the same as for the camera: 1) you set up the view direction with the code that looks like this: https://github.com/ssloy/tinyrenderer/blob/dbc5d9287610e993a09bce89dec459162c925abe/our_gl.cpp#L16

2) you set the distance to the light via the projection matrix https://github.com/ssloy/tinyrenderer/blob/dbc5d9287610e993a09bce89dec459162c925abe/our_gl.cpp#L12

XiaofanLinUS commented 2 years ago

k