mathe/Library/PackageCache/com.unity.render-pipelines.core@14.0.8/Runtime/XR/XRView.cs

35 lines
1.3 KiB
C#
Raw Normal View History

2024-09-20 20:30:10 +02:00
using System;
namespace UnityEngine.Experimental.Rendering
{
internal readonly struct XRView
{
internal readonly Matrix4x4 projMatrix;
internal readonly Matrix4x4 viewMatrix;
internal readonly Rect viewport;
internal readonly Mesh occlusionMesh;
internal readonly int textureArraySlice;
internal readonly Vector2 eyeCenterUV;
internal XRView(Matrix4x4 projMatrix, Matrix4x4 viewMatrix, Rect viewport, Mesh occlusionMesh, int textureArraySlice)
{
this.projMatrix = projMatrix;
this.viewMatrix = viewMatrix;
this.viewport = viewport;
this.occlusionMesh = occlusionMesh;
this.textureArraySlice = textureArraySlice;
eyeCenterUV = ComputeEyeCenterUV(projMatrix);
}
private static Vector2 ComputeEyeCenterUV(Matrix4x4 proj)
{
var projectionParameters = proj.decomposeProjection;
float left = Math.Abs(projectionParameters.left);
float right = Math.Abs(projectionParameters.right);
float top = Math.Abs(projectionParameters.top);
float bottom = Math.Abs(projectionParameters.bottom);
return new Vector2(left / (right + left), top / (top + bottom));
}
}
}