public void EvaluateClusterDebugView(CommandBuffer cmd, HDCamera hdCamera) { ComputeShader lightClusterDebugCS = m_RenderPipelineRayTracingResources.lightClusterDebugCS; if (lightClusterDebugCS == null) { return; } // Bind the output texture CoreUtils.SetRenderTarget(cmd, m_DebugLightClusterTexture, m_SharedRTManager.GetDepthStencilBuffer(), clearFlag: ClearFlag.Color, clearColor: Color.black); // Grab the kernel int m_LightClusterDebugKernel = lightClusterDebugCS.FindKernel("DebugLightCluster"); // Inject all the parameters to the debug compute cmd.SetComputeBufferParam(lightClusterDebugCS, m_LightClusterDebugKernel, HDShaderIDs._RaytracingLightCluster, m_LightCluster); cmd.SetComputeVectorParam(lightClusterDebugCS, HDShaderIDs._MinClusterPos, minClusterPos); cmd.SetComputeVectorParam(lightClusterDebugCS, HDShaderIDs._MaxClusterPos, maxClusterPos); cmd.SetComputeVectorParam(lightClusterDebugCS, _ClusterCellSize, clusterCellSize); cmd.SetComputeIntParam(lightClusterDebugCS, HDShaderIDs._LightPerCellCount, numLightsPerCell); cmd.SetComputeTextureParam(lightClusterDebugCS, m_LightClusterDebugKernel, HDShaderIDs._CameraDepthTexture, m_SharedRTManager.GetDepthStencilBuffer()); // Target output texture cmd.SetComputeTextureParam(lightClusterDebugCS, m_LightClusterDebugKernel, _DebutLightClusterTexture, m_DebugLightClusterTexture); // Texture dimensions int texWidth = hdCamera.actualWidth; int texHeight = hdCamera.actualHeight; // Dispatch the compute int lightVolumesTileSize = 8; int numTilesX = (texWidth + (lightVolumesTileSize - 1)) / lightVolumesTileSize; int numTilesY = (texHeight + (lightVolumesTileSize - 1)) / lightVolumesTileSize; cmd.DispatchCompute(lightClusterDebugCS, m_LightClusterDebugKernel, numTilesX, numTilesY, 1); // Bind the parameters m_DebugMaterialProperties.SetBuffer(HDShaderIDs._RaytracingLightCluster, m_LightCluster); m_DebugMaterialProperties.SetVector(HDShaderIDs._MinClusterPos, minClusterPos); m_DebugMaterialProperties.SetVector(HDShaderIDs._MaxClusterPos, maxClusterPos); m_DebugMaterialProperties.SetVector(_ClusterCellSize, clusterCellSize); m_DebugMaterialProperties.SetInt(HDShaderIDs._LightPerCellCount, numLightsPerCell); m_DebugMaterialProperties.SetTexture(HDShaderIDs._CameraDepthTexture, m_SharedRTManager.GetDepthTexture()); // Draw the faces cmd.DrawProcedural(Matrix4x4.identity, m_DebugMaterial, 1, MeshTopology.Lines, 48, 64 * 64 * 32, m_DebugMaterialProperties); cmd.DrawProcedural(Matrix4x4.identity, m_DebugMaterial, 0, MeshTopology.Triangles, 36, 64 * 64 * 32, m_DebugMaterialProperties); // Bind the result (RenderPipelineManager.currentPipeline as HDRenderPipeline).PushFullScreenDebugTexture(hdCamera, cmd, m_DebugLightClusterTexture, FullScreenDebugMode.LightCluster); }
SSGIDenoiserResources PrepareSSGIDenoiserResources(RTHandle historyDepthBuffer, RTHandle indirectDiffuseHistory, RTHandle inputOutputBuffer, RTHandle intermediateBuffer) { SSGIDenoiserResources resources = new SSGIDenoiserResources(); // Input Buffers resources.depthTexture = m_SharedRTManager.GetDepthTexture(); resources.normalBuffer = m_SharedRTManager.GetNormalBuffer(); resources.motionVectorsBuffer = m_SharedRTManager.GetMotionVectorsBuffer(); // History Buffer resources.indirectDiffuseHistory = indirectDiffuseHistory; resources.historyDepthBuffer = historyDepthBuffer; // Intermediate buffer resources.intermediateBuffer = intermediateBuffer; // In-output Buffer resources.inputOutputBuffer = inputOutputBuffer; return(resources); }
public void Denoise(CommandBuffer cmd, HDCamera hdCamera, RTHandle noisyBuffer, RTHandle outputBuffer, bool halfResolution = false, float historyValidity = 1.0f) { // Grab the global illumination volume component var giSettings = hdCamera.volumeStack.GetComponent <UnityEngine.Rendering.HighDefinition.GlobalIllumination>(); var historyDepthBuffer = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.Depth); var historyDepthBuffer1 = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.Depth1); // If the depth textures are not available, we can't denoise if (historyDepthBuffer == null || historyDepthBuffer1 == null) { HDUtils.BlitCameraTexture(cmd, noisyBuffer, outputBuffer); return; } // Compute the dispatch parameters based on if we are half res or not int tileSize = 8; int numTilesX, numTilesY; Vector4 halfScreenSize; EvaluateDispatchParameters(hdCamera, halfResolution, tileSize, out numTilesX, out numTilesY, out halfScreenSize); // Pick the right kernel to use int m_KernelFilter = halfResolution ? m_SpatialFilterHalfKernel : m_SpatialFilterKernel; // Bind the input scalars var info = m_SharedRTManager.GetDepthBufferMipChainInfo(); firstMipOffset.Set(HDShadowUtils.Asfloat((uint)info.mipLevelOffsets[1].x), HDShadowUtils.Asfloat((uint)info.mipLevelOffsets[1].y)); cmd.SetComputeVectorParam(m_SSGIDenoiserCS, HDShaderIDs._DepthPyramidFirstMipLevelOffset, firstMipOffset); cmd.SetComputeIntParam(m_SSGIDenoiserCS, HDShaderIDs._IndirectDiffuseSpatialFilter, giSettings.filterRadius); // Inject half screen size if required if (halfResolution) { cmd.SetComputeVectorParam(m_SSGIDenoiserCS, HDShaderIDs._HalfScreenSize, halfScreenSize); } // Bind the input buffers cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._DepthTexture, m_SharedRTManager.GetDepthTexture()); cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._InputNoisyBuffer, noisyBuffer); // Bind the output buffer cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._OutputFilteredBuffer, outputBuffer); // Do the spatial pass cmd.DispatchCompute(m_SSGIDenoiserCS, m_KernelFilter, numTilesX, numTilesY, hdCamera.viewCount); // Grab the history buffer RTHandle indirectDiffuseHistory = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.RaytracedIndirectDiffuseHF); if (indirectDiffuseHistory == null) { indirectDiffuseHistory = hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.RaytracedIndirectDiffuseHF, IndirectDiffuseHistoryBufferAllocatorFunction, 1); // clear it to black if this is the first pass to avoid nans CoreUtils.SetRenderTarget(cmd, indirectDiffuseHistory, ClearFlag.Color, clearColor: Color.black); } // Pick the right kernel to use m_KernelFilter = halfResolution ? m_TemporalFilterHalfKernel : m_TemporalFilterKernel; // Bind the input buffers cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._DepthTexture, m_SharedRTManager.GetDepthTexture()); cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._NormalBufferTexture, m_SharedRTManager.GetNormalBuffer()); cmd.SetComputeFloatParam(m_SSGIDenoiserCS, HDShaderIDs._HistoryValidity, historyValidity); if (halfResolution) { cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._HistoryDepthTexture, historyDepthBuffer1); cmd.SetComputeVectorParam(m_SSGIDenoiserCS, HDShaderIDs._DepthPyramidFirstMipLevelOffset, firstMipOffset); } else { cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._HistoryDepthTexture, historyDepthBuffer); } cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._HistoryBuffer, indirectDiffuseHistory); cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._InputNoisyBuffer, outputBuffer); // Bind the output buffer cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_KernelFilter, HDShaderIDs._OutputFilteredBuffer, noisyBuffer); // Do the temporal pass cmd.DispatchCompute(m_SSGIDenoiserCS, m_KernelFilter, numTilesX, numTilesY, hdCamera.viewCount); // Copy the new version into the history buffer cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_CopyHistory, HDShaderIDs._InputNoisyBuffer, noisyBuffer); cmd.SetComputeTextureParam(m_SSGIDenoiserCS, m_CopyHistory, HDShaderIDs._OutputFilteredBuffer, indirectDiffuseHistory); cmd.DispatchCompute(m_SSGIDenoiserCS, m_CopyHistory, numTilesX, numTilesY, hdCamera.viewCount); }