diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index dcb283334df..804fda3ff16 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -126,6 +126,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Implemented ray traced reflections for transparent objects. - Add a new parameter to control reflections in recursive rendering. - Added an initial version of SSGI. +- Added back-compatibility with builtin stereo matrices. ### Fixed - Fix when rescale probe all direction below zero (1219246) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 09de756b62f..3d7b15cbf7e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -1136,6 +1136,7 @@ void UpdateShaderVariablesGlobalCB(HDCamera hdCamera, CommandBuffer cmd) ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesGlobalCB, HDShaderIDs._ShaderVariablesGlobal); + hdCamera.xr.UpdateBuiltinStereoMatrices(cmd); hdCamera.UpdateShaderVariablesXRCB(ref m_ShaderVariablesXRCB); ConstantBuffer.PushGlobal(cmd, m_ShaderVariablesXRCB, HDShaderIDs._ShaderVariablesXR); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/XR/XRPass.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/XR/XRPass.cs index a4523b22549..40a635b4a39 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/XR/XRPass.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/XR/XRPass.cs @@ -182,7 +182,7 @@ internal void AddViewInternal(XRView xrView) { Debug.LogWarning("If you're trying to enable XR single-pass after the first frame, you need to set TextureXR.maxViews to 2 before the render pipeline is created (typically in a script with Awake())."); } - + throw new NotImplementedException($"Invalid XR setup for single-pass, trying to add too many views! Max supported: {maxSupportedViews}"); } } @@ -274,5 +274,30 @@ internal void RenderOcclusionMeshes(CommandBuffer cmd, RTHandle depthBuffer) } } } + + static readonly int _unity_StereoMatrixV = Shader.PropertyToID("unity_StereoMatrixV"); + static readonly int _unity_StereoMatrixP = Shader.PropertyToID("unity_StereoMatrixP"); + static readonly int _unity_StereoMatrixVP = Shader.PropertyToID("unity_StereoMatrixVP"); + Matrix4x4[] builtinViewMatrix = new Matrix4x4[2]; + Matrix4x4[] builtinProjMatrix = new Matrix4x4[2]; + Matrix4x4[] builtinViewProjMatrix = new Matrix4x4[2]; + + // Maintain compatibility with builtin renderer + internal void UpdateBuiltinStereoMatrices(CommandBuffer cmd) + { + if (singlePassEnabled) + { + for (int viewIndex = 0; viewIndex < 2; ++viewIndex) + { + builtinViewMatrix[viewIndex] = GetViewMatrix(viewIndex); + builtinProjMatrix[viewIndex] = GL.GetGPUProjectionMatrix(GetProjMatrix(viewIndex), true); + builtinViewProjMatrix[viewIndex] = builtinProjMatrix[viewIndex] * builtinViewMatrix[viewIndex]; + } + + cmd.SetGlobalMatrixArray(_unity_StereoMatrixV, builtinViewMatrix); + cmd.SetGlobalMatrixArray(_unity_StereoMatrixP, builtinProjMatrix); + cmd.SetGlobalMatrixArray(_unity_StereoMatrixVP, builtinViewProjMatrix); + } + } } } diff --git a/com.unity.testing.hdrp/TestRunner/HDRP_TestSettings.cs b/com.unity.testing.hdrp/TestRunner/HDRP_TestSettings.cs index d95eb181660..fd673a19472 100644 --- a/com.unity.testing.hdrp/TestRunner/HDRP_TestSettings.cs +++ b/com.unity.testing.hdrp/TestRunner/HDRP_TestSettings.cs @@ -30,10 +30,6 @@ public class HDRP_TestSettings : GraphicsTestSettings void Awake() { - // Built-in font shaders are incompatible with XR, replace them with a ShaderGraph version - if (XRSystem.testModeEnabled && xrCompatible) - doBeforeTest.AddListener(ReplaceBuiltinFontShaders); - if (renderPipelineAsset == null) { Debug.LogWarning("No RenderPipelineAsset has been assigned in the test settings. This may result in a wrong test."); @@ -60,31 +56,4 @@ void OnApplicationQuit() quitDebug.Clear(); } - - void ReplaceBuiltinFontShaders() - { -#if UNITY_EDITOR - var fontMaterialSG = AssetDatabase.LoadAssetAtPath("Packages/com.unity.testing.hdrp/Fonts/Font Material SG.mat"); - if (fontMaterialSG != null) - { - foreach (var textMesh in GameObject.FindObjectsOfType()) - { - var textMeshRenderer = textMesh.gameObject.GetComponent(); - - if (!textMeshRenderer.material.shader.name.StartsWith("Shader Graphs")) - { - // From Unity source: Runtime\Resources\Assets\DefaultResources\Font.shader - var fontTexture = textMeshRenderer.material.GetTexture("_MainTex"); - var fontColor = textMeshRenderer.material.GetColor("_Color"); - - textMeshRenderer.material = fontMaterialSG; - textMeshRenderer.material.SetTexture("_MainTex", fontTexture); - textMeshRenderer.material.SetColor("_Color", fontColor); - - textMeshRenderer.shadowCastingMode = ShadowCastingMode.Off; - } - } - } -#endif - } }