Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added marker for all AOV request operation on GPU
- Added remapping options for Depth Pyramid debug view mode
- Added an option to support AOV shader at runtime in HDRP settings (case 1265070)
- Supporting SSGI in the render graph mode.

### Fixed
- Fix when rescale probe all direction below zero (1219246)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.RenderGraphModule;

namespace UnityEngine.Rendering.HighDefinition
{
public partial class HDRenderPipeline
{
class TraceSSGIPassData
{
public SSGITraceParameters parameters;
public TextureHandle depthTexture;
public TextureHandle normalBuffer;
public TextureHandle motionVectorsBuffer;
public TextureHandle colorPyramid;
public TextureHandle historyDepth;
public TextureHandle hitPointBuffer;
public TextureHandle outputBuffer;
}

TextureHandle TraceSSGI(RenderGraph renderGraph, HDCamera hdCamera, GlobalIllumination giSettings, TextureHandle depthPyramid, TextureHandle normalBuffer, TextureHandle motionVectorsBuffer)
{
using (var builder = renderGraph.AddRenderPass<TraceSSGIPassData>("Trace SSGI", out var passData, ProfilingSampler.Get(HDProfileId.SSGITrace)))
{
builder.EnableAsyncCompute(false);

passData.parameters = PrepareSSGITraceParameters(hdCamera, giSettings);
passData.depthTexture = builder.ReadTexture(depthPyramid);
passData.normalBuffer = builder.ReadTexture(normalBuffer);
passData.motionVectorsBuffer = builder.ReadTexture(motionVectorsBuffer);
var colorPyramid = hdCamera.GetPreviousFrameRT((int)HDCameraFrameHistoryType.ColorBufferMipChain);
passData.colorPyramid = colorPyramid != null ? builder.ReadTexture(renderGraph.ImportTexture(colorPyramid)) : renderGraph.defaultResources.blackTextureXR;
var historyDepth = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.Depth);
passData.historyDepth = historyDepth != null ? builder.ReadTexture(renderGraph.ImportTexture(historyDepth)) : renderGraph.defaultResources.blackTextureXR;
passData.hitPointBuffer = builder.CreateTransientTexture(new TextureDesc(Vector2.one, true, true)
{ colorFormat = GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite = true, name = "SSGI Hit Point"});
passData.outputBuffer = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true)
{ colorFormat = GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite = true, name = "SSGI Signal"}));

builder.SetRenderFunc(
(TraceSSGIPassData data, RenderGraphContext ctx) =>
{
// We need to fill the structure that holds the various resources
SSGITraceResources resources = new SSGITraceResources();
resources.depthTexture = data.depthTexture;
resources.normalBuffer = data.normalBuffer;
resources.motionVectorsBuffer = data.motionVectorsBuffer;
resources.colorPyramid = data.colorPyramid;
resources.historyDepth = data.historyDepth;
resources.hitPointBuffer = data.hitPointBuffer;
resources.outputBuffer = data.outputBuffer;
ExecuteSSGITrace(ctx.cmd, data.parameters, resources);
});
return passData.outputBuffer;
}
}

class UpscaleSSGIPassData
{
public SSGIUpscaleParameters parameters;
public TextureHandle depthTexture;
public TextureHandle inputBuffer;
public TextureHandle outputBuffer;
}

TextureHandle UpscaleSSGI(RenderGraph renderGraph, HDCamera hdCamera, GlobalIllumination giSettings, 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); ;
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;
}
}

TextureHandle RenderSSGI(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthPyramid, TextureHandle normalBuffer, TextureHandle motionVectorsBuffer, ShaderVariablesRaytracing shaderVariablesRayTracingCB)
{
// Grab the global illumination volume component
GlobalIllumination giSettings = hdCamera.volumeStack.GetComponent<GlobalIllumination>();

using (new RenderGraphProfilingScope(renderGraph, ProfilingSampler.Get(HDProfileId.SSGIPass)))
{
// Trace the signal
TextureHandle colorBuffer = TraceSSGI(renderGraph, hdCamera, giSettings, depthPyramid, normalBuffer, motionVectorsBuffer);

// Denoise the signal
float historyValidity = EvaluateHistoryValidity(hdCamera);
SSGIDenoiser ssgiDenoiser = GetSSGIDenoiser();
ssgiDenoiser.Denoise(renderGraph, hdCamera, depthPyramid, normalBuffer, motionVectorsBuffer, colorBuffer, !giSettings.fullResolutionSS, historyValidity: historyValidity);

// Upscale it if required
// If this was a half resolution effect, we still have to upscale it
if (!giSettings.fullResolutionSS)
colorBuffer = UpscaleSSGI(renderGraph, hdCamera, giSettings, depthPyramid, colorBuffer);
return colorBuffer;
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading