diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/112_Reflection_AlternativeSGNodes.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/112_Reflection_AlternativeSGNodes.png index 42363847d70..f8ccffd35d6 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/112_Reflection_AlternativeSGNodes.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/112_Reflection_AlternativeSGNodes.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3dbd076f38b123f9dd96db53fa3b6a8383570c90e1d43b50a94cfdbcb4d30372 -size 44327 +oid sha256:a1e67a64d5a24a8234e44badfc551f2b250825ef0a344db9b663a6874b613735 +size 38299 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/LinuxEditor/Vulkan/None/4061_CustomPostProcessMotionVectors.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/LinuxEditor/Vulkan/None/4061_CustomPostProcessMotionVectors.png index b4e3c3af98d..5fc411d1d5b 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/LinuxEditor/Vulkan/None/4061_CustomPostProcessMotionVectors.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/LinuxEditor/Vulkan/None/4061_CustomPostProcessMotionVectors.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2b316f30b0fe1f2c2bdcf29779c7c59e8970087c7bab27a309aae8ad0af14010 -size 10556 +oid sha256:8c1a37f1e195f37a1f6ba8470c85d751d9d4906f5954fb951b7beb3057aa73df +size 9088 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/4061_CustomPostProcessMotionVectors.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/4061_CustomPostProcessMotionVectors.png index 1c9dc584218..5fc411d1d5b 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/4061_CustomPostProcessMotionVectors.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/4061_CustomPostProcessMotionVectors.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:55a182d1d88a164d3760b10c4995508e4908bbab46ece6f2aaf98c479b42bd02 -size 10510 +oid sha256:8c1a37f1e195f37a1f6ba8470c85d751d9d4906f5954fb951b7beb3057aa73df +size 9088 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/4061_CustomPostProcessMotionVectors.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/4061_CustomPostProcessMotionVectors.png index 4dcfb27b203..5fc411d1d5b 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/4061_CustomPostProcessMotionVectors.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/4061_CustomPostProcessMotionVectors.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:39e343610b62e18567b358f95077de49d4feee233c8e508bd1c235cebeecde1c -size 9008 +oid sha256:8c1a37f1e195f37a1f6ba8470c85d751d9d4906f5954fb951b7beb3057aa73df +size 9088 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/4061_CustomPostProcessMotionVectors.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/4061_CustomPostProcessMotionVectors.png index b4e3c3af98d..5fc411d1d5b 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/4061_CustomPostProcessMotionVectors.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/4061_CustomPostProcessMotionVectors.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2b316f30b0fe1f2c2bdcf29779c7c59e8970087c7bab27a309aae8ad0af14010 -size 10556 +oid sha256:8c1a37f1e195f37a1f6ba8470c85d751d9d4906f5954fb951b7beb3057aa73df +size 9088 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/4061_CustomPostProcessMotionVectors.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/4061_CustomPostProcessMotionVectors.png index b4e3c3af98d..5fc411d1d5b 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/4061_CustomPostProcessMotionVectors.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/4061_CustomPostProcessMotionVectors.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2b316f30b0fe1f2c2bdcf29779c7c59e8970087c7bab27a309aae8ad0af14010 -size 10556 +oid sha256:8c1a37f1e195f37a1f6ba8470c85d751d9d4906f5954fb951b7beb3057aa73df +size 9088 diff --git a/com.unity.render-pipelines.core/CHANGELOG.md b/com.unity.render-pipelines.core/CHANGELOG.md index fde1380c5b6..f38c664e1b0 100644 --- a/com.unity.render-pipelines.core/CHANGELOG.md +++ b/com.unity.render-pipelines.core/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Fixed XR support in CoreUtils.DrawFullscreen function. +- Fixed an issue causing Render Graph execution errors after a random amount of time. ## [12.1.2] - 2021-10-22 diff --git a/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs b/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs index f76f02a4c7d..4d878cab1fe 100644 --- a/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs +++ b/com.unity.render-pipelines.core/Editor/Debugging/DebugWindow.cs @@ -378,6 +378,8 @@ void OnGUI() if (GUILayout.Button(Styles.resetButtonContent, EditorStyles.toolbarButton)) { DebugManager.instance.Reset(); + DestroyWidgetStates(); + UpdateWidgetStates(); InternalEditorUtility.RepaintAllViews(); } diff --git a/com.unity.render-pipelines.core/Editor/Volume/VolumeEditor.cs b/com.unity.render-pipelines.core/Editor/Volume/VolumeEditor.cs index 834a94b5372..d4badd1f158 100644 --- a/com.unity.render-pipelines.core/Editor/Volume/VolumeEditor.cs +++ b/com.unity.render-pipelines.core/Editor/Volume/VolumeEditor.cs @@ -71,7 +71,7 @@ void RefreshEffectListEditor(VolumeProfile asset) { m_ComponentList.Clear(); - asset.Sanitize(); + asset?.Sanitize(); if (asset != null) m_ComponentList.Init(asset, new SerializedObject(asset)); diff --git a/com.unity.render-pipelines.core/Runtime/Debugging/DebugUpdater.cs b/com.unity.render-pipelines.core/Runtime/Debugging/DebugUpdater.cs index 755f778679f..2e553692d9a 100644 --- a/com.unity.render-pipelines.core/Runtime/Debugging/DebugUpdater.cs +++ b/com.unity.render-pipelines.core/Runtime/Debugging/DebugUpdater.cs @@ -20,11 +20,10 @@ class DebugUpdater : MonoBehaviour [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)] static void RuntimeInit() { - if (!Debug.isDebugBuild) - return; - +#if DEVELOPMENT_BUILD || UNITY_EDITOR if (DebugManager.instance.enableRuntimeUI) EnableRuntime(); +#endif } internal static void SetEnabled(bool enabled) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs index 6577d4b28b1..673e9ea0eb2 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs @@ -48,14 +48,21 @@ public bool IsValid() static public void NewFrame(int executionIndex) { + uint previousValidBit = s_CurrentValidBit; // Scramble frame count to avoid collision when wrapping around. s_CurrentValidBit = (uint)(((executionIndex >> 16) ^ (executionIndex & 0xffff) * 58546883) << 16); // In case the current valid bit is 0, even though perfectly valid, 0 represents an invalid handle, hence we'll // trigger an invalid state incorrectly. To account for this, we actually skip 0 as a viable s_CurrentValidBit and // start from 1 again. - if (s_CurrentValidBit == 0) + // In the same spirit, s_SharedResourceValidBit is reserved for shared textures so we should never use it otherwise + // resources could be considered valid at frame N+1 (because shared) even though they aren't. + if (s_CurrentValidBit == 0 || s_CurrentValidBit == s_SharedResourceValidBit) { - s_CurrentValidBit = 1 << 16; + // We need to make sure we don't pick the same value twice. + uint value = 1; + while (previousValidBit == (value << 16)) + value++; + s_CurrentValidBit = (value << 16); } } } diff --git a/com.unity.render-pipelines.core/Runtime/Utilities/CameraCaptureBridge.cs b/com.unity.render-pipelines.core/Runtime/Utilities/CameraCaptureBridge.cs index 162b9d4b443..45145156d6d 100644 --- a/com.unity.render-pipelines.core/Runtime/Utilities/CameraCaptureBridge.cs +++ b/com.unity.render-pipelines.core/Runtime/Utilities/CameraCaptureBridge.cs @@ -35,7 +35,7 @@ public static bool enabled /// Enumeration of actions public static IEnumerator> GetCaptureActions(Camera camera) { - if (!actionDict.TryGetValue(camera, out var actions)) + if (!actionDict.TryGetValue(camera, out var actions) || actions.Count == 0) return null; return actions.GetEnumerator(); diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 2527e327d4d..409a0fc8885 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -29,6 +29,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed objects belonging to preview scenes being marked as dirty during migration (case 1367204). - Fixed compilation errors from Path Tracing on the PS5 build. - Fixed option to force motion blur off when in XR. +- Fixed taa jitter for after post process materials (case 1380967). +- Fixed dirtiness handling in path tracing, when using multiple cameras at once (case 1376940). +- Fixed flickering / edge aliasing issue when DoF and TAAU or DLSS are enabled (case 1381858). +- Fixed rasterized accumulation motion blur when DoF is enabled (case 1378497). +- Fixed light mode not available after switching a light to area "Disc" or "Tube" (case 1372588). +- Fixed CoC size computation when dynamic resolution is enabled +- Fixed shadow cascade transition not working properly with bias. +- Fixed broken rendering when duplicating a camera while the Rendering Debugger is opened. +- Fixed screen space shadow debug view not showing when no shadows is available. +- Fixed nullref from debug menu in release build (case 1381556). +- Fixed debug window reset. +- Fixed camera bridge action in release build (case 1367866). +- Fixed contact shadow disappearing when shadowmask is used and no non-static object is available. +- Fixed atmospheric scattering being incorrectly enabled when scene lighting is disabled. ## [12.1.2] - 2021-10-22 diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Surface-Type.md b/com.unity.render-pipelines.high-definition/Documentation~/Surface-Type.md index b120a3061bc..ccfcb40c4c0 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Surface-Type.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Surface-Type.md @@ -23,8 +23,8 @@ If you set the **Surface Type** to **Transparent**, HDRP exposes options to set | **Sorting Priority** | Allows you to change the rendering order of overlaid transparent surfaces. For more information and an example of usage, see the [Material sorting documentation](Renderer-And-Material-Priority.md#SortingByMaterial). | | **Receive fog** | Enable the checkbox to allow fog to affect the transparent surface. When disabled, HDRP does not take this Material into account when it calculates the fog in the Scene. | | **Back Then Front Rendering** | Enable the checkbox to make HDRP render this Material in two separate draw calls. HDRP renders the back face in the first draw call and the front face in the second. | -| **Transparent depth prepass** | Enable the checkbox to add polygons from the transparent surface to the depth buffer to improve their sorting. HDRP performs this operation before the lighting pass and this process improves GPU performance. | -| **Transparent depth postpass** | Enable the checkbox to add polygons to the depth buffer that post-processing uses. HDRP performs this operation before the lighting pass. Enabling this feature is useful if you want to use post-processing effects that use depth information, like [motion blur](Post-Processing-Motion-Blur.md) or [depth of field](Post-Processing-Depth-of-Field.md). | +| **Transparent depth prepass** | Enable the checkbox to add polygons from the transparent surface to the depth buffer to improve their sorting. HDRP performs this operation before the transparent lighting pass. | +| **Transparent depth postpass** | Enable the checkbox to add polygons from the transparent surface to the depth buffer so they affect post-processing. HDRP performs this operation after the lighting pass. Enabling this feature is useful when using post-processing effects that use depth information, like [motion blur](Post-Processing-Motion-Blur.md) or [depth of field](Post-Processing-Depth-of-Field.md). | | **Transparent Writes Motion Vectors** | Enable the checkbox to make HDRP write motion vectors for transparent GameObjects that use this Material. This allows HDRP to process effects like motion blur for transparent objects. For more information on motion vectors, see the [motion vectors documentation](Motion-Vectors.md). | | **Depth Write** | Enable the checkbox to make HDRP write depth values for transparent GameObjects that use this Material. | | **Depth Test** | Use the drop-down to select the comparison function to use for the depth test. | diff --git a/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs b/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs index abeac84ec99..a1e5e0e6102 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs @@ -227,7 +227,7 @@ static void DrawGeneralContent(SerializedHDLight serialized, Editor owner, bool EditorGUI.showMixedValue = false; // Draw the mode, for Tube and Disc lights, there is only one choice, so we can disable the enum. - using (new EditorGUI.DisabledScope(serialized.areaLightShape == AreaLightShape.Tube || serialized.areaLightShape == AreaLightShape.Disc)) + using (new EditorGUI.DisabledScope(updatedLightType == HDLightType.Area && (serialized.areaLightShape == AreaLightShape.Tube || serialized.areaLightShape == AreaLightShape.Disc))) serialized.settings.DrawLightmapping(); if (updatedLightType == HDLightType.Area) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl index a4a651e75cd..95ca356e178 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl @@ -257,7 +257,7 @@ void EvaluateAtmosphericScattering(PositionInputs posInput, float3 V, out float3 #ifdef DEBUG_DISPLAY // Don't sample atmospheric scattering when lighting debug more are enabled so fog is not visible - if (_DebugLightingMode >= DEBUGLIGHTINGMODE_DIFFUSE_LIGHTING && _DebugLightingMode <= DEBUGLIGHTINGMODE_EMISSIVE_LIGHTING) + if (_DebugLightingMode == DEBUGLIGHTINGMODE_MATCAP_VIEW || (_DebugLightingMode >= DEBUGLIGHTINGMODE_DIFFUSE_LIGHTING && _DebugLightingMode <= DEBUGLIGHTINGMODE_EMISSIVE_LIGHTING)) return; if (_DebugShadowMapMode == SHADOWMAPDEBUGMODE_SINGLE_SHADOW || _DebugLightingMode == DEBUGLIGHTINGMODE_LUX_METER || _DebugLightingMode == DEBUGLIGHTINGMODE_LUMINANCE_METER) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDGpuLightsBuilder.Jobs.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDGpuLightsBuilder.Jobs.cs index 6161bf7f537..2f24a43267e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDGpuLightsBuilder.Jobs.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDGpuLightsBuilder.Jobs.cs @@ -683,6 +683,12 @@ private void ConvertDirectionalLightToGPUFormat( lightData.flareSize = Mathf.Max(lightRenderData.flareSize * Mathf.Deg2Rad, 5.960464478e-8f); lightData.flareFalloff = lightRenderData.flareFalloff; + + // On some vendors trigonometry has very bad precision, so we precompute what we can on CPU to avoid precision issues (case 1369376). + float radInner = 0.5f * lightData.angularDiameter; + lightData.flareCosInner = Mathf.Cos(radInner); + lightData.flareCosOuter = Mathf.Cos(radInner + lightData.flareSize); + lightData.flareTint = (Vector3)(Vector4)lightRenderData.flareTint; lightData.surfaceTint = (Vector3)(Vector4)lightRenderData.surfaceTint; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDGpuLightsBuilder.LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDGpuLightsBuilder.LightLoop.cs index 9ce11ff3063..1bce684050a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDGpuLightsBuilder.LightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDGpuLightsBuilder.LightLoop.cs @@ -225,7 +225,8 @@ private void GetContactShadowMask(HDAdditionalLightData hdAdditionalLightData, B return; // Evaluate the contact shadow index of this light - contactShadowMask = 1 << m_ContactShadowIndex++; + contactShadowMask = 1 << m_ContactShadowIndex; + m_ContactShadowIndex++; // Update the index for next light that will need to cast contact shadows. // If this light has ray traced contact shadow if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing) && hdAdditionalLightData.rayTraceContactShadow) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightDefinition.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightDefinition.cs index 60ac297011c..03d4c59d05a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightDefinition.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightDefinition.cs @@ -99,12 +99,16 @@ struct DirectionalLightData public float diffuseDimmer; public float specularDimmer; + public float penumbraTint; public float isRayTracedContactShadow; public float distanceFromCamera; // -1 -> no sky interaction public float angularDiameter; // Units: radians + public float flareFalloff; + public float flareCosInner; + public float flareCosOuter; public float __unused__; public Vector3 flareTint; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightDefinition.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightDefinition.cs.hlsl index bbf1e994bc2..f6a26c97c57 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightDefinition.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightDefinition.cs.hlsl @@ -80,6 +80,8 @@ struct DirectionalLightData float distanceFromCamera; float angularDiameter; float flareFalloff; + float flareCosInner; + float flareCosOuter; float __unused__; float3 flareTint; float flareSize; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl index e96e06bb597..05f1a8b3dfd 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl @@ -190,7 +190,7 @@ float4 EvaluateLight_Directional(LightLoopContext lightLoopContext, PositionInpu // Height fog attenuation. { // TODO: should probably unify height attenuation somehow... - float cosZenithAngle = L.y; + float cosZenithAngle = max(L.y, 0.001f); float fragmentHeight = posInput.positionWS.y; float3 oDepth = OpticalDepthHeightFog(_HeightFogBaseExtinction, _HeightFogBaseHeight, _HeightFogExponents, cosZenithAngle, fragmentHeight); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ContactShadows.compute b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ContactShadows.compute index ab84a489b27..4be74166151 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ContactShadows.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ContactShadows.compute @@ -200,9 +200,9 @@ void DeferredContactShadow(uint2 groupThreadId : SV_GroupThreadID, uint2 groupId // Do the contact shadow for the directional light if (featureFlags & LIGHTFEATUREFLAGS_DIRECTIONAL) { - if (_DirectionalShadowIndex >= 0) + for (uint i = 0; i < _DirectionalLightCount; ++i) { - DirectionalLightData light = _DirectionalLightDatas[_DirectionalShadowIndex]; + DirectionalLightData light = _DirectionalLightDatas[i]; if (light.contactShadowMask != 0 && light.isRayTracedContactShadow == 0.0) { @@ -214,6 +214,7 @@ void DeferredContactShadow(uint2 groupThreadId : SV_GroupThreadID, uint2 groupId // we take full bits at one multiplied by contact shadow and filter the bit at the contact shadow index. contactShadowMask |= light.contactShadowMask * occluded; } + } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDRenderPipeline.ScreenSpaceShadows.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDRenderPipeline.ScreenSpaceShadows.cs index e09d01405e7..505658b35af 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDRenderPipeline.ScreenSpaceShadows.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDRenderPipeline.ScreenSpaceShadows.cs @@ -479,8 +479,13 @@ TextureHandle RenderScreenSpaceShadows(RenderGraph renderGraph, HDCamera hdCamer PrepassOutput prepassOutput, TextureHandle depthBuffer, TextureHandle normalBuffer, TextureHandle motionVectorsBuffer, TextureHandle historyValidityBuffer, TextureHandle rayCountTexture) { // If screen space shadows are not supported for this camera, we are done - if (!hdCamera.frameSettings.IsEnabled(FrameSettingsField.ScreenSpaceShadows) || !RequestedScreenSpaceShadows()) + bool validConditions = hdCamera.frameSettings.IsEnabled(FrameSettingsField.ScreenSpaceShadows) && RequestedScreenSpaceShadows(); + if (!validConditions) + { + // We push the debug texture anyway if we are not evaluating any screen space shadows. + PushFullScreenDebugTexture(m_RenderGraph, m_RenderGraph.defaultResources.whiteTextureXR, FullScreenDebugMode.ScreenSpaceShadows); return m_RenderGraph.defaultResources.blackTextureArrayXR; + } using (new RenderGraphProfilingScope(renderGraph, ProfilingSampler.Get(HDProfileId.ScreenSpaceShadows))) { diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl index 99c0a95b059..0e08873fe78 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl @@ -265,6 +265,7 @@ float EvalShadow_CascadedDepth_Blend_SplitIndex(HDShadowContext shadowContext, T positionWS = basePositionWS + sd.cacheTranslationDelta.xyz; /* normal based bias */ + float worldTexelSize = sd.worldTexelSize; float3 orig_pos = positionWS; float3 normalBias = EvalShadow_NormalBias(sd.worldTexelSize, sd.normalBias, normalWS); positionWS += normalBias; @@ -283,6 +284,11 @@ float EvalShadow_CascadedDepth_Blend_SplitIndex(HDShadowContext shadowContext, T if (alpha > 0.0) { LoadDirectionalShadowDatas(sd, shadowContext, index + shadowSplitIndex); + + // We need to modify the bias as the world texel size changes between splits and an update is needed. + float biasModifier = (sd.worldTexelSize / worldTexelSize); + normalBias *= biasModifier; + float3 evaluationPosWS = basePositionWS + sd.cacheTranslationDelta.xyz + normalBias; float3 posNDC; posTC = EvalShadow_GetTexcoordsAtlas(sd, _CascadeShadowAtlasSize.zw, evaluationPosWS, posNDC, false); diff --git a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/DepthOfFieldCoCReproject.compute b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/DepthOfFieldCoCReproject.compute index aff57a44bb2..710c30e1ad5 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/DepthOfFieldCoCReproject.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/DepthOfFieldCoCReproject.compute @@ -54,10 +54,11 @@ void KMain(uint3 dispatchThreadId : SV_DispatchThreadID) float coc3 = cocBR.x; float coc4 = cocBR.z; #else - float coc1 = LOAD_TEXTURE2D_X(_InputCoCTexture, posInputs.positionSS - uint2(1u, 0u)).x; // Left - float coc2 = LOAD_TEXTURE2D_X(_InputCoCTexture, posInputs.positionSS - uint2(0u, 1u)).x; // Top - float coc3 = LOAD_TEXTURE2D_X(_InputCoCTexture, posInputs.positionSS + uint2(0u, 1u)).x; // Bottom - float coc4 = LOAD_TEXTURE2D_X(_InputCoCTexture, posInputs.positionSS + uint2(1u, 0u)).x; // Right + float2 coord = ClampAndScaleUVPostProcessTextureForPoint(posInputs.positionSS); + float coc1 = LOAD_TEXTURE2D_X(_InputCoCTexture, coord - uint2(1u, 0u)).x; // Left + float coc2 = LOAD_TEXTURE2D_X(_InputCoCTexture, coord - uint2(0u, 1u)).x; // Top + float coc3 = LOAD_TEXTURE2D_X(_InputCoCTexture, coord + uint2(0u, 1u)).x; // Bottom + float coc4 = LOAD_TEXTURE2D_X(_InputCoCTexture, coord + uint2(1u, 0u)).x; // Right #endif // Dejittered center sample diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs index 5636d8a3862..8078b9d6d81 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs @@ -22,6 +22,7 @@ public void ResetIteration() public uint height; public bool skyEnabled; public bool fogEnabled; + public ulong accelSize; public float accumulatedWeight; public uint currentIteration; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDAdditionalCameraData.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDAdditionalCameraData.cs index 6f9cd2595b6..81b0c6f77bc 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDAdditionalCameraData.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDAdditionalCameraData.cs @@ -690,6 +690,11 @@ void OnEnable() m_Camera.allowMSAA = false; // We don't use this option in HD (it is legacy MSAA) and it produce a warning in the inspector UI if we let it m_Camera.allowHDR = false; + // By doing that, we force the update of frame settings debug data once. Otherwise, when the Rendering Debugger is opened, + // Wrong data is registered to the undo system because it did not get the chance to be updated once. + FrameSettings dummy = new FrameSettings(); + FrameSettingsHistory.AggregateFrameSettings(ref dummy, m_Camera, this, HDRenderPipeline.currentAsset, null); + RegisterDebug(); #if UNITY_EDITOR diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs index df314f50030..8d457f66ccb 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs @@ -1383,6 +1383,8 @@ public ScreenSpaceReflectionAlgorithm MaterialPropertyBlock m_RecorderPropertyBlock = new MaterialPropertyBlock(); Rect? m_OverridePixelRect = null; + internal bool hasCaptureActions => m_RecorderCaptureActions != null; + // Keep track of the previous DLSS state private DynamicResolutionHandler.UpsamplerScheduleType m_PrevUpsamplerSchedule = DynamicResolutionHandler.UpsamplerScheduleType.AfterPost; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs index 40b9ca2c8ac..a4c17549cbc 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs @@ -510,6 +510,11 @@ TextureHandle RenderPostProcess(RenderGraph renderGraph, source = DepthOfFieldPass(renderGraph, hdCamera, depthBuffer, motionVectors, depthBufferMipChain, source, depthMinMaxAvgMSAA, prepassOutput.stencilBuffer); + if (m_DepthOfField.IsActive() && m_SubFrameManager.isRecording && m_SubFrameManager.subFrameCount > 1) + { + RenderAccumulation(m_RenderGraph, hdCamera, source, source, false); + } + // Motion blur after depth of field for aesthetic reasons (better to see motion // blurred bokeh rather than out of focus motion blur) source = MotionBlurPass(renderGraph, hdCamera, depthBuffer, motionVectors, source); @@ -636,6 +641,13 @@ TextureHandle RenderAfterPostProcessObjects(RenderGraph renderGraph, HDCamera hd builder.SetRenderFunc( (AfterPostProcessPassData data, RenderGraphContext ctx) => { + // Disable camera jitter. See coment in RestoreNonjitteredMatrices + if (data.hdCamera.RequiresCameraJitter()) + { + data.hdCamera.UpdateAllViewConstants(false); + data.hdCamera.UpdateShaderVariablesGlobalCB(ref data.globalCB); + } + UpdateOffscreenRenderingConstants(ref data.globalCB, true, 1.0f); ConstantBuffer.PushGlobal(ctx.cmd, data.globalCB, HDShaderIDs._ShaderVariablesGlobal); @@ -643,6 +655,13 @@ TextureHandle RenderAfterPostProcessObjects(RenderGraph renderGraph, HDCamera hd // Setup off-screen transparency here DrawTransparentRendererList(ctx.renderContext, ctx.cmd, data.hdCamera.frameSettings, data.transparentAfterPostprocessRL); + // Reenable camera jitter for CustomPostProcessBeforeTAA injection point + if (data.hdCamera.RequiresCameraJitter()) + { + data.hdCamera.UpdateAllViewConstants(true); + data.hdCamera.UpdateShaderVariablesGlobalCB(ref data.globalCB); + } + UpdateOffscreenRenderingConstants(ref data.globalCB, false, 1.0f); ConstantBuffer.PushGlobal(ctx.cmd, data.globalCB, HDShaderIDs._ShaderVariablesGlobal); }); @@ -2744,9 +2763,9 @@ static void DoPhysicallyBasedDepthOfField(in DepthOfFieldParameters dofParameter // The sensor scale is used to convert the CoC size from mm to screen pixels float sensorScale; if (dofParameters.camera.camera.gateFit == Camera.GateFitMode.Horizontal) - sensorScale = (0.5f / dofParameters.camera.camera.sensorSize.x) * dofParameters.camera.camera.pixelWidth; + sensorScale = (0.5f / dofParameters.camera.camera.sensorSize.x) * dofParameters.camera.actualWidth; else - sensorScale = (0.5f / dofParameters.camera.camera.sensorSize.y) * dofParameters.camera.camera.pixelHeight; + sensorScale = (0.5f / dofParameters.camera.camera.sensorSize.y) * dofParameters.camera.actualHeight; // "A Lens and Aperture Camera Model for Synthetic Image Generation" [Potmesil81] // Note: Focus distance is in meters, but focalLength and sensor size are in mm. @@ -2912,9 +2931,13 @@ TextureHandle DepthOfFieldPass(RenderGraph renderGraph, HDCamera hdCamera, Textu { bool postDoFTAAEnabled = false; bool isSceneView = hdCamera.camera.cameraType == CameraType.SceneView; - bool taaEnabled = m_AntialiasingFS && hdCamera.antialiasing == HDAdditionalCameraData.AntialiasingMode.TemporalAntialiasing; + bool stabilizeCoC = m_AntialiasingFS && hdCamera.antialiasing == HDAdditionalCameraData.AntialiasingMode.TemporalAntialiasing; bool isOrtho = hdCamera.camera.orthographic; + // If DLSS is enabled, we need to stabilize the CoC buffer (because the upsampled depth is jittered) + if (m_DLSSPassEnabled) + stabilizeCoC = true; + // If Path tracing is enabled, then DoF is computed in the path tracer by sampling the lens aperure (when using the physical camera mode) bool isDoFPathTraced = (hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing) && hdCamera.volumeStack.GetComponent().enable.value && @@ -2927,7 +2950,7 @@ TextureHandle DepthOfFieldPass(RenderGraph renderGraph, HDCamera hdCamera, Textu { // If we switch DoF modes and the old one was not using TAA, make sure we invalidate the history // Note: for Rendergraph the m_IsDoFHisotoryValid perhaps should be moved to the "pass data" struct - if (taaEnabled && hdCamera.dofHistoryIsValid != m_DepthOfField.physicallyBased) + if (stabilizeCoC && hdCamera.dofHistoryIsValid != m_DepthOfField.physicallyBased) { hdCamera.resetPostProcessingHistory = true; } @@ -2956,7 +2979,7 @@ TextureHandle DepthOfFieldPass(RenderGraph renderGraph, HDCamera hdCamera, Textu TextureHandle dest = GetPostprocessOutputHandle(renderGraph, "DoF Destination"); passData.destination = builder.WriteTexture(dest); passData.motionVecTexture = builder.ReadTexture(motionVectors); - passData.taaEnabled = taaEnabled; + passData.taaEnabled = stabilizeCoC; if (!m_DepthOfField.physicallyBased) { @@ -3107,7 +3130,7 @@ TextureHandle DepthOfFieldPass(RenderGraph renderGraph, HDCamera hdCamera, Textu } // When physically based DoF is enabled, TAA runs two times, first to stabilize the color buffer before DoF and then after DoF to accumulate more aperture samples - if (taaEnabled && m_DepthOfField.physicallyBased) + if (stabilizeCoC && m_DepthOfField.physicallyBased) { source = DoTemporalAntialiasing(renderGraph, hdCamera, depthBuffer, motionVectors, depthBufferMipChain, source, stencilTexture, postDoF: true, "Post-DoF TAA Destination"); hdCamera.dofHistoryIsValid = true; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs index d566cbbf556..8a4d78c124b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs @@ -238,7 +238,8 @@ void RecordRenderGraph(RenderRequest renderRequest, PushFullScreenDebugTexture(m_RenderGraph, colorBuffer, FullScreenDebugMode.WorldSpacePosition, fullScreenDebugFormat); PushFullScreenLightingDebugTexture(m_RenderGraph, colorBuffer, fullScreenDebugFormat); - if (m_SubFrameManager.isRecording && m_SubFrameManager.subFrameCount > 1) + bool accumulateInPost = m_PostProcessEnabled && m_DepthOfField.IsActive(); + if (!accumulateInPost && m_SubFrameManager.isRecording && m_SubFrameManager.subFrameCount > 1) { RenderAccumulation(m_RenderGraph, hdCamera, colorBuffer, colorBuffer, false); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs index 6e91d9ee60d..7f464cbf1c2 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs @@ -584,7 +584,6 @@ static class HDShaderIDs public static readonly int _SpaceEmissionMultiplier = Shader.PropertyToID("_SpaceEmissionMultiplier"); public static readonly int _RenderSunDisk = Shader.PropertyToID("_RenderSunDisk"); - public static readonly int _SunDiskCosines = Shader.PropertyToID("_SunDiskCosines"); public static readonly int _ColorSaturation = Shader.PropertyToID("_ColorSaturation"); public static readonly int _AlphaSaturation = Shader.PropertyToID("_AlphaSaturation"); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs index fc660c86a47..ccc13e3240e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs @@ -73,7 +73,6 @@ public partial class HDRenderPipeline #if UNITY_EDITOR uint m_CacheMaxIteration = 0; #endif // UNITY_EDITOR - ulong m_CacheAccelSize = 0; uint m_CacheLightCount = 0; int m_CameraID = 0; bool m_RenderSky = true; @@ -186,7 +185,7 @@ private void OnSceneGui(SceneView sv) private CameraData CheckDirtiness(HDCamera hdCamera, int camID, CameraData camData) { - // Check camera resolution dirtiness + // Check resolution dirtiness if (hdCamera.actualWidth != camData.width || hdCamera.actualHeight != camData.height) { camData.width = (uint)hdCamera.actualWidth; @@ -194,7 +193,7 @@ private CameraData CheckDirtiness(HDCamera hdCamera, int camID, CameraData camDa return ResetPathTracing(camID, camData); } - // Check camera sky dirtiness + // Check sky dirtiness bool enabled = (hdCamera.clearColorMode == HDAdditionalCameraData.ClearColorMode.Sky); if (enabled != camData.skyEnabled) { @@ -202,7 +201,7 @@ private CameraData CheckDirtiness(HDCamera hdCamera, int camID, CameraData camDa return ResetPathTracing(camID, camData); } - // Check camera fog dirtiness + // Check fog dirtiness enabled = Fog.IsFogEnabled(hdCamera); if (enabled != camData.fogEnabled) { @@ -210,9 +209,11 @@ private CameraData CheckDirtiness(HDCamera hdCamera, int camID, CameraData camDa return ResetPathTracing(camID, camData); } - // Check camera matrix dirtiness - if (hdCamera.mainViewConstants.nonJitteredViewProjMatrix != (hdCamera.mainViewConstants.prevViewProjMatrix)) + // Check acceleration structure dirtiness + ulong accelSize = m_CurrentRAS.GetSize(); + if (accelSize != camData.accelSize) { + camData.accelSize = accelSize; return ResetPathTracing(camID, camData); } @@ -240,15 +241,13 @@ private CameraData CheckDirtiness(HDCamera hdCamera, int camID, CameraData camDa return camData; } - // Check geometry dirtiness - ulong accelSize = m_CurrentRAS.GetSize(); - if (accelSize != m_CacheAccelSize) + // Check camera matrix dirtiness + if (hdCamera.mainViewConstants.nonJitteredViewProjMatrix != (hdCamera.mainViewConstants.prevViewProjMatrix)) { - m_CacheAccelSize = accelSize; - ResetPathTracing(); + return ResetPathTracing(camID, camData); } - // If the camera has changed, re-render the sky texture + // If nothing but the camera has changed, re-render the sky texture if (camID != m_CameraID) { m_RenderSky = true; @@ -414,7 +413,10 @@ TextureHandle RenderPathTracing(RenderGraph renderGraph, HDCamera hdCamera, Text #if UNITY_HDRP_DXR_TESTS_DEFINE if (Application.isPlaying) + { + camData.ResetIteration(); m_SubFrameManager.subFrameCount = 1; + } #endif if (camData.currentIteration < m_SubFrameManager.subFrameCount) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Shadows/RayTracingContactShadow.raytrace b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Shadows/RayTracingContactShadow.raytrace index ac35c50d795..c1bac5a59ad 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Shadows/RayTracingContactShadow.raytrace +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Shadows/RayTracingContactShadow.raytrace @@ -94,10 +94,9 @@ void RayGenContactShadows() uint contactShadowMask = 0; UnpackContactShadowData(_ContactShadowTextureUAV[COORD_TEXTURE2D_X(pixelCoord)], fade, contactShadowMask); - // Let's first process the directional shadow - if (_DirectionalShadowIndex >= 0) + for (int i = 0; i < _DirectionalLightCount; ++i) { - DirectionalLightData light = _DirectionalLightDatas[_DirectionalShadowIndex]; + DirectionalLightData light = _DirectionalLightDatas[i]; if (light.contactShadowMask != 0 && light.isRayTracedContactShadow == 1.0) { diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs index 9f46f0dfd17..97045abbfda 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs @@ -905,7 +905,7 @@ internal static bool PostProcessIsFinalPass(HDCamera hdCamera) // Post process pass is the final blit only when not in developer mode. // In developer mode, we support a range of debug rendering that needs to occur after post processes. // In order to simplify writing them, we don't Y-flip in the post process pass but add a final blit at the end of the frame. - return !Debug.isDebugBuild && !WillCustomPassBeExecuted(hdCamera, CustomPassInjectionPoint.AfterPostProcess); + return !Debug.isDebugBuild && !WillCustomPassBeExecuted(hdCamera, CustomPassInjectionPoint.AfterPostProcess) && !hdCamera.hasCaptureActions; } // These two convertion functions are used to store GUID assets inside materials, diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader index 4dfea227c0e..98e859f9ff6 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader @@ -4,6 +4,7 @@ Shader "Hidden/HDRP/Sky/PbrSky" #pragma vertex Vert + // #pragma enable_d3d11_debug_symbols #pragma editor_sync_compilation #pragma target 4.5 #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch @@ -25,13 +26,6 @@ Shader "Hidden/HDRP/Sky/PbrSky" float _GroundEmissionMultiplier; float _SpaceEmissionMultiplier; - // Inner and outer cosine computed as: - // float radInner = 0.5 * light.angularDiameter - // float cosInner = cos(radInner); // (In _SunDiskCosines.x) - // float cosOuter = cos(radInner + light.flareSize); // (In _SunDiskCosines.y) - // We need to pass it over instead of computing it here because on some vendors trigonometry has very bad precision, so we precompute what we can on CPU to have better precision. - float4 _SunDiskCosines; - // Sky framework does not set up global shader variables (even per-view ones), // so they can contain garbage. It's very difficult to not include them, however, // since the sky framework includes them internally in many header files. @@ -118,19 +112,16 @@ Shader "Hidden/HDRP/Sky/PbrSky" float rad = acos(LdotV); float radInner = 0.5 * light.angularDiameter; - float cosInner = _SunDiskCosines.x; - float cosOuter = _SunDiskCosines.y; - - float solidAngle = TWO_PI * (1 - cosInner); + float solidAngle = TWO_PI * (1 - light.flareCosInner); - if (LdotV >= cosOuter) + if (LdotV >= light.flareCosOuter) { // Sun flare is visible. Sun disk may or may not be visible. // Assume uniform emission. float3 color = light.color.rgb; float scale = rcp(solidAngle); - if (LdotV >= cosInner) // Sun disk. + if (LdotV >= light.flareCosInner) // Sun disk. { tFrag = lightDist; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSkyRenderer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSkyRenderer.cs index 54898c0321b..19ebc2d518d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSkyRenderer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSkyRenderer.cs @@ -500,14 +500,6 @@ public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderFo } s_PbrSkyMaterialProperties.SetInt(HDShaderIDs._HasSpaceEmissionTexture, hasSpaceEmissionTexture); - // We need to pass it over instead of computing it here because on some vendors trigonometry has very bad precision, so we precompute what we can on CPU to have better precision. - // We can safely retrieve HDAdditionalLightData as for PBR sky the sunlight is always going to be an HDRP light. - var lightData = builtinParams.sunLight.gameObject.GetComponent(); - float radInner = 0.5f * lightData.angularDiameter * Mathf.Deg2Rad; - float cosInner = Mathf.Cos(radInner); - float cosOuter = Mathf.Cos(radInner + lightData.flareSize); - s_PbrSkyMaterialProperties.SetVector(HDShaderIDs._SunDiskCosines, new Vector4(cosInner, cosOuter, 0, 0)); - s_PbrSkyMaterialProperties.SetInt(HDShaderIDs._RenderSunDisk, renderSunDisk ? 1 : 0); int pass = (renderForCubemap ? 0 : 2); diff --git a/com.unity.shadergraph/CHANGELOG.md b/com.unity.shadergraph/CHANGELOG.md index 215111469f6..1de1e346f3b 100644 --- a/com.unity.shadergraph/CHANGELOG.md +++ b/com.unity.shadergraph/CHANGELOG.md @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Fixed a ShaderGraph warning when connecting a node using Object Space BiTangent to the vertex stage [1361512] (https://issuetracker.unity3d.com/issues/shader-graph-cross-implicit-truncation-of-vector-type-errors-are-thrown-when-connecting-transform-node-to-vertex-block) - + ## [12.1.1] - 2021-10-04 ### Fixed diff --git a/com.unity.template-hd/Assets/Scenes/SampleScene.unity b/com.unity.template-hd/Assets/Scenes/SampleScene.unity index ad5967f4c88..62b51083a5e 100644 --- a/com.unity.template-hd/Assets/Scenes/SampleScene.unity +++ b/com.unity.template-hd/Assets/Scenes/SampleScene.unity @@ -29268,9 +29268,9 @@ MonoBehaviour: m_UseScreenSpaceShadows: 0 m_InteractsWithSky: 1 m_AngularDiameter: 0.53 - m_FlareSize: 0 - m_FlareTint: {r: 0, g: 0, b: 0, a: 1} - m_FlareFalloff: 0 + m_FlareSize: 2 + m_FlareTint: {r: 1, g: 1, b: 1, a: 1} + m_FlareFalloff: 4 m_SurfaceTexture: {fileID: 0} m_SurfaceTint: {r: 1, g: 1, b: 1, a: 1} m_Distance: 150000000