I am creating a planar reflection camera script that mirror the main camera and I am using camera.CalculateObliqueMatrix to clip out objects that are behind the plane. The code looks like this:
var plane = _reflectionCamera.cameraToWorldMatrix.transpose * clipPlane;
var obliqueMatrix = _reflectionCamera.CalculateObliqueMatrix(plane);
_reflectionCamera.projectionMatrix = obliqueMatrix;
Then I wrote this code to get the new frustum corners to draw it out:
var m = camera.cameraToWorldMatrix * camera.projectionMatrix.inverse;
points[0] = m.MultiplyPoint(new Vector3(-1f, -1f, -1f));
points[1] = m.MultiplyPoint(new Vector3(-1f, 1f, -1f));
points[2] = m.MultiplyPoint(new Vector3( 1f, 1f, -1f));
points[3] = m.MultiplyPoint(new Vector3( 1f, -1f, -1f));
points[4] = m.MultiplyPoint(new Vector3(-1f, -1f, 1f));
points[5] = m.MultiplyPoint(new Vector3(-1f, 1f, 1f));
points[6] = m.MultiplyPoint(new Vector3( 1f, 1f, 1f));
points[7] = m.MultiplyPoint(new Vector3( 1f, -1f, 1f));
The frustum looks correct when the main camera is looking straight down at the plane.
However, if I look at the plane at an angle, the far plane of the frustum starts to stretch,
and as the angle gets steeper the top and far plane become closer to parallel with each other, as a result the frustum is stretched to infinity.
While this works fine at clipping out objects that are behind the plane, it loses the ability to clip objects that are behind the far plane. What my expected result is this:
Does anybody know how to get the desired result?