diff --git a/Assets/Plugins/Windows/GfxPluginNativeRender.dll b/Assets/Plugins/Windows/GfxPluginNativeRender.dll index d4f2ea6..b4d75f2 100644 Binary files a/Assets/Plugins/Windows/GfxPluginNativeRender.dll and b/Assets/Plugins/Windows/GfxPluginNativeRender.dll differ diff --git a/Assets/Settings/Mobile/Mobile_High.asset b/Assets/Settings/Mobile/Mobile_High.asset index db4fccc..b1a6030 100644 --- a/Assets/Settings/Mobile/Mobile_High.asset +++ b/Assets/Settings/Mobile/Mobile_High.asset @@ -28,7 +28,7 @@ MonoBehaviour: m_SupportsHDR: 1 m_HDRColorBufferPrecision: 0 m_MSAA: 1 - m_RenderScale: 0.6 + m_RenderScale: 0.75 m_UpscalingFilter: 0 m_FsrOverrideSharpness: 1 m_FsrSharpness: 1 @@ -115,5 +115,5 @@ MonoBehaviour: m_ShaderVariantLogLevel: 0 m_ShadowCascades: 0 superResolution: 14 - sSRenderScale: 4 + sSRenderScale: 3 vrsRate: 0 diff --git a/Assets/Settings/Mobile/Mobile_High_Renderer.asset b/Assets/Settings/Mobile/Mobile_High_Renderer.asset index 3b3ffd6..396e5a4 100644 --- a/Assets/Settings/Mobile/Mobile_High_Renderer.asset +++ b/Assets/Settings/Mobile/Mobile_High_Renderer.asset @@ -145,23 +145,24 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c3c4391133b9f3142b57264047029ec5, type: 3} m_Name: XESS m_EditorClassIdentifier: - m_Active: 1 + m_Active: 0 xess1ConfigParam: OutputWidth: 1920 OutputHeight: 1080 Quality: 103 - UseHiResMotionVectors: 1 + UseHiResMotionVectors: 0 UseJitteredMotionVectors: 0 - UseMotionVectorsInNDC: 0 + UseMotionVectorsInNDC: 1 UseExposureTexture: 0 UseResponsiveMask: 0 UseAutoExposure: 0 EnableProfiling: 0 - VelocityScaleX: 1 - VelocityScaleY: 1 + VelocityScaleX: -2 + VelocityScaleY: 2 JitterScaleX: 1 JitterScaleY: 1 ExposureScale: 1 + MipMapBias: -1.91 --- !u!114 &1524480044783497712 MonoBehaviour: m_ObjectHideFlags: 0 @@ -174,14 +175,14 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a6b8ba513f1b1fe499924f362fdde22d, type: 3} m_Name: GSR m_EditorClassIdentifier: - m_Active: 0 + m_Active: 1 v1settings: EnableEdgeDirection: 1 Mode: 1 Sharp: 2 GSRV1Material: {fileID: 2100000, guid: d57e64d5723127243b429034bed82c7d, type: 2} v2settings: - UseCompute2Pass: 1 + UseCompute2Pass: 0 GSRV2Material: {fileID: 2100000, guid: faa906817c0647f42a0cec70faeb91c1, type: 2} GSRV2ComputeShader: {fileID: 7200000, guid: 9a4e6ff1f9a33fa4ea1e9744e313e2fd, type: 3} FiveSample: 0 diff --git a/NativeRenderPlugin/features/xess1/xess.cpp b/NativeRenderPlugin/features/xess1/xess.cpp index 8951ce5..5c3c036 100644 --- a/NativeRenderPlugin/features/xess1/xess.cpp +++ b/NativeRenderPlugin/features/xess1/xess.cpp @@ -126,6 +126,8 @@ struct Xess1ConfigParam /// If enable GPU profiling. bool EnableProfiling; + bool InvertedDepth; + float VelocityScaleX; float VelocityScaleY; @@ -145,6 +147,7 @@ struct Xess1ExecParam void* ColorTexture; void* VelocityTexture; void* OutputTexture; + void* DepthTexture; }; bool XessV13::configxess(void* data) @@ -181,6 +184,10 @@ bool XessV13::configxess(void* data) { params.initFlags |= XESS_D3D12_DEBUG_ENABLE_PROFILING; } + if (config->InvertedDepth) + { + params.initFlags |= XESS_INIT_FLAG_INVERTED_DEPTH; + } params.pPipelineLibrary = nullptr; @@ -232,7 +239,7 @@ void XessV13::execute(void* data, ID3D12GraphicsCommandList* cmd_list) params.pColorTexture = (ID3D12Resource*)param->ColorTexture; params.pVelocityTexture = (ID3D12Resource*)param->VelocityTexture; params.pOutputTexture = (ID3D12Resource*)param->OutputTexture; - params.pDepthTexture = nullptr; + params.pDepthTexture = (ID3D12Resource*)param->DepthTexture; params.pExposureScaleTexture = nullptr; params.pResponsivePixelMaskTexture = nullptr; diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/Passes/PostProcessPass.cs b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/Passes/PostProcessPass.cs index 9562362..0a14a39 100644 --- a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/Passes/PostProcessPass.cs +++ b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/Passes/PostProcessPass.cs @@ -501,9 +501,11 @@ namespace UnityEngine.Rendering.Universal ref var colorDescriptor = ref cameraData.cameraTargetDescriptor; colorDescriptor.width = cameraData.camera.pixelWidth; colorDescriptor.height = cameraData.camera.pixelHeight; - - colorDescriptor.graphicsFormat = GraphicsFormat.R16G16B16A16_SFloat; - colorDescriptor.enableRandomWrite = true; // compute + if (asset.SuperResolution == ESuperResolution.XESS13) + { + colorDescriptor.graphicsFormat = GraphicsFormat.R16G16B16A16_SFloat; + colorDescriptor.enableRandomWrite = true; // compute + } renderer.m_ColorBufferSystem.SetCameraSettings(colorDescriptor, FilterMode.Bilinear); diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/ScriptableRenderer.cs b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/ScriptableRenderer.cs index 06288ee..4de6e9e 100644 --- a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/ScriptableRenderer.cs +++ b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/ScriptableRenderer.cs @@ -275,6 +275,7 @@ namespace UnityEngine.Rendering.Universal // Temporal Anti-aliasing can use negative mip bias to increase texture sharpness and new information for the jitter. float taaMipBias = Math.Min(cameraData.taaSettings.mipBias, 0.0f); mipBias = Math.Min(mipBias, taaMipBias); + // TODO: xyang Mip bias cmd.SetGlobalVector(ShaderPropertyId.globalMipBias, new Vector2(mipBias, Mathf.Pow(2.0f, mipBias))); //Set per camera matrices. diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SF/FG.cs b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SF/FG.cs index 78620d0..b821488 100644 --- a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SF/FG.cs +++ b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SF/FG.cs @@ -58,6 +58,7 @@ namespace X.Rendering.Feature public static void RecordFrame(RTHandle source, CommandBuffer cmd) { +#if UNITY_ANDROID && !UNITY_EDITOR presented = false; var index = frameIndex++ % 2; var desc = source.rt.descriptor; @@ -70,6 +71,8 @@ namespace X.Rendering.Feature RenderingUtils.ReAllocateIfNeeded(ref presentRt, desc); var history = historys[index]; cmd.Blit(source, history); +#endif + } } } diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/XESS.cs b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/XESS.cs index a26c222..b8b97a9 100644 --- a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/XESS.cs +++ b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/XESS.cs @@ -39,7 +39,7 @@ namespace X.Rendering.Feature public bool UseAutoExposure; /// If enable GPU profiling. public bool EnableProfiling; - + public bool InvertedDepth; public float VelocityScaleX; public float VelocityScaleY; @@ -47,6 +47,9 @@ namespace X.Rendering.Feature public float JitterScaleY; public float ExposureScale; + + [Range(-5,5)] + public float MipMapBias; }; [StructLayout(LayoutKind.Sequential)] @@ -61,6 +64,7 @@ namespace X.Rendering.Feature public IntPtr ColorTexture; public IntPtr VelocityTexture; public IntPtr OutputTexture; + public IntPtr DepthTexture; }; internal unsafe class XESS : ScriptableRendererFeature, ISuperResolutionFeature @@ -72,6 +76,7 @@ namespace X.Rendering.Feature private bool needTurnOffXess = false; IntPtr xess1ExecParamPtr; IntPtr xess1ConfigParamPtr; + private ProfilingSampler profiler; public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) { @@ -82,6 +87,7 @@ namespace X.Rendering.Feature xess1ExecParamPtr = Marshal.AllocHGlobal(sizeof(Xess1ExecParam)); xess1ConfigParamPtr = Marshal.AllocHGlobal(sizeof(Xess1ConfigParam)); needTurnOnXess = true; + profiler = new ProfilingSampler("Xess1"); } protected override void Dispose(bool disposing) @@ -91,8 +97,43 @@ namespace X.Rendering.Feature Marshal.FreeHGlobal(xess1ConfigParamPtr); } + static internal Matrix4x4 CalculateJitterMatrix(ref CameraData cameraData, out Vector2 jitter) + { + Matrix4x4 jitterMat = Matrix4x4.identity; + + jitter = Vector2.zero; + { + int taaFrameIndex = Time.frameCount; + + float actualWidth = cameraData.cameraTargetDescriptor.width; + float actualHeight = cameraData.cameraTargetDescriptor.height; + float jitterScale = cameraData.taaSettings.jitterScale; + + jitter = CalculateJitter(taaFrameIndex) * jitterScale; + + float offsetX = jitter.x * (2.0f / actualWidth); + float offsetY = jitter.y * (2.0f / actualHeight); + + jitterMat = Matrix4x4.Translate(new Vector3(offsetX, offsetY, 0.0f)); + } + + return jitterMat; + } + + static internal Vector2 CalculateJitter(int frameIndex) + { + // The variance between 0 and the actual halton sequence values reveals noticeable + // instability in Unity's shadow maps, so we avoid index 0. + float jitterX = HaltonSequence.Get((frameIndex & 1023) + 1, 2) - 0.5f; + float jitterY = HaltonSequence.Get((frameIndex & 1023) + 1, 3) - 0.5f; + + return new Vector2(jitterX, jitterY); + } + + public void DoSR(CommandBuffer cmd, RTHandle source, RTHandle destination, RTHandle motionVector, ref RenderingData renderingData) { + using var scp = new ProfilingScope(cmd, profiler); Xess1ExecParam* xessexecPtr = (Xess1ExecParam*) xess1ExecParamPtr.ToPointer(); xessexecPtr->ResetHistory = false; if (needTurnOnXess) @@ -111,6 +152,7 @@ namespace X.Rendering.Feature xesscfgPtr->UseJitteredMotionVectors = xess1ConfigParam.UseJitteredMotionVectors; xesscfgPtr->UseMotionVectorsInNDC = xess1ConfigParam.UseMotionVectorsInNDC; xesscfgPtr->UseResponsiveMask = xess1ConfigParam.UseResponsiveMask; + xesscfgPtr->InvertedDepth = xess1ConfigParam.InvertedDepth; xesscfgPtr->VelocityScaleX = xess1ConfigParam.VelocityScaleX; xesscfgPtr->VelocityScaleY = xess1ConfigParam.VelocityScaleY; xesscfgPtr->UseExposureTexture = xess1ConfigParam.UseExposureTexture; @@ -119,14 +161,24 @@ namespace X.Rendering.Feature cmd.IssuePluginEventAndData(RenderingPlugin.GetRenderEventAndDataFunc(), (int)RenderingPlugin.NativeRenderingEvent.UpdateXESS1Config, xess1ConfigParamPtr); xessexecPtr->ResetHistory = true; } + + var cameraData = renderingData.cameraData; + var camera = cameraData.camera; + Matrix4x4 projectionMatrix = camera.projectionMatrix; + Matrix4x4 jitterMat = CalculateJitterMatrix(ref cameraData, out Vector2 jitter); + cameraData.SetViewProjectionAndJitterMatrix(camera.worldToCameraMatrix, projectionMatrix, jitterMat); + cameraData.worldSpaceCameraPos = camera.transform.position; + + cmd.SetGlobalVector(ShaderPropertyId.globalMipBias, new Vector2(xess1ConfigParam.MipMapBias, Mathf.Pow(2.0f, xess1ConfigParam.MipMapBias))); xessexecPtr->InputWidth = source.referenceSize.x; xessexecPtr->InputHeight = source.referenceSize.y; xessexecPtr->ExposureScale = 1.0f; xessexecPtr->ColorTexture = source.rt.GetNativeTexturePtr(); xessexecPtr->VelocityTexture = motionVector.rt.GetNativeTexturePtr(); xessexecPtr->OutputTexture = destination.rt.GetNativeTexturePtr(); - xessexecPtr->Jitterx = 0; - xessexecPtr->Jittery = 0; + xessexecPtr->DepthTexture = renderingData.cameraData.renderer.cameraDepthTargetHandle.rt.GetNativeTexturePtr(); + xessexecPtr->Jitterx = -jitter.x; + xessexecPtr->Jittery = jitter.y; cmd.IssuePluginEventAndData(RenderingPlugin.GetRenderEventAndDataFunc(), (int)RenderingPlugin.NativeRenderingEvent.DoXESS1, xess1ExecParamPtr); if (needTurnOffXess) diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/TemporalAA.cs b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/TemporalAA.cs index de92686..5dcc574 100644 --- a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/TemporalAA.cs +++ b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/TemporalAA.cs @@ -297,12 +297,12 @@ namespace UnityEngine.Rendering.Universal return s; } } - - static internal Matrix4x4 CalculateJitterMatrix(ref CameraData cameraData) + static internal Matrix4x4 CalculateJitterMatrix(ref CameraData cameraData, out Vector2 jitter) { Matrix4x4 jitterMat = Matrix4x4.identity; bool isJitter = cameraData.IsTemporalAAEnabled(); + jitter = Vector2.zero; if (isJitter) { int taaFrameCountOffset = cameraData.taaSettings.jitterFrameCountOffset; @@ -312,7 +312,7 @@ namespace UnityEngine.Rendering.Universal float actualHeight = cameraData.cameraTargetDescriptor.height; float jitterScale = cameraData.taaSettings.jitterScale; - var jitter = CalculateJitter(taaFrameIndex) * jitterScale; + jitter = CalculateJitter(taaFrameIndex) * jitterScale; float offsetX = jitter.x * (2.0f / actualWidth); float offsetY = jitter.y * (2.0f / actualHeight); @@ -323,6 +323,11 @@ namespace UnityEngine.Rendering.Universal return jitterMat; } + static internal Matrix4x4 CalculateJitterMatrix(ref CameraData cameraData) + { + return CalculateJitterMatrix(ref cameraData, out var jitter); + } + static internal Vector2 CalculateJitter(int frameIndex) { // The variance between 0 and the actual halton sequence values reveals noticeable diff --git a/UserSettings/Layouts/default-2022.dwlt b/UserSettings/Layouts/default-2022.dwlt index fb9159a..13c98f1 100644 --- a/UserSettings/Layouts/default-2022.dwlt +++ b/UserSettings/Layouts/default-2022.dwlt @@ -43,7 +43,7 @@ MonoBehaviour: width: 2542 height: 1331 m_ShowMode: 4 - m_Title: Inspector + m_Title: Console m_RootView: {fileID: 13} m_MinSize: {x: 875, y: 321} m_MaxSize: {x: 10000, y: 10000} @@ -97,7 +97,7 @@ MonoBehaviour: m_MinSize: {x: 1000, y: 521} m_MaxSize: {x: 4000, y: 4021} vertical: 0 - controlID: 184 + controlID: 1238 draggingID: 0 --- !u!114 &5 MonoBehaviour: @@ -118,8 +118,8 @@ MonoBehaviour: y: 0 width: 1662 height: 759 - m_MinSize: {x: 202, y: 221} - m_MaxSize: {x: 4002, y: 4021} + m_MinSize: {x: 200, y: 200} + m_MaxSize: {x: 4000, y: 4000} m_ActualView: {fileID: 22} m_Panes: - {fileID: 22} @@ -150,7 +150,7 @@ MonoBehaviour: m_MinSize: {x: 200, y: 50} m_MaxSize: {x: 16192, y: 8096} vertical: 0 - controlID: 40 + controlID: 55 draggingID: 0 --- !u!114 &7 MonoBehaviour: @@ -202,7 +202,7 @@ MonoBehaviour: m_MinSize: {x: 200, y: 50} m_MaxSize: {x: 16192, y: 8096} vertical: 0 - controlID: 128 + controlID: 143 draggingID: 0 --- !u!114 &9 MonoBehaviour: @@ -228,7 +228,7 @@ MonoBehaviour: m_MinSize: {x: 300, y: 100} m_MaxSize: {x: 24288, y: 16192} vertical: 0 - controlID: 164 + controlID: 141 draggingID: 0 --- !u!114 &10 MonoBehaviour: @@ -249,8 +249,8 @@ MonoBehaviour: y: 0 width: 441 height: 1281 - m_MinSize: {x: 276, y: 71} - m_MaxSize: {x: 4001, y: 4021} + m_MinSize: {x: 275, y: 50} + m_MaxSize: {x: 4000, y: 4000} m_ActualView: {fileID: 20} m_Panes: - {fileID: 20} @@ -403,7 +403,7 @@ MonoBehaviour: m_MinSize: {x: 200, y: 100} m_MaxSize: {x: 16192, y: 16192} vertical: 1 - controlID: 127 + controlID: 142 draggingID: 0 --- !u!114 &17 MonoBehaviour: @@ -919,8 +919,8 @@ MonoBehaviour: m_Tooltip: m_Pos: serializedVersion: 2 - x: 9 - y: 841 + x: -32000 + y: -31211 width: 1399 height: 501 m_SerializedDataModeController: @@ -959,9 +959,9 @@ MonoBehaviour: m_IsLocked: 0 m_FolderTreeState: scrollPos: {x: 0, y: 0} - m_SelectedIDs: 7cbb0000 - m_LastClickedID: 47996 - m_ExpandedIDs: 000000004cb800004eb8000050b8000052b8000054b8000056b8000058b800005ab800005cb800005eb8000060b8000062b8000064b8000066b8000068b800006ab8000000ca9a3bffffff7f + m_SelectedIDs: 82bb0000 + m_LastClickedID: 48002 + m_ExpandedIDs: 0000000052b8000054b8000056b8000058b800005ab800005cb800005eb8000060b8000062b8000064b8000066b8000068b800006ab800006cb800006eb8000070b8000000ca9a3bffffff7f m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -989,7 +989,7 @@ MonoBehaviour: scrollPos: {x: 0, y: 0} m_SelectedIDs: m_LastClickedID: 0 - m_ExpandedIDs: 000000004cb800004eb8000050b8000052b8000054b8000056b8000058b800005ab800005cb800005eb8000060b8000062b8000064b8000066b8000068b800006ab80000 + m_ExpandedIDs: 0000000052b8000054b8000056b8000058b800005ab800005cb800005eb8000060b8000062b8000064b8000066b8000068b800006ab800006cb800006eb8000070b80000 m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -1065,8 +1065,8 @@ MonoBehaviour: m_Tooltip: m_Pos: serializedVersion: 2 - x: 2110 - y: 82 + x: -29899 + y: -31970 width: 440 height: 1260 m_SerializedDataModeController: @@ -1112,8 +1112,8 @@ MonoBehaviour: m_Tooltip: m_Pos: serializedVersion: 2 - x: 9 - y: 82 + x: -32000 + y: -31970 width: 438 height: 738 m_SerializedDataModeController: @@ -1129,9 +1129,9 @@ MonoBehaviour: m_SceneHierarchy: m_TreeViewState: scrollPos: {x: 0, y: 0} - m_SelectedIDs: 7cbb0000 + m_SelectedIDs: 48030000 m_LastClickedID: 0 - m_ExpandedIDs: 3afaffff + m_ExpandedIDs: 46faffff m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -1175,8 +1175,8 @@ MonoBehaviour: m_Tooltip: m_Pos: serializedVersion: 2 - x: 448 - y: 82 + x: -31561 + y: -31970 width: 1660 height: 738 m_SerializedDataModeController: @@ -1273,8 +1273,8 @@ MonoBehaviour: m_Tooltip: m_Pos: serializedVersion: 2 - x: 1409 - y: 841 + x: -30600 + y: -31211 width: 699 height: 501 m_SerializedDataModeController: