Skip to content

Commit abc0bd6

Browse files
JangkyuSeoEvergreen
authored andcommitted
Merge PR #62772 from graphics/urp/xr/uum-75383
1 parent fd8b50d commit abc0bd6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Packages/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,33 @@ internal void PushBuiltinShaderConstantsXR(CommandBuffer cmd, bool renderIntoTex
236236
}
237237
else
238238
{
239+
240+
Matrix4x4 viewMatrix = GetViewMatrix();
239241
// Update multipass worldSpace camera pos
240242
Vector3 worldSpaceCameraPos = Matrix4x4.Inverse(GetViewMatrix(0)).GetColumn(3);
241243
cmd.SetGlobalVector(ShaderPropertyId.worldSpaceCameraPos, worldSpaceCameraPos);
244+
245+
//Multipass uses the same value as a normal render, and doesn't use the value set for stereo,
246+
//which is why you need to set a value like unity_MatrixInvV.
247+
//The values below should be the same as set in the SetCameraMatrices function in ScriptableRenderer.cs.
248+
Matrix4x4 gpuProjectionMatrix = GetGPUProjectionMatrix(renderIntoTexture);
249+
Matrix4x4 viewAndProjectionMatrix = gpuProjectionMatrix * viewMatrix;
250+
Matrix4x4 inverseViewMatrix = Matrix4x4.Inverse(viewMatrix);
251+
Matrix4x4 inverseProjectionMatrix = Matrix4x4.Inverse(gpuProjectionMatrix);
252+
Matrix4x4 inverseViewProjection = inverseViewMatrix * inverseProjectionMatrix;
253+
254+
// There's an inconsistency in handedness between unity_matrixV and unity_WorldToCamera
255+
// Unity changes the handedness of unity_WorldToCamera (see Camera::CalculateMatrixShaderProps)
256+
// we will also change it here to avoid breaking existing shaders. (case 1257518)
257+
Matrix4x4 worldToCameraMatrix = Matrix4x4.Scale(new Vector3(1.0f, 1.0f, -1.0f)) * viewMatrix;
258+
Matrix4x4 cameraToWorldMatrix = worldToCameraMatrix.inverse;
259+
cmd.SetGlobalMatrix(ShaderPropertyId.worldToCameraMatrix, worldToCameraMatrix);
260+
cmd.SetGlobalMatrix(ShaderPropertyId.cameraToWorldMatrix, cameraToWorldMatrix);
261+
262+
cmd.SetGlobalMatrix(ShaderPropertyId.inverseViewMatrix, inverseViewMatrix);
263+
cmd.SetGlobalMatrix(ShaderPropertyId.inverseProjectionMatrix, inverseProjectionMatrix);
264+
cmd.SetGlobalMatrix(ShaderPropertyId.inverseViewAndProjectionMatrix, inverseViewProjection);
265+
242266
}
243267
}
244268
#endif

0 commit comments

Comments
 (0)