TextureHandle UpscaleSSGI(RenderGraph renderGraph, HDCamera hdCamera, GlobalIllumination giSettings, HDUtils.PackedMipChainInfo info, TextureHandle depthPyramid, TextureHandle inputBuffer) { using (var builder = renderGraph.AddRenderPass <UpscaleSSGIPassData>("Upscale SSGI", out var passData, ProfilingSampler.Get(HDProfileId.SSGIUpscale))) { builder.EnableAsyncCompute(false); passData.parameters = PrepareSSGIUpscaleParameters(hdCamera, giSettings, info); passData.depthTexture = builder.ReadTexture(depthPyramid); passData.inputBuffer = builder.ReadTexture(inputBuffer); passData.outputBuffer = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite = true, name = "SSGI Final" })); builder.SetRenderFunc( (UpscaleSSGIPassData data, RenderGraphContext ctx) => { // We need to fill the structure that holds the various resources SSGIUpscaleResources resources = new SSGIUpscaleResources(); resources.depthTexture = data.depthTexture; resources.inputBuffer = data.inputBuffer; resources.outputBuffer = data.outputBuffer; ExecuteSSGIUpscale(ctx.cmd, data.parameters, resources); }); return(passData.outputBuffer); } }
void RenderSSGI(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext renderContext, int frameCount) { // Grab the global illumination volume component GlobalIllumination giSettings = hdCamera.volumeStack.GetComponent <GlobalIllumination>(); // Based on if we are doing it in half resolution or full, we need to define initial and final buffer to avoid a useless blit RTHandle buffer0, buffer1; if (giSettings.fullResolutionSS) { buffer0 = m_IndirectDiffuseBuffer0; buffer1 = m_IndirectDiffuseBuffer1; } else { buffer0 = m_IndirectDiffuseBuffer1; buffer1 = m_IndirectDiffuseBuffer0; } using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.SSGIPass))) { // Trace the signal using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.SSGITrace))) { SSGITraceParameters parameters = PrepareSSGITraceParameters(hdCamera, giSettings); SSGITraceResources resources = PrepareSSGITraceResources(hdCamera, buffer0, m_IndirectDiffuseHitPointBuffer); ExecuteSSGITrace(cmd, parameters, resources); } // Denoise it using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.SSGIDenoise))) { float historyValidity = EvaluateHistoryValidity(hdCamera); SSGIDenoiser ssgiDenoiser = GetSSGIDenoiser(); ssgiDenoiser.Denoise(cmd, hdCamera, buffer0, buffer1, halfResolution: !giSettings.fullResolutionSS, historyValidity: historyValidity); } // Upscale it if required // If this was a half resolution effect, we still have to upscale it if (!giSettings.fullResolutionSS) { using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.SSGIUpscale))) { ComputeShader bilateralUpsampleCS = m_Asset.renderPipelineResources.shaders.bilateralUpsampleCS; SSGIUpscaleParameters parameters = PrepareSSGIUpscaleParameters(hdCamera, giSettings); SSGIUpscaleResources resources = PrepareSSGIUpscaleResources(hdCamera, buffer0, buffer1); ExecuteSSGIUpscale(cmd, parameters, resources); } } (RenderPipelineManager.currentPipeline as HDRenderPipeline).PushFullScreenDebugTexture(hdCamera, cmd, m_IndirectDiffuseBuffer0, FullScreenDebugMode.ScreenSpaceGlobalIllumination); } }
SSGIUpscaleResources PrepareSSGIUpscaleResources(HDCamera hdCamera, RTHandle inputBuffer, RTHandle outputBuffer) { SSGIUpscaleResources ssgiUpscaleResources = new SSGIUpscaleResources(); // Input buffers ssgiUpscaleResources.depthTexture = m_SharedRTManager.GetDepthTexture(); ssgiUpscaleResources.inputBuffer = inputBuffer; // Output buffers ssgiUpscaleResources.outputBuffer = outputBuffer; return(ssgiUpscaleResources); }
static void ExecuteSSGIUpscale(CommandBuffer cmd, SSGIUpscaleParameters parameters, SSGIUpscaleResources resources) { // Re-evaluate the dispatch parameters (we are evaluating the upsample in full resolution) int ssgiTileSize = 8; int numTilesXHR = (parameters.texWidth + (ssgiTileSize - 1)) / ssgiTileSize; int numTilesYHR = (parameters.texHeight + (ssgiTileSize - 1)) / ssgiTileSize; // Inject the input scalars cmd.SetComputeVectorParam(parameters.bilateralUpsampleCS, HDShaderIDs._HalfScreenSize, parameters.halfScreenSize); cmd.SetComputeVectorParam(parameters.bilateralUpsampleCS, HDShaderIDs._DepthPyramidFirstMipLevelOffset, parameters.firstMipOffset); // Inject all the input buffers cmd.SetComputeTextureParam(parameters.bilateralUpsampleCS, parameters.upscaleKernel, HDShaderIDs._DepthTexture, resources.depthTexture); cmd.SetComputeTextureParam(parameters.bilateralUpsampleCS, parameters.upscaleKernel, HDShaderIDs._LowResolutionTexture, resources.inputBuffer); // Inject the output textures cmd.SetComputeTextureParam(parameters.bilateralUpsampleCS, parameters.upscaleKernel, HDShaderIDs._OutputUpscaledTexture, resources.outputBuffer); // Upscale the buffer to full resolution cmd.DispatchCompute(parameters.bilateralUpsampleCS, parameters.upscaleKernel, numTilesXHR, numTilesYHR, parameters.viewCount); }