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 @@ -55,6 +55,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added controls for the users to manually feed the ray tracing acceleration structure that should be used for a given camera (case 1370678).
- Depth of Field is now disabled in orthographic cameras - it was using the hidden perspective settings (case 1372582).
- Modified HDRP to use common FSR logic from SRP core.
- Optimized FSR by merging the RCAS logic into the FinalPass shader.

## [13.1.0] - 2021-09-24

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Shader "Hidden/HDRP/FinalPass"
#pragma multi_compile_local_fragment _ APPLY_AFTER_POST
#pragma multi_compile_local _ HDR_OUTPUT_REC2020 HDR_OUTPUT_SCRGB

#pragma multi_compile_local_fragment _ CATMULL_ROM_4 BYPASS
#pragma multi_compile_local_fragment _ CATMULL_ROM_4 RCAS BYPASS
#define DEBUG_UPSCALE_POINT 0

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
Expand All @@ -38,6 +38,15 @@ Shader "Hidden/HDRP/FinalPass"
SAMPLER(sampler_LinearClamp);
SAMPLER(sampler_LinearRepeat);

#define FSR_INPUT_TEXTURE _InputTexture
#define FSR_INPUT_SAMPLER s_linear_clamp_sampler
#if ENABLE_ALPHA
// When alpha is in use, activate the alpha-passthrough mode in the RCAS implementation.
// When this mode is active, ApplyRCAS returns a four component vector (rgba) instead of a three component vector (rgb).
#define FSR_ENABLE_ALPHA 1
#endif
#include "Packages/com.unity.render-pipelines.core/Runtime/PostProcessing/Shaders/FSRCommon.hlsl"

float2 _GrainParams; // x: intensity, y: response
float4 _GrainTextureParams; // xy: _ScreenSize.xy / GrainTextureSize.xy, zw: (random offset in UVs) * _GrainTextureParams.xy
float3 _DitherParams; // xy: _ScreenSize.xy / DitherTextureSize.xy, z: texture_id
Expand Down Expand Up @@ -95,15 +104,18 @@ Shader "Hidden/HDRP/FinalPass"

float2 positionNDC = input.texcoord;
uint2 positionSS = input.texcoord * _ScreenSize.xy;
uint2 scaledPositionSS = ((input.texcoord.xy * _UVTransform.xy) + _UVTransform.zw) * _ViewPortSize.xy;

// Flip logic
positionSS = positionSS * _UVTransform.xy + _UVTransform.zw * (_ScreenSize.xy - 1.0);
positionNDC = positionNDC * _UVTransform.xy + _UVTransform.zw;

