修复摄像机的矩阵变换计算,让摄像机支持正交视图
This commit is contained in:
@@ -673,21 +673,20 @@ namespace XericLibrary.PostProcess
|
|||||||
float ndcYMin = passSampleRect.y * 2f - 1f;
|
float ndcYMin = passSampleRect.y * 2f - 1f;
|
||||||
float ndcYMax = (passSampleRect.y + passSampleRect.height) * 2f - 1f;
|
float ndcYMax = (passSampleRect.y + passSampleRect.height) * 2f - 1f;
|
||||||
|
|
||||||
// 将 NDC 子区域 [ndcMin, ndcMax] 映射到 [-1, 1]
|
// 使用 remap 矩阵将 NDC 子区域映射到 [-1, 1]
|
||||||
// 投影矩阵变换: ndc = -m00 * viewX/viewZ - m02
|
// remap * proj 在 clip space 中做仿射变换:
|
||||||
// 修改后: ndc_new = scale * ndc_original - offset
|
// clipX' = remap.m00 * clipX + remap.m03 * clipW
|
||||||
// ndcMin → -1: scale * ndcMin - offset = -1 → offset = scale * ndcMin + 1
|
// clipW' = clipW(不变)
|
||||||
// ndcMax → +1: scale * ndcMax - offset = +1 → scale = 2/(ndcMax - ndcMin)
|
// ndc' = clipX'/clipW' = remap.m00 * ndc + remap.m03
|
||||||
float scaleX = 2f / (ndcXMax - ndcXMin);
|
// 边界: ndcMin → -1, ndcMax → +1
|
||||||
float scaleY = 2f / (ndcYMax - ndcYMin);
|
// 此法对透视投影和正交投影均正确
|
||||||
float offsetX = 1f + ndcXMin * scaleX;
|
Matrix4x4 remap = Matrix4x4.identity;
|
||||||
float offsetY = 1f + ndcYMin * scaleY;
|
remap.m00 = 2f / (ndcXMax - ndcXMin);
|
||||||
|
remap.m03 = -(ndcXMax + ndcXMin) / (ndcXMax - ndcXMin);
|
||||||
projMatrix.m00 *= scaleX;
|
remap.m11 = 2f / (ndcYMax - ndcYMin);
|
||||||
projMatrix.m11 *= scaleY;
|
remap.m13 = -(ndcYMax + ndcYMin) / (ndcYMax - ndcYMin);
|
||||||
projMatrix.m02 += offsetX;
|
|
||||||
projMatrix.m12 += offsetY;
|
|
||||||
|
|
||||||
|
projMatrix = remap * projMatrix;
|
||||||
projMatrix = GL.GetGPUProjectionMatrix(projMatrix, true);
|
projMatrix = GL.GetGPUProjectionMatrix(projMatrix, true);
|
||||||
cmd.SetViewProjectionMatrices(viewMatrix, projMatrix);
|
cmd.SetViewProjectionMatrices(viewMatrix, projMatrix);
|
||||||
cmd.SetViewport(new Rect(0, 0, passRTHandle.rt.width, passRTHandle.rt.height));
|
cmd.SetViewport(new Rect(0, 0, passRTHandle.rt.width, passRTHandle.rt.height));
|
||||||
@@ -962,6 +961,11 @@ namespace XericLibrary.PostProcess
|
|||||||
if (rawData.Length == 0) return;
|
if (rawData.Length == 0) return;
|
||||||
|
|
||||||
// 修复:使用 m_ReadbackBufferHandle.rt 获取宽高
|
// 修复:使用 m_ReadbackBufferHandle.rt 获取宽高
|
||||||
|
if (m_ReadbackBufferHandle == null)
|
||||||
|
{
|
||||||
|
Debug.LogWarning("[GeoLayerPicker] 更新时机不对!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
int width = m_ReadbackBufferHandle.rt.width;
|
int width = m_ReadbackBufferHandle.rt.width;
|
||||||
int height = m_ReadbackBufferHandle.rt.height;
|
int height = m_ReadbackBufferHandle.rt.height;
|
||||||
int count = m_DecodedDataArray.Length;
|
int count = m_DecodedDataArray.Length;
|
||||||
|
|||||||
Reference in New Issue
Block a user