internal HDDiffuseShadowDenoiser GetDiffuseShadowDenoiser() { if (m_DiffuseShadowDenoiser == null) { m_DiffuseShadowDenoiser = new HDDiffuseShadowDenoiser(); m_DiffuseShadowDenoiser.Init(m_Asset.renderPipelineRayTracingResources, sharedRTManager, this); } return(m_DiffuseShadowDenoiser); }
internal HDDiffuseShadowDenoiser GetDiffuseShadowDenoiser() { if (m_DiffuseShadowDenoiser == null) { m_DiffuseShadowDenoiser = new HDDiffuseShadowDenoiser(); m_DiffuseShadowDenoiser.Init(m_GlobalSettings.renderPipelineRayTracingResources); } return(m_DiffuseShadowDenoiser); }
TextureHandle DenoiseDirectionalScreenSpaceShadow(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthBuffer, TextureHandle normalBuffer, TextureHandle motionVetorsBuffer, TextureHandle noisyBuffer, TextureHandle velocityBuffer, TextureHandle distanceBuffer) { // Is the history still valid? int dirShadowIndex = m_CurrentSunLightDirectionalLightData.screenSpaceShadowIndex & (int)LightDefinitions.s_ScreenSpaceShadowIndexMask; float historyValidity = EvaluateHistoryValidityDirectionalShadow(hdCamera, dirShadowIndex, m_CurrentSunLightAdditionalLightData); // Grab the history buffers for shadows RTHandle shadowHistoryArray = RequestShadowHistoryBuffer(hdCamera); RTHandle shadowHistoryDistanceArray = RequestShadowHistoryDistanceBuffer(hdCamera); RTHandle shadowHistoryValidityArray = RequestShadowHistoryValidityBuffer(hdCamera); // Evaluate the slot of the directional light (given that it may be a color shadow, we need to use the mask to get the actual slot indices) GetShadowChannelMask(dirShadowIndex, m_CurrentSunLightAdditionalLightData.colorShadow ? ScreenSpaceShadowType.Color : ScreenSpaceShadowType.GrayScale, ref m_ShadowChannelMask0); GetShadowChannelMask(dirShadowIndex, ScreenSpaceShadowType.GrayScale, ref m_ShadowChannelMask1); // Apply the temporal denoiser HDTemporalFilter temporalFilter = GetTemporalFilter(); HDTemporalFilter.TemporalDenoiserArrayOutputData temporalFilterResult = temporalFilter.DenoiseBuffer(renderGraph, hdCamera, depthBuffer, normalBuffer, motionVetorsBuffer, noisyBuffer, shadowHistoryArray, distanceBuffer, shadowHistoryDistanceArray, velocityBuffer, shadowHistoryValidityArray, dirShadowIndex / 4, m_ShadowChannelMask0, m_ShadowChannelMask1, true, !m_CurrentSunLightAdditionalLightData.colorShadow, historyValidity); // Apply the spatial denoiser HDDiffuseShadowDenoiser shadowDenoiser = GetDiffuseShadowDenoiser(); TextureHandle denoisedBuffer = shadowDenoiser.DenoiseBufferDirectional(renderGraph, hdCamera, depthBuffer, normalBuffer, temporalFilterResult.outputSignal, temporalFilterResult.outputSignalDistance, m_CurrentSunLightAdditionalLightData.filterSizeTraced, m_CurrentSunLightAdditionalLightData.angularDiameter * 0.5f, !m_CurrentSunLightAdditionalLightData.colorShadow); // Now that we have overriden this history, mark is as used by this light hdCamera.PropagateShadowHistory(m_CurrentSunLightAdditionalLightData, dirShadowIndex, GPULightType.Directional); return(denoisedBuffer); }
void DenoiseDirectionalScreenSpaceShadow(CommandBuffer cmd, HDCamera hdCamera, RTHandle velocityBuffer, RTHandle distanceBuffer, RTHandle inoutBuffer) { RTHandle intermediateBuffer = GetRayTracingBuffer(InternalRayTracingBuffers.RGBA1); RTHandle intermediateDistanceBuffer = GetRayTracingBuffer(InternalRayTracingBuffers.RG0); // Is the history still valid? int dirShadowIndex = m_CurrentSunLightDirectionalLightData.screenSpaceShadowIndex & (int)LightDefinitions.s_ScreenSpaceShadowIndexMask; float historyValidity = EvaluateHistoryValidityDirectionalShadow(hdCamera, dirShadowIndex, m_CurrentSunLightAdditionalLightData); // Grab the history buffers for shadows RTHandle shadowHistoryArray = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.RaytracedShadowHistory) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.RaytracedShadowHistory, ShadowHistoryBufferAllocatorFunction, 1); RTHandle shadowHistoryValidityArray = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.RaytracedShadowHistoryValidity) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.RaytracedShadowHistoryValidity, ShadowHistoryValidityBufferAllocatorFunction, 1); RTHandle shadowHistoryDistanceArray = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.RaytracedShadowDistanceValidity) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.RaytracedShadowDistanceValidity, ShadowHistoryDistanceBufferAllocatorFunction, 1); // Grab the slot of the directional light (given that it may be a color shadow, we need to use the mask to get the actual slot index) GetShadowChannelMask(dirShadowIndex, m_CurrentSunLightAdditionalLightData.colorShadow ? ScreenSpaceShadowType.Color : ScreenSpaceShadowType.GrayScale, ref m_ShadowChannelMask0); GetShadowChannelMask(dirShadowIndex, ScreenSpaceShadowType.GrayScale, ref m_ShadowChannelMask1); // Apply the temporal denoiser HDTemporalFilter temporalFilter = GetTemporalFilter(); temporalFilter.DenoiseBuffer(cmd, hdCamera, inoutBuffer, shadowHistoryArray, shadowHistoryValidityArray, velocityBuffer, intermediateBuffer, dirShadowIndex / 4, m_ShadowChannelMask0, distanceBuffer, shadowHistoryDistanceArray, intermediateDistanceBuffer, m_ShadowChannelMask1, singleChannel: !m_CurrentSunLightAdditionalLightData.colorShadow, historyValidity: historyValidity); // Apply the spatial denoiser HDDiffuseShadowDenoiser shadowDenoiser = GetDiffuseShadowDenoiser(); shadowDenoiser.DenoiseBufferDirectional(cmd, hdCamera, intermediateBuffer, intermediateDistanceBuffer, inoutBuffer, m_CurrentSunLightAdditionalLightData.filterSizeTraced, m_CurrentSunLightAdditionalLightData.angularDiameter * 0.5f, singleChannel: !m_CurrentSunLightAdditionalLightData.colorShadow); // Now that we have overriden this history, mark is as used by this light hdCamera.PropagateShadowHistory(m_CurrentSunLightAdditionalLightData, dirShadowIndex, GPULightType.Directional); }