internal HDDiffuseDenoiser GetDiffuseDenoiser() { if (m_DiffuseDenoiser == null) { m_DiffuseDenoiser = new HDDiffuseDenoiser(); m_DiffuseDenoiser.Init(m_Asset.renderPipelineResources, m_Asset.renderPipelineRayTracingResources, this); } return(m_DiffuseDenoiser); }
internal HDDiffuseDenoiser GetDiffuseDenoiser() { if (m_DiffuseDenoiser == null) { m_DiffuseDenoiser = new HDDiffuseDenoiser(); m_DiffuseDenoiser.Init(HDRenderPipelineGlobalSettings.instance.renderPipelineResources, HDRenderPipelineGlobalSettings.instance.renderPipelineRayTracingResources, this); } return(m_DiffuseDenoiser); }
internal HDDiffuseDenoiser GetDiffuseDenoiser() { if (m_DiffuseDenoiser == null) { m_DiffuseDenoiser = new HDDiffuseDenoiser(); m_DiffuseDenoiser.Init(m_GlobalSettings.renderPipelineResources, this); } return(m_DiffuseDenoiser); }
TextureHandle DenoiseSSGI(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle rtGIBuffer, TextureHandle depthPyramid, TextureHandle normalBuffer, TextureHandle motionVectorBuffer, TextureHandle historyValidationTexture) { var giSettings = hdCamera.volumeStack.GetComponent <GlobalIllumination>(); if (giSettings.denoiseSS) { // Evaluate the history's validity float historyValidity0 = EvaluateIndirectDiffuseHistoryValidity0(hdCamera, true, false); HDTemporalFilter temporalFilter = GetTemporalFilter(); HDDiffuseDenoiser diffuseDenoiser = GetDiffuseDenoiser(); // Run the temporal denoiser TextureHandle historyBufferHF = renderGraph.ImportTexture(RequestIndirectDiffuseHistoryTextureHF(hdCamera)); HDTemporalFilter.TemporalFilterParameters filterParams; filterParams.singleChannel = false; filterParams.historyValidity = historyValidity0; filterParams.occluderMotionRejection = false; filterParams.receiverMotionRejection = false; filterParams.exposureControl = 1.0f; TextureHandle denoisedRTGI = temporalFilter.Denoise(renderGraph, hdCamera, filterParams, rtGIBuffer, renderGraph.defaultResources.blackTextureXR, historyBufferHF, depthPyramid, normalBuffer, motionVectorBuffer, historyValidationTexture); // Apply the diffuse denoiser rtGIBuffer = diffuseDenoiser.Denoise(renderGraph, hdCamera, singleChannel: false, kernelSize: giSettings.denoiserRadiusSS, halfResolutionFilter: giSettings.halfResolutionDenoiserSS, jitterFilter: giSettings.secondDenoiserPassSS, denoisedRTGI, depthPyramid, normalBuffer, rtGIBuffer); // If the second pass is requested, do it otherwise blit if (giSettings.secondDenoiserPassSS) { float historyValidity1 = EvaluateIndirectDiffuseHistoryValidity1(hdCamera, true, false); // Run the temporal denoiser TextureHandle historyBufferLF = renderGraph.ImportTexture(RequestIndirectDiffuseHistoryTextureLF(hdCamera)); filterParams.singleChannel = false; filterParams.historyValidity = historyValidity1; filterParams.occluderMotionRejection = false; filterParams.receiverMotionRejection = false; filterParams.exposureControl = 1.0f; denoisedRTGI = temporalFilter.Denoise(renderGraph, hdCamera, filterParams, rtGIBuffer, renderGraph.defaultResources.blackTextureXR, historyBufferLF, depthPyramid, normalBuffer, motionVectorBuffer, historyValidationTexture); // Apply the diffuse denoiser rtGIBuffer = diffuseDenoiser.Denoise(renderGraph, hdCamera, singleChannel: false, kernelSize: giSettings.denoiserRadiusSS * 0.5f, halfResolutionFilter: giSettings.halfResolutionDenoiserSS, jitterFilter: false, denoisedRTGI, depthPyramid, normalBuffer, rtGIBuffer); // Propagate the history validity for the second buffer PropagateIndirectDiffuseHistoryValidity1(hdCamera, true, false); } // Propagate the history validity for the first buffer PropagateIndirectDiffuseHistoryValidity0(hdCamera, true, false); return(rtGIBuffer); } else { return(rtGIBuffer); } }
void DenoiseIndirectDiffuseBuffer(HDCamera hdCamera, CommandBuffer cmd, GlobalIllumination settings) { // Grab the high frequency history buffer RTHandle indirectDiffuseHistoryHF = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.RaytracedIndirectDiffuseHF) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.RaytracedIndirectDiffuseHF, IndirectDiffuseHistoryBufferAllocatorFunction, 1); // Request the intermediate textures we will be using RTHandle intermediateBuffer1 = GetRayTracingBuffer(InternalRayTracingBuffers.RGBA1); RTHandle validationBuffer = GetRayTracingBuffer(InternalRayTracingBuffers.R0); // Evaluate the history validity float historyValidity0 = EvaluateIndirectDiffuseHistoryValidity0(hdCamera, settings.fullResolution, true); // Grab the temporal denoiser HDTemporalFilter temporalFilter = GetTemporalFilter(); // Temporal denoising TemporalFilterParameters tfParameters = temporalFilter.PrepareTemporalFilterParameters(hdCamera, false, historyValidity0); TemporalFilterResources tfResources = temporalFilter.PrepareTemporalFilterResources(hdCamera, validationBuffer, m_IndirectDiffuseBuffer0, indirectDiffuseHistoryHF, intermediateBuffer1); HDTemporalFilter.DenoiseBuffer(cmd, tfParameters, tfResources); // Apply the first pass of our denoiser HDDiffuseDenoiser diffuseDenoiser = GetDiffuseDenoiser(); DiffuseDenoiserParameters ddParams = diffuseDenoiser.PrepareDiffuseDenoiserParameters(hdCamera, false, settings.denoiserRadius, settings.halfResolutionDenoiser, settings.secondDenoiserPass); RTHandle intermediateBuffer = GetRayTracingBuffer(InternalRayTracingBuffers.RGBA0); DiffuseDenoiserResources ddResources = diffuseDenoiser.PrepareDiffuseDenoiserResources(intermediateBuffer1, intermediateBuffer, m_IndirectDiffuseBuffer0); HDDiffuseDenoiser.DenoiseBuffer(cmd, ddParams, ddResources); // If the second pass is requested, do it otherwise blit if (settings.secondDenoiserPass) { float historyValidity1 = EvaluateIndirectDiffuseHistoryValidity1(hdCamera, settings.fullResolution, true); // Grab the low frequency history buffer RTHandle indirectDiffuseHistoryLF = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.RaytracedIndirectDiffuseLF) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.RaytracedIndirectDiffuseLF, IndirectDiffuseHistoryBufferAllocatorFunction, 1); // Run the temporal denoiser tfParameters = temporalFilter.PrepareTemporalFilterParameters(hdCamera, false, historyValidity1); tfResources = temporalFilter.PrepareTemporalFilterResources(hdCamera, validationBuffer, m_IndirectDiffuseBuffer0, indirectDiffuseHistoryLF, intermediateBuffer1); HDTemporalFilter.DenoiseBuffer(cmd, tfParameters, tfResources); // Run the spatial denoiser ddParams = diffuseDenoiser.PrepareDiffuseDenoiserParameters(hdCamera, false, settings.denoiserRadius * 0.5f, settings.halfResolutionDenoiser, false); ddResources = diffuseDenoiser.PrepareDiffuseDenoiserResources(intermediateBuffer1, intermediateBuffer, m_IndirectDiffuseBuffer0); HDDiffuseDenoiser.DenoiseBuffer(cmd, ddParams, ddResources); PropagateIndirectDiffuseHistoryValidity1(hdCamera, settings.fullResolution, true); } // Propagate the history PropagateIndirectDiffuseHistoryValidity0(hdCamera, settings.fullResolution, true); }
public void DenoiseAO(CommandBuffer cmd, HDCamera hdCamera, AmbientOcclusionDenoiseParameters aoDenoiseParameters, AmbientOcclusionDenoiseResources aoDenoiseResources) { if (aoDenoiseParameters.denoise) { // Apply the temporal denoiser HDTemporalFilter temporalFilter = m_RenderPipeline.GetTemporalFilter(); temporalFilter.DenoiseBuffer(cmd, hdCamera, aoDenoiseResources.inputTexture, aoDenoiseResources.ambientOcclusionHistory, aoDenoiseResources.intermediateBuffer, historyValidity: aoDenoiseParameters.historyValidity); // Apply the diffuse denoiser HDDiffuseDenoiser diffuseDenoiser = m_RenderPipeline.GetDiffuseDenoiser(); diffuseDenoiser.DenoiseBuffer(cmd, hdCamera, aoDenoiseResources.intermediateBuffer, aoDenoiseResources.outputTexture, aoDenoiseParameters.denoiserRadius); } else { HDUtils.BlitCameraTexture(cmd, aoDenoiseResources.inputTexture, aoDenoiseResources.outputTexture); } }
void DenoiseIndirectDiffuseBuffer(HDCamera hdCamera, CommandBuffer cmd, GlobalIllumination settings) { // Grab the high frequency history buffer RTHandle indirectDiffuseHistoryHF = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.RaytracedIndirectDiffuseHF) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.RaytracedIndirectDiffuseHF, IndirectDiffuseHistoryBufferAllocatorFunction, 1); // Request the intermediate texture we will be using RTHandle intermediateBuffer1 = GetRayTracingBuffer(InternalRayTracingBuffers.RGBA1); float historyValidity = 1.0f; #if UNITY_HDRP_DXR_TESTS_DEFINE if (Application.isPlaying) { historyValidity = 0.0f; } else #endif // We need to check if something invalidated the history buffers historyValidity *= ValidRayTracingHistory(hdCamera) ? 1.0f : 0.0f; // Apply the temporal denoiser HDTemporalFilter temporalFilter = GetTemporalFilter(); temporalFilter.DenoiseBuffer(cmd, hdCamera, m_IndirectDiffuseBuffer, indirectDiffuseHistoryHF, intermediateBuffer1, singleChannel: false, historyValidity: historyValidity); // Apply the first pass of our denoiser HDDiffuseDenoiser diffuseDenoiser = GetDiffuseDenoiser(); diffuseDenoiser.DenoiseBuffer(cmd, hdCamera, intermediateBuffer1, m_IndirectDiffuseBuffer, settings.denoiserRadius.value, singleChannel: false, halfResolutionFilter: settings.halfResolutionDenoiser.value); // If the second pass is requested, do it otherwise blit if (settings.secondDenoiserPass.value) { // Grab the low frequency history buffer RTHandle indirectDiffuseHistoryLF = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.RaytracedIndirectDiffuseLF) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.RaytracedIndirectDiffuseLF, IndirectDiffuseHistoryBufferAllocatorFunction, 1); temporalFilter.DenoiseBuffer(cmd, hdCamera, m_IndirectDiffuseBuffer, indirectDiffuseHistoryLF, intermediateBuffer1, singleChannel: false, historyValidity: historyValidity); diffuseDenoiser.DenoiseBuffer(cmd, hdCamera, intermediateBuffer1, m_IndirectDiffuseBuffer, settings.secondDenoiserRadius.value, singleChannel: false, halfResolutionFilter: settings.halfResolutionDenoiser.value); } }
public void DenoiseAO(CommandBuffer cmd, HDCamera hdCamera, AmbientOcclusionDenoiseParameters aoDenoiseParameters, AmbientOcclusionDenoiseResources aoDenoiseResources) { if (aoDenoiseParameters.denoise) { // Prepare and execute the temporal filter HDTemporalFilter temporalFilter = m_RenderPipeline.GetTemporalFilter(); TemporalFilterParameters tfParameters = temporalFilter.PrepareTemporalFilterParameters(hdCamera, true, aoDenoiseParameters.historyValidity); RTHandle validationBuffer = m_RenderPipeline.GetRayTracingBuffer(InternalRayTracingBuffers.R0); TemporalFilterResources tfResources = temporalFilter.PrepareTemporalFilterResources(hdCamera, validationBuffer, aoDenoiseResources.inputTexture, aoDenoiseResources.ambientOcclusionHistory, aoDenoiseResources.intermediateBuffer); HDTemporalFilter.DenoiseBuffer(cmd, tfParameters, tfResources); // Apply the diffuse denoiser HDDiffuseDenoiser diffuseDenoiser = m_RenderPipeline.GetDiffuseDenoiser(); DiffuseDenoiserParameters ddParams = diffuseDenoiser.PrepareDiffuseDenoiserParameters(hdCamera, true, aoDenoiseParameters.denoiserRadius, false); RTHandle intermediateBuffer = m_RenderPipeline.GetRayTracingBuffer(InternalRayTracingBuffers.RGBA0); DiffuseDenoiserResources ddResources = diffuseDenoiser.PrepareDiffuseDenoiserResources(aoDenoiseResources.intermediateBuffer, intermediateBuffer, aoDenoiseResources.outputTexture); HDDiffuseDenoiser.DenoiseBuffer(cmd, ddParams, ddResources); } else { HDUtils.BlitCameraTexture(cmd, aoDenoiseResources.inputTexture, aoDenoiseResources.outputTexture); } }
public void RenderAO(HDCamera hdCamera, CommandBuffer cmd, RTHandle outputTexture, ScriptableRenderContext renderContext, int frameCount) { // Let's check all the resources HDRaytracingEnvironment rtEnvironment = m_RaytracingManager.CurrentEnvironment(); BlueNoise blueNoise = m_RaytracingManager.GetBlueNoiseManager(); // Check if the state is valid for evaluating ambient occlusion bool invalidState = rtEnvironment == null; // If any of the previous requirements is missing, the effect is not requested or no acceleration structure, set the default one and leave right away if (invalidState) { SetDefaultAmbientOcclusionTexture(cmd); return; } RayTracingShader aoShader = m_PipelineRayTracingResources.aoRaytracing; var aoSettings = VolumeManager.instance.stack.GetComponent <AmbientOcclusion>(); // Grab the acceleration structure for the target camera RayTracingAccelerationStructure accelerationStructure = m_RaytracingManager.RequestAccelerationStructure(rtEnvironment.aoLayerMask); // Define the shader pass to use for the reflection pass cmd.SetRayTracingShaderPass(aoShader, "VisibilityDXR"); // Set the acceleration structure for the pass cmd.SetRayTracingAccelerationStructure(aoShader, HDShaderIDs._RaytracingAccelerationStructureName, accelerationStructure); // Inject the ray generation data cmd.SetRayTracingFloatParams(aoShader, HDShaderIDs._RaytracingRayBias, rtEnvironment.rayBias); cmd.SetRayTracingFloatParams(aoShader, HDShaderIDs._RaytracingRayMaxLength, aoSettings.rayLength.value); cmd.SetRayTracingIntParams(aoShader, HDShaderIDs._RaytracingNumSamples, aoSettings.sampleCount.value); // Set the data for the ray generation cmd.SetRayTracingTextureParam(aoShader, HDShaderIDs._DepthTexture, m_SharedRTManager.GetDepthStencilBuffer()); cmd.SetRayTracingTextureParam(aoShader, HDShaderIDs._NormalBufferTexture, m_SharedRTManager.GetNormalBuffer()); int frameIndex = hdCamera.IsTAAEnabled() ? hdCamera.taaFrameIndex : (int)frameCount % 8; cmd.SetGlobalInt(HDShaderIDs._RaytracingFrameIndex, frameIndex); // Inject the ray-tracing sampling data blueNoise.BindDitheredRNGData8SPP(cmd); // Value used to scale the ao intensity cmd.SetRayTracingFloatParam(aoShader, HDShaderIDs._RaytracingAOIntensity, aoSettings.intensity.value); cmd.SetRayTracingIntParam(aoShader, HDShaderIDs._RayCountEnabled, m_RaytracingManager.rayCountManager.RayCountIsEnabled()); cmd.SetRayTracingTextureParam(aoShader, HDShaderIDs._RayCountTexture, m_RaytracingManager.rayCountManager.GetRayCountTexture()); // Set the output textures cmd.SetRayTracingTextureParam(aoShader, HDShaderIDs._AmbientOcclusionTextureRW, m_AOIntermediateBuffer0); // Run the computation cmd.DispatchRays(aoShader, m_RayGenShaderName, (uint)hdCamera.actualWidth, (uint)hdCamera.actualHeight, (uint)hdCamera.viewCount); using (new ProfilingSample(cmd, "Filter Ambient Occlusion", CustomSamplerId.RaytracingAmbientOcclusion.GetSampler())) { if (aoSettings.denoise.value) { // Grab the history buffer RTHandle ambientOcclusionHistory = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.RaytracedAmbientOcclusion) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.RaytracedAmbientOcclusion, AmbientOcclusionHistoryBufferAllocatorFunction, 1); // Apply the temporal denoiser HDTemporalFilter temporalFilter = m_RaytracingManager.GetTemporalFilter(); temporalFilter.DenoiseBuffer(cmd, hdCamera, m_AOIntermediateBuffer0, ambientOcclusionHistory, m_AOIntermediateBuffer1); // Apply the diffuse denoiser HDDiffuseDenoiser diffuseDenoiser = m_RaytracingManager.GetDiffuseDenoiser(); diffuseDenoiser.DenoiseBuffer(cmd, hdCamera, m_AOIntermediateBuffer1, outputTexture, aoSettings.denoiserRadius.value); } else { HDUtils.BlitCameraTexture(cmd, m_AOIntermediateBuffer0, outputTexture); } } // Bind the textures and the params cmd.SetGlobalTexture(HDShaderIDs._AmbientOcclusionTexture, outputTexture); cmd.SetGlobalVector(HDShaderIDs._AmbientOcclusionParam, new Vector4(0f, 0f, 0f, VolumeManager.instance.stack.GetComponent <AmbientOcclusion>().directLightingStrength.value)); // TODO: All the push-debug stuff should be centralized somewhere (RenderPipelineManager.currentPipeline as HDRenderPipeline).PushFullScreenDebugTexture(hdCamera, cmd, outputTexture, FullScreenDebugMode.SSAO); }
public void RenderAO(HDCamera hdCamera, CommandBuffer cmd, RTHandle outputTexture, ShaderVariablesRaytracing globalCB, ScriptableRenderContext renderContext, int frameCount) { // If any of the previous requirements is missing, the effect is not requested or no acceleration structure, set the default one and leave right away if (!m_RenderPipeline.GetRayTracingState()) { SetDefaultAmbientOcclusionTexture(cmd); return; } RayTracingShader aoShader = m_PipelineRayTracingResources.aoRaytracing; var aoSettings = hdCamera.volumeStack.GetComponent <AmbientOcclusion>(); RayCountManager rayCountManager = m_RenderPipeline.GetRayCountManager(); using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RaytracingAmbientOcclusion))) { // Grab the acceleration structure for the target camera RayTracingAccelerationStructure accelerationStructure = m_RenderPipeline.RequestAccelerationStructure(); // Define the shader pass to use for the reflection pass cmd.SetRayTracingShaderPass(aoShader, "VisibilityDXR"); // Set the acceleration structure for the pass cmd.SetRayTracingAccelerationStructure(aoShader, HDShaderIDs._RaytracingAccelerationStructureName, accelerationStructure); // Inject the ray generation data (be careful of the global constant buffer limitation) globalCB._RaytracingRayMaxLength = aoSettings.rayLength; globalCB._RaytracingNumSamples = aoSettings.sampleCount; ConstantBuffer.PushGlobal(cmd, globalCB, HDShaderIDs._ShaderVariablesRaytracing); // Set the data for the ray generation cmd.SetRayTracingTextureParam(aoShader, HDShaderIDs._DepthTexture, m_RenderPipeline.sharedRTManager.GetDepthStencilBuffer()); cmd.SetRayTracingTextureParam(aoShader, HDShaderIDs._NormalBufferTexture, m_RenderPipeline.sharedRTManager.GetNormalBuffer()); // Inject the ray-tracing sampling data BlueNoise blueNoise = m_RenderPipeline.GetBlueNoiseManager(); blueNoise.BindDitheredRNGData8SPP(cmd); // Value used to scale the ao intensity cmd.SetRayTracingFloatParam(aoShader, HDShaderIDs._RaytracingAOIntensity, aoSettings.intensity.value); // Set the output textures cmd.SetRayTracingTextureParam(aoShader, HDShaderIDs._RayCountTexture, rayCountManager.GetRayCountTexture()); cmd.SetRayTracingTextureParam(aoShader, HDShaderIDs._AmbientOcclusionTextureRW, m_AOIntermediateBuffer0); // Run the computation cmd.DispatchRays(aoShader, m_RayGenShaderName, (uint)hdCamera.actualWidth, (uint)hdCamera.actualHeight, (uint)hdCamera.viewCount); } using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RaytracingFilterAmbientOcclusion))) { if (aoSettings.denoise) { // Grab the history buffer RTHandle ambientOcclusionHistory = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.RaytracedAmbientOcclusion) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.RaytracedAmbientOcclusion, AmbientOcclusionHistoryBufferAllocatorFunction, 1); float historyValidity = 1.0f; #if UNITY_HDRP_DXR_TESTS_DEFINE if (Application.isPlaying) { historyValidity = 0.0f; } else #endif // We need to check if something invalidated the history buffers historyValidity = m_RenderPipeline.ValidRayTracingHistory(hdCamera) ? 1.0f : 0.0f; // Apply the temporal denoiser HDTemporalFilter temporalFilter = m_RenderPipeline.GetTemporalFilter(); temporalFilter.DenoiseBuffer(cmd, hdCamera, m_AOIntermediateBuffer0, ambientOcclusionHistory, m_AOIntermediateBuffer1, historyValidity: historyValidity); // Apply the diffuse denoiser HDDiffuseDenoiser diffuseDenoiser = m_RenderPipeline.GetDiffuseDenoiser(); diffuseDenoiser.DenoiseBuffer(cmd, hdCamera, m_AOIntermediateBuffer1, outputTexture, aoSettings.denoiserRadius); } else { HDUtils.BlitCameraTexture(cmd, m_AOIntermediateBuffer0, outputTexture); } } // Bind the textures and the params cmd.SetGlobalTexture(HDShaderIDs._AmbientOcclusionTexture, outputTexture); // TODO: All the push-debug stuff should be centralized somewhere (RenderPipelineManager.currentPipeline as HDRenderPipeline).PushFullScreenDebugTexture(hdCamera, cmd, outputTexture, FullScreenDebugMode.SSAO); }