Created
October 30, 2018 14:36
-
-
Save Bradshaw/5333bcf73d26075dee56320e9ff1edb0 to your computer and use it in GitHub Desktop.
Use this with a Unity camera set to orthographic projection in an oblique top-down view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class StretchProject : MonoBehaviour { | |
public Matrix4x4 originalProjection; | |
Camera cam; | |
[Range(1,2)] | |
public float stretch = 1; | |
[Range(0,0.95f)] | |
public float squash; | |
Matrix4x4 p; | |
Matrix4x4 w; | |
public bool squashAndStretch = true; | |
void Start() | |
{ | |
cam = GetComponent<Camera>(); | |
originalProjection = cam.projectionMatrix; | |
} | |
void OnPreCull() | |
{ | |
cam.ResetWorldToCameraMatrix(); | |
p = originalProjection; | |
if (squashAndStretch){ | |
p.m11 = originalProjection.m11 * stretch; | |
w = cam.worldToCameraMatrix; | |
w = w * Matrix4x4.Scale( Vector3.one - Vector3.up*squash); | |
cam.worldToCameraMatrix = w; | |
} | |
cam.projectionMatrix = p; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment