Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -598,6 +598,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Changed a few resources used by ray tracing shaders to be global resources (using register space1) for improved CPU performance.
- All custom pass volumes are now executed for one injection point instead of the first one.
- Hidden unsupported choice in emission in Materials
- Avoid building the mip chain a second time for SSR for transparent objects.

## [7.1.1] - 2019-09-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#pragma kernel ScreenSpaceReflectionsTracing SSR_TRACE
#pragma kernel ScreenSpaceReflectionsReprojection SSR_REPROJECT

#pragma multi_compile _ DEPTH_SOURCE_NOT_FROM_MIP_CHAIN

// Tweak parameters.
// #define DEBUG
#define SSR_TRACE_BEHIND_OBJECTS
Expand Down Expand Up @@ -40,6 +42,12 @@
RW_TEXTURE2D(float4, _SsrDebugTexture);
#endif

// Given that for transparent objects we do not trace in a depth buffer that contains them
// we need a seperate texture for the mip chain and for the depth source
#ifdef DEPTH_SOURCE_NOT_FROM_MIP_CHAIN
TEXTURE2D_X(_DepthTexture);
#endif

#ifdef SSR_TRACE
TEXTURE2D_X_UINT2( _StencilTexture);
RW_TEXTURE2D_X(float2, _SsrHitPointTexture);
Expand Down Expand Up @@ -121,7 +129,12 @@ void ScreenSpaceReflectionsTracing(uint3 groupId : SV_GroupID,
}

float2 positionNDC = positionSS * _ScreenSize.zw + (0.5 * _ScreenSize.zw); // Should we precompute the half-texel bias? We seem to use it a lot.

#ifdef DEPTH_SOURCE_NOT_FROM_MIP_CHAIN
float deviceDepth = LOAD_TEXTURE2D_X(_DepthTexture, positionSS).r;
#else
float deviceDepth = LOAD_TEXTURE2D_X(_CameraDepthTexture, positionSS).r;
#endif