#ifdef CATMULL_ROM_4
CTYPE outColor = UpscaledResult(positionNDC.xy);
#elif defined(RCAS)
CTYPE outColor = ApplyRCAS(scaledPositionSS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ApplyRCAS returns a float3, yet you have a CTYPE. This means that you could potentially be setting alpha 0 and causing a shader compiler warning (float3 casted into float4).

Notice how the other passes use the CTYPE_SWIZZE to address this. Can you dig in a bit into support for alpha? I think this might break this pass.

Copy link
Contributor Author

@gmitrano-unity gmitrano-unity Nov 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a new commit that adds some comments explaining how this is handled:

#define FSR_INPUT_TEXTURE _InputTexture
#define FSR_INPUT_SAMPLER s_linear_clamp_sampler
#if ENABLE_ALPHA
// When alpha is in use, activate the alpha-passthrough mode in the RCAS implementation.
// When this mode is active, ApplyRCAS returns a four component vector (rgba) instead of a three component vector (rgb).
#define FSR_ENABLE_ALPHA 1
#endif
#include "Packages/com.unity.render-pipelines.core/Runtime/PostProcessing/Shaders/FSRCommon.hlsl"

Any idea if this functionality is tested in the DRS tests?

#elif defined(BYPASS)
CTYPE outColor = LOAD_TEXTURE2D_X(_InputTexture, ((input.texcoord.xy * _UVTransform.xy) + _UVTransform.zw) * _ViewPortSize.xy).CTYPE_SWIZZLE;
CTYPE outColor = LOAD_TEXTURE2D_X(_InputTexture, scaledPositionSS).CTYPE_SWIZZLE;
#else
CTYPE outColor = LOAD_TEXTURE2D_X(_InputTexture, positionSS).CTYPE_SWIZZLE;
#endif
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ internal enum HDProfileId
CustomPostProcessAfterPP,
CustomPostProcessAfterOpaqueAndSky,
ContrastAdaptiveSharpen,
RobustContrastAdaptiveSharpen,
EdgeAdaptiveSpatialUpsampling,
PrepareProbeVolumeList,
ProbeVolumeDebug,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@ TextureHandle RenderPostProcess(RenderGraph renderGraph,
// AMD Fidelity FX passes
source = ContrastAdaptiveSharpeningPass(renderGraph, hdCamera, source);
source = EdgeAdaptiveSpatialUpsampling(renderGraph, hdCamera, source);
source = RobustContrastAdaptiveSharpeningPass(renderGraph, hdCamera, source);
}

FinalPass(renderGraph, hdCamera, afterPostProcessBuffer, alphaTexture, dest, source, uiBuffer, m_BlueNoise, flipYInPostProcess);
Expand Down Expand Up @@ -4755,58 +4754,6 @@ TextureHandle ContrastAdaptiveSharpeningPass(RenderGraph renderGraph, HDCamera h

#endregion

#region RCAS
class RCASData
{
public ComputeShader rcasCS;
public int mainKernel;
public int viewCount;
public int outputWidth;
public int outputHeight;

public TextureHandle source;
public TextureHandle destination;
}

TextureHandle RobustContrastAdaptiveSharpeningPass(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle source)
{
if (hdCamera.DynResRequest.enabled && hdCamera.DynResRequest.filter == DynamicResUpscaleFilter.EdgeAdaptiveScalingUpres)
{
using (var builder = renderGraph.AddRenderPass<RCASData>("Robust Contrast Adaptive Sharpen", out var passData, ProfilingSampler.Get(HDProfileId.RobustContrastAdaptiveSharpen)))
{
passData.rcasCS = defaultResources.shaders.robustContrastAdaptiveSharpenCS;
if (PostProcessEnableAlpha())
passData.rcasCS.EnableKeyword("ENABLE_ALPHA");
else
passData.rcasCS.DisableKeyword("ENABLE_ALPHA");
passData.mainKernel = passData.rcasCS.FindKernel("KMain");
passData.viewCount = hdCamera.viewCount;
passData.outputWidth = Mathf.RoundToInt(hdCamera.finalViewport.width);
passData.outputHeight = Mathf.RoundToInt(hdCamera.finalViewport.height);
passData.source = builder.ReadTexture(source);
passData.destination = builder.WriteTexture(GetPostprocessUpsampledOutputHandle(renderGraph, "Robust Contrast Adaptive Sharpen Destination"));

builder.SetRenderFunc(
(RCASData data, RenderGraphContext ctx) =>
{
FSRUtils.SetRcasConstants(ctx.cmd);
ctx.cmd.SetComputeTextureParam(data.rcasCS, data.mainKernel, HDShaderIDs._InputTexture, data.source);
ctx.cmd.SetComputeTextureParam(data.rcasCS, data.mainKernel, HDShaderIDs._OutputTexture, data.destination);

int dispatchX = HDUtils.DivRoundUp(data.outputWidth, 8);
int dispatchY = HDUtils.DivRoundUp(data.outputHeight, 8);

ctx.cmd.DispatchCompute(data.rcasCS, data.mainKernel, dispatchX, dispatchY, data.viewCount);
});

source = passData.destination;
}
}
return source;
}

#endregion

#region EASU
class EASUData
{
Expand Down Expand Up @@ -4976,9 +4923,15 @@ void FinalPass(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle afterPo
finalPassMaterial.EnableKeyword("CATMULL_ROM_4");
break;
case DynamicResUpscaleFilter.ContrastAdaptiveSharpen:
case DynamicResUpscaleFilter.EdgeAdaptiveScalingUpres:
finalPassMaterial.EnableKeyword("BYPASS");
break;
case DynamicResUpscaleFilter.EdgeAdaptiveScalingUpres:
// The RCAS half of the FSR technique (EASU + RCAS) is merged into FinalPass instead of
// running it inside a separate compute shader. This allows us to avoid an additional
// round-trip through memory which improves performance.
finalPassMaterial.EnableKeyword("RCAS");
FSRUtils.SetRcasConstants(ctx.cmd);
break;
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,6 @@ public sealed class ShaderResources

[Reload("Runtime/PostProcessing/Shaders/ContrastAdaptiveSharpen.compute")]
public ComputeShader contrastAdaptiveSharpenCS;
[Reload("Runtime/PostProcessing/Shaders/RobustContrastAdaptiveSharpen.compute")]
public ComputeShader robustContrastAdaptiveSharpenCS;
[Reload("Runtime/PostProcessing/Shaders/EdgeAdaptiveSpatialUpsampling.compute")]
public ComputeShader edgeAdaptiveSpatialUpsamplingCS;
[Reload("Runtime/VirtualTexturing/Shaders/DownsampleVTFeedback.compute")]
Expand Down