Skip to content

Commit 009a380

Browse files
svc-reach-platform-supportEvergreen
authored andcommitted
[Port] [6000.5] [UUM-136528] Fixed Nearest-Neighbor upscaling dependency on final post-process pass
1 parent 1ddd619 commit 009a380

3 files changed

Lines changed: 55 additions & 4 deletions

File tree

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

Lines changed: 23 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;
@@ -28,6 +35,7 @@ public UberPostProcessPass(Shader shader, Texture2D[] filmGrainTextures)
2835

2936
// Defaults
3037
m_DitherTexture = null; // Dither disabled.
38+
m_FilteringOperation = FilteringOperation.Linear; // Common case.
3139
m_HdrOperations = HDROutputUtils.Operation.None; // HDR disabled.
3240
m_RequireSRGBConversionBlit = false; // sRGB conversion is typically automatic based on format.
3341
m_IsFinalPass = false; // Assume other passes.
@@ -42,12 +50,14 @@ public override void Dispose()
4250
}
4351

4452
public void Setup(Texture ditherTexture,
53+
FilteringOperation filteringOperation,
4554
HDROutputUtils.Operation hdrOperations,
4655
bool requireSRGBConversionBlit,
4756
bool isFinalPass,
4857
bool renderOverlayUI)
4958
{
5059
m_DitherTexture = ditherTexture;
60+
m_FilteringOperation = filteringOperation;
5161
m_HdrOperations = hdrOperations;
5262
m_RequireSRGBConversionBlit = requireSRGBConversionBlit;
5363
m_IsFinalPass = isFinalPass;
@@ -64,6 +74,7 @@ private class UberPostPassData
6474
internal UniversalCameraData cameraData;
6575

6676
internal Tonemapping tonemapping;
77+
internal FilteringOperation filteringOperation;
6778
internal HDROutputUtils.Operation hdrOperations;
6879
internal bool isHdrGrading;
6980

@@ -166,6 +177,7 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
166177

167178
// HDR
168179
passData.tonemapping = tonemapping;
180+
passData.filteringOperation = m_FilteringOperation;
169181
passData.hdrOperations = m_HdrOperations;
170182
passData.isHdrGrading = postProcessingData.gradingMode == ColorGradingMode.HighDynamicRange;
171183

@@ -187,10 +199,21 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
187199
{
188200
var cameraData = data.cameraData;
189201
var material = data.material;
202+
var filteringOperation = data.filteringOperation;
190203

191204
// Reset keywords
192205
material.shaderKeywords = null;
193206

207+
switch (filteringOperation)
208+
{
209+
case FilteringOperation.Point:
210+
material.EnableKeyword(ShaderKeywordStrings.PointSampling);
211+
break;
212+
case FilteringOperation.Linear: goto default;
213+
default:
214+
break;
215+
}
216+
194217
data.lut.Apply(material);
195218

196219
if (data.bloom.IsActive())

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,26 @@ public void RenderPostProcessing(RenderGraph renderGraph, ContextContainer frame
213213
hdrOperations = !hasFinalPass && enableColorEncodingIfNeeded ? HDROutputUtils.Operation.ColorEncoding : HDROutputUtils.Operation.None;
214214
}
215215

216+
UberPostProcessPass.FilteringOperation filteringOperation = UberPostProcessPass.FilteringOperation.Linear;
217+
218+
// Point sampling is only used for upscaling so the default linear sampler should be used if there is a final pass
219+
if (cameraData.imageScalingMode == ImageScalingMode.Upscaling && !hasFinalPass)
220+
{
221+
#if ENABLE_UPSCALER_FRAMEWORK
222+
if (cameraData.resolvedUpscalerHash == UniversalRenderPipeline.k_UpscalerHash_Point)
223+
{
224+
filteringOperation = UberPostProcessPass.FilteringOperation.Point;
225+
}
226+
#else
227+
if (cameraData.upscalingFilter == ImageUpscalingFilter.Point)
228+
{
229+
filteringOperation = UberPostProcessPass.FilteringOperation.Point;
230+
}
231+
#endif
232+
}
233+
216234
bool renderOverlayUI = requireHDROutput && enableColorEncodingIfNeeded;
217-
m_UberPass.Setup(ditherTexture, hdrOperations, applySrgbEncoding, !hasFinalPass, renderOverlayUI);
235+
m_UberPass.Setup(ditherTexture, filteringOperation, hdrOperations, applySrgbEncoding, !hasFinalPass, renderOverlayUI);
218236
m_UberPass.RecordRenderGraph(renderGraph, frameData);
219237
}
220238

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)