bool killRay = deviceDepth == UNITY_RAW_FAR_CLIP_VALUE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ LightingOutput RenderDeferredLighting( RenderGraph renderGraph,
class RenderSSRPassData
{
public RenderSSRParameters parameters;
public TextureHandle depthBuffer;
public TextureHandle depthPyramid;
public TextureHandle colorPyramid;
public TextureHandle stencilBuffer;
Expand All @@ -254,6 +255,7 @@ TextureHandle RenderSSR( RenderGraph renderGraph,
HDCamera hdCamera,
TextureHandle normalBuffer,
TextureHandle motionVectorsBuffer,
TextureHandle depthBuffer,
TextureHandle depthPyramid,
TextureHandle stencilBuffer,
TextureHandle clearCoatMask)
Expand Down Expand Up @@ -282,7 +284,8 @@ TextureHandle RenderSSR( RenderGraph renderGraph,

var colorPyramid = renderGraph.ImportTexture(hdCamera.GetPreviousFrameRT((int)HDCameraFrameHistoryType.ColorBufferMipChain));

passData.parameters = PrepareSSRParameters(hdCamera);
passData.parameters = PrepareSSRParameters(hdCamera, true);
passData.depthBuffer = builder.ReadTexture(depthBuffer);
passData.depthPyramid = builder.ReadTexture(depthPyramid);
passData.colorPyramid = builder.ReadTexture(colorPyramid);
passData.stencilBuffer = builder.ReadTexture(stencilBuffer);
Expand All @@ -305,6 +308,7 @@ TextureHandle RenderSSR( RenderGraph renderGraph,
{
var res = context.resources;
RenderSSR(data.parameters,
res.GetTexture(data.depthBuffer),
res.GetTexture(data.depthPyramid),
res.GetTexture(data.hitPointsTexture),
res.GetTexture(data.stencilBuffer),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void ExecuteWithRenderGraph( RenderRequest renderRequest,
hdCamera,
prepassOutput.resolvedNormalBuffer,
prepassOutput.resolvedMotionVectorsBuffer,
prepassOutput.depthBuffer,
prepassOutput.depthPyramidTexture,
prepassOutput.stencilBuffer,
clearCoatMask);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3750,6 +3750,7 @@ struct RenderSSRParameters
public ComputeShader ssrCS;
public int tracingKernel;
public int reprojectionKernel;
public bool transparentSSR;

public int width, height, viewCount;
public int maxIteration;
Expand All @@ -3769,14 +3770,15 @@ struct RenderSSRParameters
public int colorPyramidMipCount;
}

RenderSSRParameters PrepareSSRParameters(HDCamera hdCamera)
RenderSSRParameters PrepareSSRParameters(HDCamera hdCamera, bool transparentSSR)
{
var volumeSettings = hdCamera.volumeStack.GetComponent<ScreenSpaceReflection>();
var parameters = new RenderSSRParameters();

parameters.ssrCS = m_ScreenSpaceReflectionsCS;
parameters.tracingKernel = m_SsrTracingKernel;
parameters.reprojectionKernel = m_SsrReprojectionKernel;
parameters.transparentSSR = transparentSSR;

parameters.width = hdCamera.actualWidth;
parameters.height = hdCamera.actualHeight;
Expand Down Expand Up @@ -3811,6 +3813,7 @@ RenderSSRParameters PrepareSSRParameters(HDCamera hdCamera)
}

static void RenderSSR( in RenderSSRParameters parameters,
RTHandle depthTexture,
RTHandle depthPyramid,
RTHandle SsrHitPointTexture,
RTHandle stencilBuffer,
Expand All @@ -3836,6 +3839,12 @@ static void RenderSSR( in RenderSSRParameters parameters,
cmd.SetComputeIntParam(cs, HDShaderIDs._SsrStencilBit, (int)StencilUsage.TraceReflectionRay);

// cmd.SetComputeTextureParam(cs, kernel, "_SsrDebugTexture", m_SsrDebugTexture);
// Bind the non mip chain if we are rendering the transaprent version
if (parameters.transparentSSR)
{
CoreUtils.SetKeyword(cmd, "DEPTH_SOURCE_NOT_FROM_MIP_CHAIN", true);
cmd.SetComputeTextureParam(cs, parameters.tracingKernel, HDShaderIDs._DepthTexture, depthTexture);
}
cmd.SetComputeTextureParam(cs, parameters.tracingKernel, HDShaderIDs._CameraDepthTexture, depthPyramid);
cmd.SetComputeTextureParam(cs, parameters.tracingKernel, HDShaderIDs._SsrClearCoatMaskTexture, clearCoatMask);
cmd.SetComputeTextureParam(cs, parameters.tracingKernel, HDShaderIDs._SsrHitPointTexture, SsrHitPointTexture);
Expand All @@ -3854,6 +3863,9 @@ static void RenderSSR( in RenderSSRParameters parameters,
cmd.SetComputeBufferParam(cs, parameters.tracingKernel, HDShaderIDs._DepthPyramidMipLevelOffsets, parameters.offsetBufferData);

cmd.DispatchCompute(cs, parameters.tracingKernel, HDUtils.DivRoundUp(parameters.width, 8), HDUtils.DivRoundUp(parameters.height, 8), parameters.viewCount);

if (parameters.transparentSSR)
CoreUtils.SetKeyword(cmd, "DEPTH_SOURCE_NOT_FROM_MIP_CHAIN", false);
}

using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.SsrReprojection)))
Expand Down Expand Up @@ -3889,8 +3901,8 @@ void RenderSSR(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext ren
// Evaluate the clear coat mask texture based on the lit shader mode
RTHandle clearCoatMask = hdCamera.frameSettings.litShaderMode == LitShaderMode.Deferred ? m_GbufferManager.GetBuffer(2) : TextureXR.GetBlackTexture();

var parameters = PrepareSSRParameters(hdCamera);
RenderSSR(parameters, m_SharedRTManager.GetDepthTexture(), m_SsrHitPointTexture,
var parameters = PrepareSSRParameters(hdCamera, false);
RenderSSR(parameters, m_SharedRTManager.GetDepthStencilBuffer(), m_SharedRTManager.GetDepthTexture(), m_SsrHitPointTexture,
m_SharedRTManager.GetStencilBuffer(hdCamera.frameSettings.IsEnabled(FrameSettingsField.MSAA)), clearCoatMask, previousColorPyramid,
m_SsrLightingTexture, cmd, renderContext);

Expand Down Expand Up @@ -3919,16 +3931,12 @@ void RenderSSRTransparent(HDCamera hdCamera, CommandBuffer cmd, ScriptableRender
// Clear the SSR lighting buffer (not sure it is required)
CoreUtils.SetRenderTarget(cmd, m_SsrLightingTexture, ClearFlag.Color, Color.clear);
CoreUtils.SetRenderTarget(cmd, m_SsrHitPointTexture, ClearFlag.Color, Color.clear);

// Invalid the depth pyramid and regenerate the depth pyramid
m_IsDepthBufferCopyValid = false;
GenerateDepthPyramid(hdCamera, cmd, FullScreenDebugMode.DepthPyramid);
}

// Evaluate the screen space reflection for the transparent pixels
var previousColorPyramid = hdCamera.GetPreviousFrameRT((int)HDCameraFrameHistoryType.ColorBufferMipChain);
var parameters = PrepareSSRParameters(hdCamera);
RenderSSR(parameters, m_SharedRTManager.GetDepthTexture(), m_SsrHitPointTexture, m_SharedRTManager.GetStencilBuffer(), TextureXR.GetBlackTexture(), previousColorPyramid, m_SsrLightingTexture, cmd, renderContext);
var parameters = PrepareSSRParameters(hdCamera, true);
RenderSSR(parameters, m_SharedRTManager.GetDepthStencilBuffer(), m_SharedRTManager.GetDepthTexture(), m_SsrHitPointTexture, m_SharedRTManager.GetStencilBuffer(), TextureXR.GetBlackTexture(), previousColorPyramid, m_SsrLightingTexture, cmd, renderContext);

// If color pyramid was not valid, we bind a black texture
if (!hdCamera.colorPyramidHistoryIsValid)
Expand Down