事实上效果并不怎么好,因为延迟光照下的很多效果不支持正交,许多后期效果会炸掉,需要酌情使用
通过对投影矩阵进行插值来实现
如果透视相机的远截面和正交相机的远截面差太多,插值时会很奇怪,需要注意。
效果:
代码:
using UnityEngine; using System.Collections; public class ProjectionLerp : MonoBehaviour { [Range(0, 0.9f)] public float lerp; public float nearClip = -0.1f; public float size =3f; void Update() { var ratio = Screen.width / (float)Screen.height; var a = Matrix4x4.Perspective(45, ratio, 0.1f, 5000f); var b = Matrix4x4.Ortho(-size * ratio, size * ratio, -size, size, nearClip, 5000f); Camera.main.projectionMatrix = Lerp(a, b, lerp); } Matrix4x4 Lerp(Matrix4x4 a, Matrix4x4 b, float lerp) { var result = new Matrix4x4(); result.SetRow(0, Vector4.Lerp(a.GetRow(0), b.GetRow(0), lerp)); result.SetRow(1, Vector4.Lerp(a.GetRow(1), b.GetRow(1), lerp)); result.SetRow(2, Vector4.Lerp(a.GetRow(2), b.GetRow(2), lerp)); result.SetRow(3, Vector4.Lerp(a.GetRow(3), b.GetRow(3), lerp)); return result; } }
时间: 2024-10-27 12:31:18