Issue with using render texture and custom projection matrix
I have a screenshot script that can make a Screenshot in a different resolution and apsect ratio than the App Screen size. Along with that I also offset the camera a bit (Obliqueness). This may not be easy to grasp by I try to describe it.
It works fine in the preview where AdjustCameraViewport is called in Update() but once I make my screenshot the oblique value does not seem to change. So what I wonder is if when I set the renderTarget if that does not update the projection matrix accordingly as I have limited knowledge of these kind of things.
Becuase what happens is when I scale my screen to the render target aspect ratio then the result is correct. If I offset the image horizontally then the value is greater if my screen aspect is smaller than rt.aspect and the olbiqueness is lesser when my screen aspect is bigger. So my conclusion is that the matrix is still the same in some way. Because when I manipulate the obliqueness (seet to 0 or increase by 1000) only in "Line X" it has no effect at all and the previously described results come out.
Here is basically my render call:
SkyCamera.targetTexture = rt;
CameraController.AdjustCameraViewport(rt.width, rt.height, false, true); //Line X
yield return new WaitForEndOfFrame();
SkyCamera.Render();
You can see the methods below. You can ignore the fieldOfView part, it works as it should. I can confirm that hob and vob values are correct, I debugged them.
public void AdjustCameraViewport(float width, float height, bool activeCam = true, bool skyCam = true)
{
float aspect = width / height;
float hob = HoriOblique / aspect;
float vob = VertOblique * aspect;
if (activeCam)
{
CameraScissorRect.SetObliqueness(Camera, hob, vob);
Camera.fieldOfView = GetAdjustedFov(curFov, aspect);
}
if (skyCam)
{
CameraScissorRect.SetObliqueness(SkyCamera, hob, vob);
SkyCamera.fieldOfView = GetAdjustedFov(curFovBackground, aspect);
}
}
public static void SetObliqueness(Camera cam, float horizObl, float vertObl)
{
cam.ResetProjectionMatrix();
Matrix4x4 mat = cam.projectionMatrix;
mat[0, 2] = horizObl;
mat[1, 2] = vertObl;
cam.projectionMatrix = mat;
}