2
\$\begingroup\$

I need to render a small portion of the display to a texture.

I found a script to simulate a scissor rect by modifying the projection matrix - Unity 5 doesn't seem to provide any out-of-the-box scissor functionality. However, modifying the matrix in this way causes my scene to render monoscopic.

Suggestions? There used to be an OVRCameraController class that provided a SetVerticalFOV() method, but that appears to have been removed from the SDK.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

So, the best (only) way I've found of doing this is to modify the projection matrix before rendering. Given a scale and a center position,

var center = new Vector2(....);
var scale = new Vector2(....);

var zoomPanMatrix = Matrix4x4.Scale(scale);
/// offset view X (screen)
zoomPanMatrix.m03 += (1 - 2 * center.x) * scale.x;
/// offset view Y (screen)
zoomPanMatrix.m13 += (1 - 2 * center.y) * scale.y;

This creates a matrix that zooms in (scale) and pans to (center) the area of interest, in screen space.

On a side note, this also works if you want to, say, render a part of a larger image for a display wall, super-high res tiled image files, etc.

When rendering (I'm rendering to a texture, so this code is in OnRenderImage())

var originalProjectionMatrix = cam.projectionMatrix;

cam.projectionMatrix = zoomPanMatrix * originalProjectionMatrix;

cam.Render();

cam.projectionMatrix = originalProjectionMatrix;

If you want to take advantage of this for frustum culling, do the above and clip against the resulting frustum.

There's probably a way to do this with an oblique projection matrix. Good luck with that. I also played with concatenating an offset orthographic matrix - which should work - but didn't spend a lot of time on it,

I have to modify center based on which eye is rendering to get real stereo, but it works fine.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.