Skip to content

Commit cda5bf6

Browse files
CalChiuEvergreen
authored andcommitted
[Port] [6000.4] [UUM-136528] Fixed Nearest-Neighbor upscaling dependency on final post-process pass
1 parent dde0082 commit cda5bf6

3 files changed

Lines changed: 44 additions & 4 deletions

File tree

Packages/com.unity.render-pipelines.universal/Runtime/Passes/PostProcess/UberPostProcessPass.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ internal sealed class UberPostProcessPass : PostProcessPass
99
Material m_Material;
1010
Texture2D[] m_FilmGrainTextures;
1111

12+
public enum FilteringOperation
13+
{
14+
Linear,
15+
Point
16+
}
17+
1218
Texture m_DitherTexture;
1319
RTHandle m_UserLut;
20+
FilteringOperation m_FilteringOperation;
1421
HDROutputUtils.Operation m_HdrOperations;
1522
bool m_IsValid;
1623
bool m_IsFinalPass;
@@ -36,13 +43,15 @@ public override void Dispose()
3643
}
3744

3845
public void Setup(Texture ditherTexture,
46+
FilteringOperation filteringOperation,
3947
HDROutputUtils.Operation hdrOperations,
4048
bool requireSRGBConversionBlit,
4149
bool useFastSRGBLinearConversion,
4250
bool isFinalPass,
4351
bool renderOverlayUI)
4452
{
4553
m_DitherTexture = ditherTexture;
54+
m_FilteringOperation = filteringOperation;
4655
m_HdrOperations = hdrOperations;
4756
m_RequireSRGBConversionBlit = requireSRGBConversionBlit;
4857
m_UseFastSRGBLinearConversion = useFastSRGBLinearConversion;
@@ -60,6 +69,7 @@ private class UberPostPassData
6069
internal UniversalCameraData cameraData;
6170

6271
internal Tonemapping tonemapping;
72+
internal FilteringOperation filteringOperation;
6373
internal HDROutputUtils.Operation hdrOperations;
6474
internal bool isHdrGrading;
6575

@@ -162,6 +172,7 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
162172

163173
// HDR
164174
passData.tonemapping = tonemapping;
175+
passData.filteringOperation = m_FilteringOperation;
165176
passData.hdrOperations = m_HdrOperations;
166177
passData.isHdrGrading = postProcessingData.gradingMode == ColorGradingMode.HighDynamicRange;
167178

@@ -184,11 +195,22 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
184195
var cmd = context.cmd;
185196
var cameraData = data.cameraData;
186197
var material = data.material;
198+
var filteringOperation = data.filteringOperation;
187199
RTHandle sourceTextureHdl = data.sourceTexture;
188200

189201
// Reset keywords
190202
material.shaderKeywords = null;
191203

204+
switch (filteringOperation)
205+
{
206+
case FilteringOperation.Point:
207+
material.EnableKeyword(ShaderKeywordStrings.PointSampling);
208+
break;
209+
case FilteringOperation.Linear: goto default;
210+
default:
211+
break;
212+
}
213+
192214
data.lut.Apply(material);
193215

194216
if (data.bloom.IsActive())

Packages/com.unity.render-pipelines.universal/Runtime/PostProcess.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,16 @@ public void RenderPostProcessing(RenderGraph renderGraph, ContextContainer frame
299299
hdrOperations = !hasFinalPass && enableColorEncodingIfNeeded ? HDROutputUtils.Operation.ColorEncoding : HDROutputUtils.Operation.None;
300300
}
301301

302+
UberPostProcessPass.FilteringOperation filteringOperation = UberPostProcessPass.FilteringOperation.Linear;
303+
304+
// Point sampling is only used for upscaling so the default linear sampler should be used if there is a final pass
305+
if (cameraData.imageScalingMode == ImageScalingMode.Upscaling && !hasFinalPass && cameraData.upscalingFilter == ImageUpscalingFilter.Point)
306+
{
307+
filteringOperation = UberPostProcessPass.FilteringOperation.Point;
308+
}
309+
302310
bool renderOverlayUI = requireHDROutput && enableColorEncodingIfNeeded && resourceData.overlayUITexture.IsValid();
303-
m_UberPass.Setup(ditherTexture, hdrOperations, applySrgbEncoding, useFastSRGBLinearConversion, !hasFinalPass, renderOverlayUI);
311+
m_UberPass.Setup(ditherTexture, filteringOperation, hdrOperations, applySrgbEncoding, useFastSRGBLinearConversion, !hasFinalPass, renderOverlayUI);
304312
m_UberPass.RecordRenderGraph(renderGraph, frameData);
305313
}
306314
}

Packages/com.unity.render-pipelines.universal/Shaders/PostProcessing/UberPost.shader

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Shader "Hidden/Universal Render Pipeline/UberPost"
22
{
33
HLSLINCLUDE
4+
#pragma multi_compile_local_fragment _ _POINT_SAMPLING
45
#pragma multi_compile_local_fragment _ _DISTORTION
56
#pragma multi_compile_local_fragment _ _CHROMATIC_ABERRATION
67
#pragma multi_compile_local_fragment _ _BLOOM_LQ _BLOOM_HQ _BLOOM_LQ_DIRT _BLOOM_HQ_DIRT
@@ -146,6 +147,15 @@ Shader "Hidden/Universal Render Pipeline/UberPost"
146147
return uv;
147148
}
148149

150+
half4 SampleColor(float2 uv)
151+
{
152+
#if _POINT_SAMPLING
153+
return SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_PointClamp, uv);
154+
#else
155+
return SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv);
156+
#endif
157+
}
158+
149159
half4 FragUberPost(Varyings input) : SV_Target
150160
{
151161
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
@@ -155,7 +165,7 @@ Shader "Hidden/Universal Render Pipeline/UberPost"
155165

156166
// NOTE: Hlsl specifies missing input.a to fill 1 (0 for .rgb).
157167
// InputColor is a "bottom" layer for alpha output.
158-
half4 inputColor = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, ClampUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS(uvDistorted), _BlitTexture_TexelSize.xy));
168+
half4 inputColor = SampleColor(ClampUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS(uvDistorted), _BlitTexture_TexelSize.xy));
159169
half3 color = inputColor.rgb;
160170

161171
#if _CHROMATIC_ABERRATION
@@ -167,8 +177,8 @@ Shader "Hidden/Universal Render Pipeline/UberPost"
167177
float2 delta = (end - uv) / 3.0;
168178

169179
half r = color.r;
170-
half g = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, ClampUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS(DistortUV(delta + uv) ), _BlitTexture_TexelSize.xy)).y;
171-
half b = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, ClampUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS(DistortUV(delta * 2.0 + uv)), _BlitTexture_TexelSize.xy)).z;
180+
half g = SampleColor(ClampUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS(DistortUV(delta + uv) ), _BlitTexture_TexelSize.xy)).y;
181+
half b = SampleColor(ClampUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS(DistortUV(delta * 2.0 + uv)), _BlitTexture_TexelSize.xy)).z;
172182

173183
color = half3(r, g, b);
174184
}

0 commit comments

Comments
 (0)