diff --git a/com.unity.render-pipelines.high-definition/Editor/Lighting/Reflection/HDBakedReflectionSystem.cs b/com.unity.render-pipelines.high-definition/Editor/Lighting/Reflection/HDBakedReflectionSystem.cs index a07b3fd9edd..a90c253eb0c 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Lighting/Reflection/HDBakedReflectionSystem.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Lighting/Reflection/HDBakedReflectionSystem.cs @@ -440,7 +440,7 @@ public static bool BakeProbes(IEnumerable bakedProbes) // to update the texture. // updateCount is a transient data, so don't execute this code before the asset reload. { - UnityEngine.Random.InitState((int)(1000 * hdPipeline.GetTime())); + UnityEngine.Random.InitState((int)(1000 * EditorApplication.timeSinceStartup)); foreach (var probe in bakedProbes) { var c = UnityEngine.Random.Range(2, 10); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/HDProbe.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/HDProbe.cs index 186f0d007f3..539f8eafbde 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/HDProbe.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/HDProbe.cs @@ -196,7 +196,6 @@ internal bool HasValidRenderedData() } else { - bool hasEverRendered = lastRenderedFrame != int.MinValue; return hasEverRendered && hasValidTexture; } } @@ -520,16 +519,16 @@ internal Matrix4x4 proxyToWorld : influenceToWorld; internal bool wasRenderedAfterOnEnable { get; private set; } = false; - internal int lastRenderedFrame { get; private set; } = int.MinValue; + internal bool hasEverRendered { get; private set; } = false; - internal void SetIsRendered(int frame) + internal void SetIsRendered() { #if UNITY_EDITOR m_WasRenderedDuringAsyncCompilation = ShaderUtil.anythingCompiling; #endif m_WasRenderedSinceLastOnDemandRequest = true; wasRenderedAfterOnEnable = true; - lastRenderedFrame = frame; + hasEverRendered = true; } // API diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.RenderGraph.cs index 0aa99566a7b..c9e2a503812 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.RenderGraph.cs @@ -10,7 +10,7 @@ TextureHandle CreateAmbientOcclusionTexture(RenderGraph renderGraph) return renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) { enableRandomWrite = true, colorFormat = GraphicsFormat.R8_UNorm, name = "Ambient Occlusion" }); } - public TextureHandle Render(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthPyramid, TextureHandle normalBuffer, TextureHandle motionVectors, int frameCount, in HDUtils.PackedMipChainInfo depthMipInfo, ShaderVariablesRaytracing shaderVariablesRaytracing, TextureHandle rayCountTexture) + public TextureHandle Render(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthPyramid, TextureHandle normalBuffer, TextureHandle motionVectors, in HDUtils.PackedMipChainInfo depthMipInfo, ShaderVariablesRaytracing shaderVariablesRaytracing, TextureHandle rayCountTexture) { var settings = hdCamera.volumeStack.GetComponent(); @@ -31,7 +31,7 @@ public TextureHandle Render(RenderGraph renderGraph, HDCamera hdCamera, TextureH hdCamera.AllocateAmbientOcclusionHistoryBuffer(scaleFactor); if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing) && settings.rayTracing.value) - return m_RaytracingAmbientOcclusion.RenderRTAO(renderGraph, hdCamera, depthPyramid, normalBuffer, motionVectors, rayCountTexture, frameCount, shaderVariablesRaytracing); + return m_RaytracingAmbientOcclusion.RenderRTAO(renderGraph, hdCamera, depthPyramid, normalBuffer, motionVectors, rayCountTexture, shaderVariablesRaytracing); else { var historyRT = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.AmbientOcclusion); @@ -42,7 +42,7 @@ public TextureHandle Render(RenderGraph renderGraph, HDCamera hdCamera, TextureH historyRT.referenceSize.y * historyRT.scaleFactor.y); var rtScaleForHistory = hdCamera.historyRTHandleProperties.rtHandleScale; - var aoParameters = PrepareRenderAOParameters(hdCamera, historySize * rtScaleForHistory, frameCount, depthMipInfo); + var aoParameters = PrepareRenderAOParameters(hdCamera, historySize * rtScaleForHistory, depthMipInfo); var packedData = RenderAO(renderGraph, aoParameters, depthPyramid, normalBuffer); result = DenoiseAO(renderGraph, aoParameters, depthPyramid, motionVectors, packedData, currentHistory, outputHistory); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.cs index f0f143f1adb..af3599f6701 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.cs @@ -281,7 +281,7 @@ struct RenderAOParameters public ShaderVariablesAmbientOcclusion cb; } - RenderAOParameters PrepareRenderAOParameters(HDCamera camera, Vector2 historySize, int frameCount, in HDUtils.PackedMipChainInfo depthMipInfo) + RenderAOParameters PrepareRenderAOParameters(HDCamera camera, Vector2 historySize, in HDUtils.PackedMipChainInfo depthMipInfo) { var parameters = new RenderAOParameters(); @@ -304,6 +304,7 @@ RenderAOParameters PrepareRenderAOParameters(HDCamera camera, Vector2 historySiz float invHalfTanFOV = -camera.mainViewConstants.projMatrix[1, 1]; float aspectRatio = parameters.runningRes.y / parameters.runningRes.x; + uint frameCount = camera.GetCameraFrameCount(); cb._AOParams0 = new Vector4( parameters.fullResolution ? 0.0f : 1.0f, diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/DensityVolume.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/DensityVolume.cs index b5583e8df44..95a6bc3d808 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/DensityVolume.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/DensityVolume.cs @@ -89,13 +89,12 @@ public DensityVolumeArtistParameters(Color color, float _meanFreePath, float _an m_EditorAdvancedFade = false; } - internal void Update(bool animate, float time) + internal void Update(float time) { //Update scrolling based on deltaTime if (volumeMask != null) { - float animationTime = animate ? time : 0.0f; - textureOffset = (textureScrollingSpeed * animationTime); + textureOffset = (textureScrollingSpeed * time); // Switch from right-handed to left-handed coordinate system. textureOffset.x = -textureOffset.x; textureOffset.y = -textureOffset.y; @@ -180,7 +179,7 @@ public partial class DensityVolume : MonoBehaviour /// Gather and Update any parameters that may have changed. - internal void PrepareParameters(bool animate, float time) + internal void PrepareParameters(float time) { //Texture has been updated notify the manager bool updated = previousVolumeMask != parameters.volumeMask; @@ -201,7 +200,7 @@ internal void PrepareParameters(bool animate, float time) #endif } - parameters.Update(animate, time); + parameters.Update(time); } private void NotifyUpdatedTexure() diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/DensityVolumeManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/DensityVolumeManager.cs index 8927159c156..8ad381cb913 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/DensityVolumeManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/DensityVolumeManager.cs @@ -105,12 +105,12 @@ public void DeRegisterVolume(DensityVolume volume) public bool ContainsVolume(DensityVolume volume) => m_Volumes.Contains(volume); - public List PrepareDensityVolumeData(CommandBuffer cmd, HDCamera currentCam, float time) + public List PrepareDensityVolumeData(CommandBuffer cmd, HDCamera currentCam) { //Update volumes - bool animate = currentCam.animateMaterials; + float time = currentCam.time; foreach (DensityVolume volume in m_Volumes) - volume.PrepareParameters(animate, time); + volume.PrepareParameters(time); using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.UpdateDensityVolumeAtlas))) { diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/VolumetricLighting.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/VolumetricLighting.cs index a6f17c2fe62..021f3397ab9 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/VolumetricLighting.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/VolumetricLighting.cs @@ -719,8 +719,8 @@ void UpdateShaderVariablesGlobalVolumetrics(ref ShaderVariablesGlobal cb, HDCame // Get the interpolated anisotropy value. var fog = hdCamera.volumeStack.GetComponent(); - int frameIndex = m_FrameCount; - int currIdx = (frameIndex + 0) & 1; + uint frameIndex = hdCamera.GetCameraFrameCount(); + uint currIdx = (frameIndex + 0) & 1; var currParams = hdCamera.vBufferParams[currIdx]; @@ -744,7 +744,7 @@ void UpdateShaderVariablesGlobalVolumetrics(ref ShaderVariablesGlobal cb, HDCame cb._VBufferRcpInstancedViewCount = 1.0f / hdCamera.viewCount; } - DensityVolumeList PrepareVisibleDensityVolumeList(HDCamera hdCamera, CommandBuffer cmd, float time) + DensityVolumeList PrepareVisibleDensityVolumeList(HDCamera hdCamera, CommandBuffer cmd) { DensityVolumeList densityVolumes = new DensityVolumeList(); @@ -765,7 +765,7 @@ DensityVolumeList PrepareVisibleDensityVolumeList(HDCamera hdCamera, CommandBuff m_VisibleVolumeData.Clear(); // Collect all visible finite volume data, and upload it to the GPU. - var volumes = DensityVolumeManager.manager.PrepareDensityVolumeData(cmd, hdCamera, time); + var volumes = DensityVolumeManager.manager.PrepareDensityVolumeData(cmd, hdCamera); for (int i = 0; i < Math.Min(volumes.Count, k_MaxVisibleDensityVolumeCount); i++) { diff --git a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs index d1a37c0f329..8ef6166406e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs @@ -3421,7 +3421,7 @@ static void DoFinalPass(in FinalPassParameters parameters, #if HDRP_DEBUG_STATIC_POSTFX int textureId = 0; #else - int textureId = Time.frameCount % blueNoiseTexture.depth; + int textureId = (int)hdCamera.GetCameraFrameCount() % blueNoiseTexture.depth; #endif finalPassMaterial.EnableKeyword("DITHER"); 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 34305f761c2..1231d34da2c 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 @@ -246,6 +246,8 @@ internal struct HistoryEffectValidity // XR multipass and instanced views are supported (see XRSystem) internal XRPass xr { get; private set; } + internal float deltaTime => time - lastTime; + // Non oblique projection matrix (RHS) // TODO: this code is never used and not compatible with XR internal Matrix4x4 nonObliqueProjMatrix @@ -453,9 +455,24 @@ internal void Update(FrameSettings currentFrameSettings, HDRenderPipeline hdrp, // Different views/tabs may have different values of the "Animated Materials" setting. animateMaterials = CoreUtils.AreAnimatedMaterialsEnabled(aniCam); - - time = animateMaterials ? hdrp.GetTime() : 0; - lastTime = animateMaterials ? hdrp.GetLastTime() : 0; + if (animateMaterials) + { + float newTime, deltaTime; +#if UNITY_EDITOR + newTime = Application.isPlaying ? Time.time : Time.realtimeSinceStartup; + deltaTime = Application.isPlaying ? Time.deltaTime : 0.033f; +#else + newTime = Time.time; + deltaTime = Time.deltaTime; +#endif + time = newTime; + lastTime = newTime - deltaTime; + } + else + { + time = 0; + lastTime = 0; + } // Make sure that the shadow history identification array is allocated and is at the right size if (shadowHistoryUsage == null || shadowHistoryUsage.Length != hdrp.currentPlatformRenderPipelineSettings.hdShadowInitParams.maxScreenSpaceShadowSlots) @@ -674,6 +691,9 @@ internal static void ResetAllHistoryRTHandleSystems(int width, int height) } } + unsafe internal void UpdateShaderVariablesGlobalCB(ref ShaderVariablesGlobal cb) + => UpdateShaderVariablesGlobalCB(ref cb, (int)cameraFrameCount); + unsafe internal void UpdateShaderVariablesGlobalCB(ref ShaderVariablesGlobal cb, int frameCount) { bool taaEnabled = frameSettings.IsEnabled(FrameSettingsField.Postprocess) @@ -708,8 +728,13 @@ unsafe internal void UpdateShaderVariablesGlobalCB(ref ShaderVariablesGlobal cb, float ct = time; float pt = lastTime; +#if UNITY_EDITOR + float dt = time - lastTime; + float sdt = dt; +#else float dt = Time.deltaTime; float sdt = Time.smoothDeltaTime; +#endif cb._Time = new Vector4(ct * 0.05f, ct, ct * 2.0f, ct * 3.0f); cb._SinTime = new Vector4(Mathf.Sin(ct * 0.125f), Mathf.Sin(ct * 0.25f), Mathf.Sin(ct * 0.5f), Mathf.Sin(ct)); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs index 9d97b449c72..6430d0dc524 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs @@ -227,7 +227,6 @@ BuildGPULightListOutput BuildGPULightList(RenderGraph render class PushGlobalCameraParamPassData { public HDCamera hdCamera; - public int frameCount; public ShaderVariablesGlobal globalCB; public ShaderVariablesXR xrCB; } @@ -237,14 +236,13 @@ void PushGlobalCameraParams(RenderGraph renderGraph, HDCamera hdCamera) using (var builder = renderGraph.AddRenderPass("Push Global Camera Parameters", out var passData)) { passData.hdCamera = hdCamera; - passData.frameCount = m_FrameCount; passData.globalCB = m_ShaderVariablesGlobalCB; passData.xrCB = m_ShaderVariablesXRCB; builder.SetRenderFunc( (PushGlobalCameraParamPassData data, RenderGraphContext context) => { - data.hdCamera.UpdateShaderVariablesGlobalCB(ref data.globalCB, data.frameCount); + data.hdCamera.UpdateShaderVariablesGlobalCB(ref data.globalCB); ConstantBuffer.PushGlobal(context.cmd, data.globalCB, HDShaderIDs._ShaderVariablesGlobal); data.hdCamera.UpdateShaderVariablesXRCB(ref data.xrCB); ConstantBuffer.PushGlobal(context.cmd, data.xrCB, HDShaderIDs._ShaderVariablesXR); @@ -442,7 +440,7 @@ TextureHandle RenderSSR(RenderGraph renderGraph, { result = RenderRayTracedReflections(renderGraph, hdCamera, prepassOutput.depthBuffer, prepassOutput.stencilBuffer, prepassOutput.normalBuffer, prepassOutput.resolvedMotionVectorsBuffer, clearCoatMask, skyTexture, rayCountTexture, - m_FrameCount, m_ShaderVariablesRayTracingCB, transparent); + m_ShaderVariablesRayTracingCB, transparent); } else { 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 9284080bde8..edfea8045e9 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 @@ -30,7 +30,7 @@ void ExecuteWithRenderGraph(RenderRequest renderRequest, { scriptableRenderContext = renderContext, commandBuffer = commandBuffer, - currentFrameIndex = GetFrameCount() + currentFrameIndex = m_FrameCount }; m_RenderGraph.Begin(renderGraphParams); @@ -104,7 +104,7 @@ void ExecuteWithRenderGraph(RenderRequest renderRequest, { gpuLightListOutput = BuildGPULightList(m_RenderGraph, hdCamera, m_TileAndClusterData, m_TotalLightCount, ref m_ShaderVariablesLightListCB, prepassOutput.depthBuffer, prepassOutput.stencilBuffer, prepassOutput.gbuffer); - lightingBuffers.ambientOcclusionBuffer = m_AmbientOcclusionSystem.Render(m_RenderGraph, hdCamera, prepassOutput.depthPyramidTexture, prepassOutput.resolvedNormalBuffer, prepassOutput.resolvedMotionVectorsBuffer, m_FrameCount, m_DepthBufferMipChainInfo, m_ShaderVariablesRayTracingCB, rayCountTexture); + lightingBuffers.ambientOcclusionBuffer = m_AmbientOcclusionSystem.Render(m_RenderGraph, hdCamera, prepassOutput.depthPyramidTexture, prepassOutput.resolvedNormalBuffer, prepassOutput.resolvedMotionVectorsBuffer, m_DepthBufferMipChainInfo, m_ShaderVariablesRayTracingCB, rayCountTexture); // Should probably be inside the AO render function but since it's a separate class it's currently not super clean to do. PushFullScreenDebugTexture(m_RenderGraph, lightingBuffers.ambientOcclusionBuffer, FullScreenDebugMode.ScreenSpaceAmbientOcclusion); @@ -135,7 +135,7 @@ void ExecuteWithRenderGraph(RenderRequest renderRequest, case IndirectDiffuseMode.Raytrace: lightingBuffers.ssgiLightingBuffer = RenderRayTracedIndirectDiffuse(m_RenderGraph, hdCamera, prepassOutput.depthBuffer, prepassOutput.stencilBuffer, prepassOutput.normalBuffer, prepassOutput.resolvedMotionVectorsBuffer, m_SkyManager.GetSkyReflection(hdCamera), rayCountTexture, - m_FrameCount, m_ShaderVariablesRayTracingCB); + m_ShaderVariablesRayTracingCB); break; default: lightingBuffers.ssgiLightingBuffer = m_RenderGraph.defaultResources.blackTextureXR; @@ -1117,7 +1117,6 @@ class PreRenderSkyPassData public TextureHandle normalBuffer; public DebugDisplaySettings debugDisplaySettings; public SkyManager skyManager; - public int frameCount; } void PreRenderSky(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle colorBuffer, TextureHandle depthStencilBuffer, TextureHandle normalbuffer) @@ -1135,12 +1134,11 @@ void PreRenderSky(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle colo passData.normalBuffer = builder.WriteTexture(normalbuffer); passData.debugDisplaySettings = m_CurrentDebugDisplaySettings; passData.skyManager = m_SkyManager; - passData.frameCount = m_FrameCount; builder.SetRenderFunc( (PreRenderSkyPassData data, RenderGraphContext context) => { - data.skyManager.PreRenderSky(data.hdCamera, data.sunLight, data.colorBuffer, data.normalBuffer, data.depthStencilBuffer, data.debugDisplaySettings, data.frameCount, context.cmd); + data.skyManager.PreRenderSky(data.hdCamera, data.sunLight, data.colorBuffer, data.normalBuffer, data.depthStencilBuffer, data.debugDisplaySettings, context.cmd); }); } } @@ -1157,7 +1155,6 @@ class RenderSkyPassData public TextureHandle intermediateBuffer; public DebugDisplaySettings debugDisplaySettings; public SkyManager skyManager; - public int frameCount; } void RenderSky(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle colorBuffer, TextureHandle volumetricLighting, TextureHandle depthStencilBuffer, TextureHandle depthTexture) @@ -1177,7 +1174,6 @@ void RenderSky(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle colorBu passData.intermediateBuffer = builder.CreateTransientTexture(colorBuffer); passData.debugDisplaySettings = m_CurrentDebugDisplaySettings; passData.skyManager = m_SkyManager; - passData.frameCount = m_FrameCount; builder.SetRenderFunc( (RenderSkyPassData data, RenderGraphContext context) => @@ -1185,7 +1181,7 @@ void RenderSky(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle colorBu // Necessary to perform dual-source (polychromatic alpha) blending which is not supported by Unity. // We load from the color buffer, perform blending manually, and store to the atmospheric scattering buffer. // Then we perform a copy from the atmospheric scattering buffer back to the color buffer. - data.skyManager.RenderSky(data.hdCamera, data.sunLight, data.colorBuffer, data.depthStencilBuffer, data.debugDisplaySettings, data.frameCount, context.cmd); + data.skyManager.RenderSky(data.hdCamera, data.sunLight, data.colorBuffer, data.depthStencilBuffer, data.debugDisplaySettings, context.cmd); if (Fog.IsFogEnabled(data.hdCamera) || Fog.IsPBRFogEnabled(data.hdCamera)) { 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 2bd77935229..9a3bd9615e7 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -226,13 +226,8 @@ internal static Volume GetOrCreateDefaultVolume() // Keep track of the maximum number of XR instanced views int m_MaxViewCount = 1; - // Use to detect frame changes + // Use to detect frame changes (for accurate frame count in editor, consider using hdCamera.GetCameraFrameCount) int m_FrameCount; - float m_LastTime, m_Time; // Do NOT take the 'animateMaterials' setting into account. - - internal int GetFrameCount() { return m_FrameCount; } - internal float GetLastTime() { return m_LastTime; } - internal float GetTime() { return m_Time; } GraphicsFormat GetColorBufferFormat() => (GraphicsFormat)m_Asset.currentPlatformRenderPipelineSettings.colorBufferFormat; @@ -994,7 +989,7 @@ void UpdateGlobalConstantBuffers(HDCamera hdCamera, CommandBuffer cmd) void UpdateShaderVariablesGlobalCB(HDCamera hdCamera, CommandBuffer cmd) { - hdCamera.UpdateShaderVariablesGlobalCB(ref m_ShaderVariablesGlobalCB, m_FrameCount); + hdCamera.UpdateShaderVariablesGlobalCB(ref m_ShaderVariablesGlobalCB); Fog.UpdateShaderVariablesGlobalCB(ref m_ShaderVariablesGlobalCB, hdCamera); UpdateShaderVariablesGlobalSubsurface(ref m_ShaderVariablesGlobalCB, hdCamera); UpdateShaderVariablesGlobalDecal(ref m_ShaderVariablesGlobalCB, hdCamera); @@ -1256,24 +1251,29 @@ protected override void Render(ScriptableRenderContext renderContext, Camera[] c BeginContextRendering(renderContext, cameras); #else BeginFrameRendering(renderContext, cameras); - #endif // Check if we can speed up FrameSettings process by skiping history // or go in detail if debug is activated. Done once for all renderer. m_FrameSettingsHistoryEnabled = FrameSettingsHistory.enabled; - int newCount = Time.frameCount; - bool newFrame = newCount != m_FrameCount; - m_FrameCount = newCount; - - if (newFrame) +#if UNITY_EDITOR + int newCount = m_FrameCount; + foreach (var c in cameras) { - m_LastTime = m_Time; // Only update time once per frame. - m_Time = Time.time; // Does NOT take the 'animateMaterials' setting into account. - m_LastTime = Mathf.Min(m_Time, m_LastTime); // Guard against broken Unity behavior. Should not be necessary. - - m_ProbeCameraCache.ClearCamerasUnusedFor(2, m_FrameCount); + if (c.cameraType != CameraType.Preview) + { + newCount++; + break; + } + } +#else + int newCount = Time.frameCount; +#endif + if (newCount != m_FrameCount) + { + m_FrameCount = newCount; + m_ProbeCameraCache.ClearCamerasUnusedFor(2, Time.frameCount); HDCamera.CleanUnused(); } @@ -1475,7 +1475,7 @@ void AddVisibleProbeVisibleIndexIfUpdateIsRequired(HDProbe probe, int visibleInI // (see m_SkyManager.HasSetValidAmbientProbe in this function). // Also, we need to set the probe as rendered only if we'll actually render it and this won't happen if visibility is not > 0. if (m_FrameCount > 1 && visibility > 0.0f) - probe.SetIsRendered(m_FrameCount); + probe.SetIsRendered(); if (!renderRequestIndicesWhereTheProbeIsVisible.TryGetValue(probe, out var visibleInIndices)) { @@ -1630,7 +1630,7 @@ ref List renderDatas for (int j = 0; j < cameraSettings.Count; ++j) { - var camera = m_ProbeCameraCache.GetOrCreate((viewerTransform, visibleProbe, j), m_FrameCount, CameraType.Reflection); + var camera = m_ProbeCameraCache.GetOrCreate((viewerTransform, visibleProbe, j), Time.frameCount, CameraType.Reflection); var additionalCameraData = camera.GetComponent(); if (additionalCameraData == null) @@ -2088,7 +2088,7 @@ AOVRequestData aovRequest material.Bind(cmd); // Frustum cull density volumes on the CPU. Can be performed as soon as the camera is set up. - DensityVolumeList densityVolumes = PrepareVisibleDensityVolumeList(hdCamera, cmd, hdCamera.time); + DensityVolumeList densityVolumes = PrepareVisibleDensityVolumeList(hdCamera, cmd); // do AdaptiveProbeVolume stuff BindAPVRuntimeResources(cmd, hdCamera); @@ -2115,7 +2115,7 @@ AOVRequestData aovRequest // Caution: We require sun light here as some skies use the sun light to render, it means that UpdateSkyEnvironment must be called after PrepareLightsForGPU. // TODO: Try to arrange code so we can trigger this call earlier and use async compute here to run sky convolution during other passes (once we move convolution shader to compute). if (!m_CurrentDebugDisplaySettings.IsMatcapViewEnabled(hdCamera)) - UpdateSkyEnvironment(hdCamera, renderContext, m_FrameCount, cmd); + UpdateSkyEnvironment(hdCamera, renderContext, cmd); else cmd.SetGlobalTexture(HDShaderIDs._SkyTexture, CoreUtils.magentaCubeTextureArray); @@ -3052,9 +3052,9 @@ static void RenderFullScreenDebug(FullScreenDebugParameters parameters, } } - void UpdateSkyEnvironment(HDCamera hdCamera, ScriptableRenderContext renderContext, int frameIndex, CommandBuffer cmd) + void UpdateSkyEnvironment(HDCamera hdCamera, ScriptableRenderContext renderContext, CommandBuffer cmd) { - m_SkyManager.UpdateEnvironment(hdCamera, renderContext, GetCurrentSunLight(), frameIndex, cmd); + m_SkyManager.UpdateEnvironment(hdCamera, renderContext, GetCurrentSunLight(), cmd); } /// @@ -3675,9 +3675,6 @@ struct PostProcessParameters // After Postprocess public bool useDepthBuffer; - public float time; - public float lastTime; - public int frameCount; public RendererListDesc opaqueAfterPPDesc; public RendererListDesc transparentAfterPPDesc; } @@ -3694,9 +3691,6 @@ PostProcessParameters PreparePostProcess(CullingResults cullResults, HDCamera hd result.blueNoise = m_BlueNoise; result.useDepthBuffer = !hdCamera.IsTAAEnabled() && hdCamera.frameSettings.IsEnabled(FrameSettingsField.ZTestAfterPostProcessTAA); - result.time = m_Time; - result.lastTime = m_LastTime; - result.frameCount = m_FrameCount; result.opaqueAfterPPDesc = CreateOpaqueRendererListDesc(cullResults, hdCamera.camera, HDShaderPassNames.s_ForwardOnlyName, renderQueueRange: HDRenderQueue.k_RenderQueue_AfterPostProcessOpaque); result.transparentAfterPPDesc = CreateTransparentRendererListDesc(cullResults, hdCamera.camera, HDShaderPassNames.s_ForwardOnlyName, renderQueueRange: HDRenderQueue.k_RenderQueue_AfterPostProcessTransparent); @@ -3722,7 +3716,7 @@ static void RenderAfterPostProcess(PostProcessParameters parameters, // The issue is that the only available depth buffer is jittered so pixels would wobble around depth tested edges. // In order to avoid that we decide that objects rendered after Post processes while TAA is active will not benefit from the depth buffer so we disable it. parameters.hdCamera.UpdateAllViewConstants(false); - parameters.hdCamera.UpdateShaderVariablesGlobalCB(ref parameters.globalCB, parameters.frameCount); + parameters.hdCamera.UpdateShaderVariablesGlobalCB(ref parameters.globalCB); UpdateOffscreenRenderingConstants(ref parameters.globalCB, true, 1); ConstantBuffer.PushGlobal(cmd, parameters.globalCB, HDShaderIDs._ShaderVariablesGlobal); @@ -3914,7 +3908,7 @@ public OverrideCameraRendering(CommandBuffer cmd, Camera overrideCamera) overrideHDCamera.Update(overrideHDCamera.frameSettings, hdrp, hdrp.m_MSAASamples, hdrp.m_XRSystem.emptyPass, allocateHistoryBuffers: false); // Reset the reference size as it could have been changed by the override camera hdrp.m_CurrentHDCamera.SetReferenceSize(); - overrideHDCamera.UpdateShaderVariablesGlobalCB(ref hdrp.m_ShaderVariablesGlobalCB, hdrp.m_FrameCount); + overrideHDCamera.UpdateShaderVariablesGlobalCB(ref hdrp.m_ShaderVariablesGlobalCB); ConstantBuffer.PushGlobal(cmd, hdrp.m_ShaderVariablesGlobalCB, HDShaderIDs._ShaderVariablesGlobal); } @@ -3949,7 +3943,7 @@ void IDisposable.Dispose() var hdrp = HDRenderPipeline.currentPipeline; // Reset the reference size as it could have been changed by the override camera hdrp.m_CurrentHDCamera.SetReferenceSize(); - hdrp.m_CurrentHDCamera.UpdateShaderVariablesGlobalCB(ref hdrp.m_ShaderVariablesGlobalCB, hdrp.m_FrameCount); + hdrp.m_CurrentHDCamera.UpdateShaderVariablesGlobalCB(ref hdrp.m_ShaderVariablesGlobalCB); ConstantBuffer.PushGlobal(cmd, hdrp.m_ShaderVariablesGlobalCB, HDShaderIDs._ShaderVariablesGlobal); } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.RenderGraph.cs index ca0f6d88a72..4253425e7e6 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.RenderGraph.cs @@ -5,7 +5,7 @@ namespace UnityEngine.Rendering.HighDefinition { partial class HDRaytracingAmbientOcclusion { - public TextureHandle RenderRTAO(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthPyramid, TextureHandle normalBuffer, TextureHandle motionVectors, TextureHandle rayCountTexture, int frameCount, ShaderVariablesRaytracing shaderVariablesRaytracing) + public TextureHandle RenderRTAO(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthPyramid, TextureHandle normalBuffer, TextureHandle motionVectors, TextureHandle rayCountTexture, ShaderVariablesRaytracing shaderVariablesRaytracing) { var settings = hdCamera.volumeStack.GetComponent(); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingIndirectDiffuse.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingIndirectDiffuse.RenderGraph.cs index b950d096c32..90c2a9aea27 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingIndirectDiffuse.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingIndirectDiffuse.RenderGraph.cs @@ -121,7 +121,7 @@ static RTHandle RequestRayTracedIndirectDiffuseHistoryTexture(HDCamera hdCamera) TextureHandle RenderIndirectDiffusePerformance(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthPyramid, TextureHandle stencilBuffer, TextureHandle normalBuffer, TextureHandle motionVectors, TextureHandle rayCountTexture, Texture skyTexture, - int frameCount, ShaderVariablesRaytracing shaderVariablesRaytracing) + ShaderVariablesRaytracing shaderVariablesRaytracing) { // Pointer to the final result TextureHandle rtgiResult; @@ -188,7 +188,7 @@ TextureHandle QualityRTGI(RenderGraph renderGraph, in QualityRTIndirectDiffusePa TextureHandle RenderIndirectDiffuseQuality(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthPyramid, TextureHandle stencilBuffer, TextureHandle normalBuffer, TextureHandle motionVectors, TextureHandle rayCountTexture, Texture skyTexture, - int frameCount, ShaderVariablesRaytracing shaderVariablesRaytracing) + ShaderVariablesRaytracing shaderVariablesRaytracing) { var settings = hdCamera.volumeStack.GetComponent(); @@ -269,7 +269,7 @@ TextureHandle DenoiseRTGI(RenderGraph renderGraph, HDCamera hdCamera, TextureHan TextureHandle RenderRayTracedIndirectDiffuse(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthPyramid, TextureHandle stencilBuffer, TextureHandle normalBuffer, TextureHandle motionVectors, Texture skyTexture, TextureHandle rayCountTexture, - int frameCount, ShaderVariablesRaytracing shaderVariablesRaytracing) + ShaderVariablesRaytracing shaderVariablesRaytracing) { GlobalIllumination giSettings = hdCamera.volumeStack.GetComponent(); @@ -286,11 +286,11 @@ TextureHandle RenderRayTracedIndirectDiffuse(RenderGraph renderGraph, HDCamera h if (qualityMode) rtreflResult = RenderIndirectDiffuseQuality(renderGraph, hdCamera, depthPyramid, stencilBuffer, normalBuffer, motionVectors, rayCountTexture, skyTexture, - frameCount, shaderVariablesRaytracing); + shaderVariablesRaytracing); else rtreflResult = RenderIndirectDiffusePerformance(renderGraph, hdCamera, depthPyramid, stencilBuffer, normalBuffer, motionVectors, rayCountTexture, skyTexture, - frameCount, shaderVariablesRaytracing); + shaderVariablesRaytracing); return rtreflResult; } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingReflection.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingReflection.RenderGraph.cs index 09e092fc288..871139c585e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingReflection.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingReflection.RenderGraph.cs @@ -146,7 +146,7 @@ static RTHandle RequestRayTracedReflectionsHistoryTexture(HDCamera hdCamera) TextureHandle RenderReflectionsPerformance(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthPyramid, TextureHandle stencilBuffer, TextureHandle normalBuffer, TextureHandle motionVectors, TextureHandle rayCountTexture, TextureHandle clearCoatTexture, Texture skyTexture, - int frameCount, ShaderVariablesRaytracing shaderVariablesRaytracing, bool transparent) + ShaderVariablesRaytracing shaderVariablesRaytracing, bool transparent) { // Pointer to the final result TextureHandle rtrResult; @@ -237,7 +237,7 @@ TextureHandle QualityRTR(RenderGraph renderGraph, in RTRQualityRenderingParamete TextureHandle RenderReflectionsQuality(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthPyramid, TextureHandle stencilBuffer, TextureHandle normalBuffer, TextureHandle motionVectors, TextureHandle rayCountTexture, TextureHandle clearCoatTexture, Texture skyTexture, - int frameCount, ShaderVariablesRaytracing shaderVariablesRaytracing, bool transparent) + ShaderVariablesRaytracing shaderVariablesRaytracing, bool transparent) { TextureHandle rtrResult; @@ -266,7 +266,7 @@ TextureHandle RenderReflectionsQuality(RenderGraph renderGraph, HDCamera hdCamer TextureHandle RenderRayTracedReflections(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthPyramid, TextureHandle stencilBuffer, TextureHandle normalBuffer, TextureHandle motionVectors, TextureHandle clearCoatTexture, Texture skyTexture, TextureHandle rayCountTexture, - int frameCount, ShaderVariablesRaytracing shaderVariablesRaytracing, bool transparent) + ShaderVariablesRaytracing shaderVariablesRaytracing, bool transparent) { ScreenSpaceReflection reflectionSettings = hdCamera.volumeStack.GetComponent(); @@ -283,11 +283,11 @@ TextureHandle RenderRayTracedReflections(RenderGraph renderGraph, HDCamera hdCam if (qualityMode) rtreflResult = RenderReflectionsQuality(renderGraph, hdCamera, depthPyramid, stencilBuffer, normalBuffer, motionVectors, rayCountTexture, clearCoatTexture, skyTexture, - frameCount, shaderVariablesRaytracing, transparent); + shaderVariablesRaytracing, transparent); else rtreflResult = RenderReflectionsPerformance(renderGraph, hdCamera, depthPyramid, stencilBuffer, normalBuffer, motionVectors, rayCountTexture, clearCoatTexture, skyTexture, - frameCount, shaderVariablesRaytracing, transparent); + shaderVariablesRaytracing, transparent); return rtreflResult; } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudSystem/CloudLayer/CloudLayerRenderer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudSystem/CloudLayer/CloudLayerRenderer.cs index c26d6adef14..f17b90ad83c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudSystem/CloudLayer/CloudLayerRenderer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudSystem/CloudLayer/CloudLayerRenderer.cs @@ -84,18 +84,14 @@ public override void PreRenderClouds(BuiltinSkyParameters builtinParams, bool re public override void RenderClouds(BuiltinSkyParameters builtinParams, bool renderForCubemap) { + var hdCamera = builtinParams.hdCamera; var cmd = builtinParams.commandBuffer; var cloudLayer = builtinParams.cloudSettings as CloudLayer; if (cloudLayer.opacity.value == 0.0f) return; -#if UNITY_EDITOR - float time = (float)EditorApplication.timeSinceStartup; -#else - float time = Time.time; -#endif - float dt = time - lastTime; - lastTime = time; + float dt = hdCamera.animateMaterials ? hdCamera.time - lastTime : 0.0f; + lastTime = hdCamera.time; m_CloudLayerMaterial.SetTexture(_CloudTexture, m_PrecomputedData.cloudTextureRT); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISkyRenderer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISkyRenderer.cs index db4cca4e8b9..03a7c7f0f14 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISkyRenderer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISkyRenderer.cs @@ -149,20 +149,15 @@ public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderFo else m_SkyHDRIMaterial.DisableKeyword("USE_FLOWMAP"); + var hdCamera = builtinParams.hdCamera; float rot = -Mathf.Deg2Rad * hdriSky.scrollDirection.value; bool upperHemisphereOnly = hdriSky.upperHemisphereOnly.value || hdriSky.procedural.value; Vector4 flowmapParam = new Vector4(upperHemisphereOnly ? 1.0f : 0.0f, scrollFactor, Mathf.Cos(rot), Mathf.Sin(rot)); m_SkyHDRIMaterial.SetVector(HDShaderIDs._FlowmapParam, flowmapParam); -#if UNITY_EDITOR - // Time.time is not always updated in editor - float time = (float)EditorApplication.timeSinceStartup; -#else - float time = Time.time; -#endif - scrollFactor += hdriSky.scrollSpeed.value * (time - lastTime) * 0.01f; - lastTime = time; + scrollFactor += hdCamera.animateMaterials ? hdriSky.scrollSpeed.value * (hdCamera.time - lastTime) * 0.01f : 0.0f; + lastTime = hdCamera.time; } else m_SkyHDRIMaterial.DisableKeyword("SKY_MOTION"); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs index d66cca43514..134763a5409 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs @@ -751,12 +751,11 @@ public void UpdateEnvironment(HDCamera hdCamera, bool updateAmbientProbe, bool staticSky, SkyAmbientMode ambientMode, - int frameIndex, CommandBuffer cmd) { if (skyContext.IsValid()) { - skyContext.currentUpdateTime += Time.deltaTime; // Consider using HDRenderPipeline.GetTime(). + skyContext.currentUpdateTime += hdCamera.deltaTime; m_BuiltinParameters.hdCamera = hdCamera; m_BuiltinParameters.commandBuffer = cmd; @@ -776,7 +775,7 @@ public void UpdateEnvironment(HDCamera hdCamera, m_BuiltinParameters.viewMatrix = hdCamera.mainViewConstants.viewMatrix; m_BuiltinParameters.screenSize = m_CubemapScreenSize; m_BuiltinParameters.debugSettings = null; // We don't want any debug when updating the environment. - m_BuiltinParameters.frameIndex = frameIndex; + m_BuiltinParameters.frameIndex = (int)hdCamera.GetCameraFrameCount(); m_BuiltinParameters.skySettings = skyContext.skySettings; m_BuiltinParameters.cloudSettings = skyContext.cloudSettings; @@ -871,11 +870,11 @@ public void UpdateEnvironment(HDCamera hdCamera, } } - public void UpdateEnvironment(HDCamera hdCamera, ScriptableRenderContext renderContext, Light sunLight, int frameIndex, CommandBuffer cmd) + public void UpdateEnvironment(HDCamera hdCamera, ScriptableRenderContext renderContext, Light sunLight, CommandBuffer cmd) { SkyAmbientMode ambientMode = hdCamera.volumeStack.GetComponent().skyAmbientMode.value; - UpdateEnvironment(hdCamera, renderContext, hdCamera.lightingSky, sunLight, m_UpdateRequired, ambientMode == SkyAmbientMode.Dynamic, false, ambientMode, frameIndex, cmd); + UpdateEnvironment(hdCamera, renderContext, hdCamera.lightingSky, sunLight, m_UpdateRequired, ambientMode == SkyAmbientMode.Dynamic, false, ambientMode, cmd); // Preview camera will have a different sun, therefore the hash for the static lighting sky will change and force a recomputation // because we only maintain one static sky. Since we don't care that the static lighting may be a bit different in the preview we never recompute @@ -893,7 +892,7 @@ public void UpdateEnvironment(HDCamera hdCamera, ScriptableRenderContext renderC { m_StaticLightingSky.skySettings = staticLightingSky != null ? staticLightingSky.skySettings : null; m_StaticLightingSky.cloudSettings = staticLightingSky != null ? staticLightingSky.cloudSettings : null; - UpdateEnvironment(hdCamera, renderContext, m_StaticLightingSky, sunLight, m_StaticSkyUpdateRequired || m_UpdateRequired, true, true, SkyAmbientMode.Static, frameIndex, cmd); + UpdateEnvironment(hdCamera, renderContext, m_StaticLightingSky, sunLight, m_StaticSkyUpdateRequired || m_UpdateRequired, true, true, SkyAmbientMode.Static, cmd); m_StaticSkyUpdateRequired = false; } @@ -905,7 +904,7 @@ public void UpdateEnvironment(HDCamera hdCamera, ScriptableRenderContext renderC cmd.SetGlobalTexture(HDShaderIDs._SkyTexture, reflectionTexture); } - internal void UpdateBuiltinParameters(SkyUpdateContext skyContext, HDCamera hdCamera, Light sunLight, RTHandle colorBuffer, RTHandle depthBuffer, DebugDisplaySettings debugSettings, int frameIndex, CommandBuffer cmd) + internal void UpdateBuiltinParameters(SkyUpdateContext skyContext, HDCamera hdCamera, Light sunLight, RTHandle colorBuffer, RTHandle depthBuffer, DebugDisplaySettings debugSettings, CommandBuffer cmd) { m_BuiltinParameters.hdCamera = hdCamera; m_BuiltinParameters.commandBuffer = cmd; @@ -917,7 +916,7 @@ internal void UpdateBuiltinParameters(SkyUpdateContext skyContext, HDCamera hdCa m_BuiltinParameters.colorBuffer = colorBuffer; m_BuiltinParameters.depthBuffer = depthBuffer; m_BuiltinParameters.debugSettings = debugSettings; - m_BuiltinParameters.frameIndex = frameIndex; + m_BuiltinParameters.frameIndex = (int)hdCamera.GetCameraFrameCount(); m_BuiltinParameters.skySettings = skyContext.skySettings; m_BuiltinParameters.cloudSettings = skyContext.cloudSettings; } @@ -929,7 +928,7 @@ public bool RequiresPreRenderSky(HDCamera hdCamera) (skyContext.HasClouds() && skyContext.cloudRenderer.RequiresPreRenderClouds(m_BuiltinParameters))); } - public void PreRenderSky(HDCamera hdCamera, Light sunLight, RTHandle colorBuffer, RTHandle normalBuffer, RTHandle depthBuffer, DebugDisplaySettings debugSettings, int frameIndex, CommandBuffer cmd) + public void PreRenderSky(HDCamera hdCamera, Light sunLight, RTHandle colorBuffer, RTHandle normalBuffer, RTHandle depthBuffer, DebugDisplaySettings debugSettings, CommandBuffer cmd) { var skyContext = hdCamera.visualSky; if (skyContext.IsValid()) @@ -940,7 +939,6 @@ public void PreRenderSky(HDCamera hdCamera, Light sunLight, RTHandle colorBuffer colorBuffer, depthBuffer, debugSettings, - frameIndex, cmd); bool preRenderSky = skyContext.skyRenderer.RequiresPreRenderSky(m_BuiltinParameters); @@ -972,7 +970,7 @@ public void PreRenderSky(HDCamera hdCamera, Light sunLight, RTHandle colorBuffer } } - public void RenderSky(HDCamera hdCamera, Light sunLight, RTHandle colorBuffer, RTHandle depthBuffer, DebugDisplaySettings debugSettings, int frameIndex, CommandBuffer cmd) + public void RenderSky(HDCamera hdCamera, Light sunLight, RTHandle colorBuffer, RTHandle depthBuffer, DebugDisplaySettings debugSettings, CommandBuffer cmd) { if (hdCamera.clearColorMode != HDAdditionalCameraData.ClearColorMode.Sky || // If the luxmeter is enabled, we don't render the sky @@ -990,7 +988,6 @@ public void RenderSky(HDCamera hdCamera, Light sunLight, RTHandle colorBuffer, R colorBuffer, depthBuffer, debugSettings, - frameIndex, cmd); SkyAmbientMode ambientMode = hdCamera.volumeStack.GetComponent().skyAmbientMode.value; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Utilities/CameraCache.cs b/com.unity.render-pipelines.high-definition/Runtime/Utilities/CameraCache.cs index 3518e7217b0..94127ac2d81 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Utilities/CameraCache.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Utilities/CameraCache.cs @@ -41,7 +41,7 @@ public Camera GetOrCreate(K key, int frameCount, CameraType cameraType = CameraT } else { - camera.lastFrame = Time.frameCount; + camera.lastFrame = frameCount; m_Cache[key] = camera; } return camera.camera; @@ -65,7 +65,7 @@ public void ClearCamerasUnusedFor(int frameWindow, int frameCount) { if (m_Cache.TryGetValue(key, out var value)) { - if ((frameCount - value.lastFrame) > frameWindow) + if (Math.Abs(frameCount - value.lastFrame) > frameWindow) { if (value.camera != null) {