Calculate camera projection matrix so that it covers a specified rect

We have a bunch of mirrors in our game, and we need to efficiently render reflections for all of them. Usual planar reflection probe algorithms dont account for the reflection surface area and as a result render more than necessary (and standard HDRP planar reflection probes dont align to the reflection vector at all, so you have to crank up the FOV to get reflections on grazing angles, which is obviously bad). How would i go about calculating the projection matrix that would only cover a specified rect? Heres the illustration of couple examples of what i mean (top-down view, green is the rect, blue is the frustum, black is the reflection camera). Also I dont need oblique projection, since im doing clipping in the shader and i need a proper control over far clip plane (since with oblique projection far clip plane doesnt clip as expected).

Nevermind, this article explains everything i needed to know.

1 Like