Skip to content

Commit 5362f92

Browse files
committed
[SRP] Screen Coordinates Override (v3)
JIRA Epic: https://jira.unity3d.com/browse/CD-74 Re-submission of #6597 which got reverted due to test failures. This PR introduces **Screen Coordinates Override** (**SCO** for the remainder of this document) for both URP and HDRP. SCO provides a transformation of screen space coordinates when evaluating screen space effects. We have found it useful in virtual production scenarios. The first use case for this is **Cluster Display** (formerly known as [Cluster Rendering](https://docs.unity3d.com/560/Documentation/Manual/ClusterRendering.html)), that is, distributed rendering. It allows for post effects such as vignette to be properly rendered at the scale of a grid of displays. Another use case is the implementation of Lens Distortion when replicating the distortion incurred by a physical lens. Since pixels near the edges may be pushed inwards of the viewport by the distortion, we need to render the scene with overscan. (By overscan, we mean rendering to an expanded pixel surface, later cropped out to its original size before being presented.) To preserve the distortion's aspect in the cropped image, we need to apply a transform to screen space coordinates when the lens distortion is being computed. The first implementation of this technique was part of the first Cluster Display effort, and was then called **Cluster Display Space** or **Global Screen Space**. A high level description of the technique can be found in [this document](https://docs.google.com/document/d/1I_mR42Tt119nVhhHwHG9F_n7DwpPin7Tds4yhx59oko/edit?usp=sharing) and [this one](https://docs.google.com/document/d/1qZqUTA5VAeV35PkldjOXXjpKD-JxWfgs2KJC6rh-4mo/edit?usp=sharing). The switch to the **Screen Coordinates Override** terminology is justified by the fact that the technique is relevant outside of Cluster Display. As illustrated above by our Lens Distortion example. In the changes we regularly see the introduction of 2 fields: - `screenCoordScaleBias` holds the scale and bias used to transform screen space coordinates. - `screenSizeOverride` holds the screen size (and its reciprocal) to be used in conjunction with transformed screen space coordinates. --- ### Changes Overview * #### SRP Core - `ScreenCoordOverrideUtils` -> basic utilities to manage the shader keyword. Main point is to avoid the duplication of the shader keyword. - `ScreenCoordOverride.hlsl` -> shader code and macros to perform the screen space coordinates conversion. * #### HDRP - `FrameSettings` -> add `ScreenCoordOverride` and `AsymmetricProjection` settings. `AsymmetricProjection` allows the activation of the asymmetric projection code path even when XR is not enabled. This is useful for Cluster Display. - `HDAdditionalCameraData` -> add the `ScreenSizeOverride` and `ScreenCoordScaleBias` fields. - `ShaderVariablesGlobal` -> add the `ScreenSizeOverride` and `ScreenCoordScaleBias` fields. - `HDCamera` -> update global shader variables. - `HDRenderPipeline` -> activates the shader keyword. - `HDRenderPipeline.PostProcess` -> activates the shader keyword based on frame settings. - `UberPost.compute` -> add SCO support. * #### URP - `ScriptableRenderer` -> fix a swap buffer issue (first fixed [here](#6522)) - `PostProcessUtils` -> init random generation using frame count so that it's consistent across machines in a Cluster Display scenario. - `UniversalAdditionalCameraData` -> add the `ScreenSizeOverride` and `ScreenCoordScaleBias` fields and feature activation. - `UniversalRenderPipeline` -> populate additional camera data. - `UniversalRenderPipelineCore` -> add fields and associated shader properties. - `UniversalRenderer` -> related to swap buffer fix. - `Input.hlsl` -> add the `ScreenSizeOverride` and `ScreenCoordScaleBias` fields. - `FinalPost.shader` -> add SCO support. - `UberPost.shader` -> add SCO support. - `CapturePass` -> fixed color buffer access (before, post effects would not be captured) - `UniversalRenderPipelineGlobalSettings` -> add shader stripping option (`SerializedUniversalRenderPipelineGlobalSettings`, `UniversalRenderPipelineGlobalSettingsUI.Drawers` and `UniversalRenderPipelineGlobalSettingsUI.Skin` were modified to reflect this change) - `ShaderPreprocessor` -> implement shader stripping option
1 parent 56fbdbc commit 5362f92

File tree

78 files changed

+4498
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+4498
-23
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef UNITY_SCREEN_COORD_OVERRIDE_INCLUDED
2+
#define UNITY_SCREEN_COORD_OVERRIDE_INCLUDED
3+
4+
float2 ScreenCoordApplyScaleBias(float2 xy, float4 screenCoordScaleBias)
5+
{
6+
return screenCoordScaleBias.zw + xy * screenCoordScaleBias.xy;
7+
}
8+
9+
float2 ScreenCoordRemoveScaleBias(float2 xy, float4 screenCoordScaleBias)
10+
{
11+
return (xy - screenCoordScaleBias.zw) / screenCoordScaleBias.xy;
12+
}
13+
14+
// Note that SCREEN_SIZE_OVERRIDE will be redefined in HDRP to use _PostProcessScreenSize.
15+
#if defined(SCREEN_COORD_OVERRIDE)
16+
#define SCREEN_COORD_APPLY_SCALEBIAS(xy) ScreenCoordApplyScaleBias(xy, _ScreenCoordScaleBias)
17+
#define SCREEN_COORD_REMOVE_SCALEBIAS(xy) ScreenCoordRemoveScaleBias(xy, _ScreenCoordScaleBias)
18+
#define SCREEN_SIZE_OVERRIDE _ScreenSizeOverride
19+
#else
20+
#define SCREEN_COORD_APPLY_SCALEBIAS(xy) xy
21+
#define SCREEN_COORD_REMOVE_SCALEBIAS(xy) xy
22+
#define SCREEN_SIZE_OVERRIDE _ScreenSize
23+
#endif
24+
25+
#endif // UNITY_SCREEN_COORD_OVERRIDE_INCLUDED

Packages/com.unity.render-pipelines.core/ShaderLibrary/ScreenCoordOverride.hlsl.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/com.unity.render-pipelines.high-definition/Documentation~/Frame-Settings.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,16 @@ These settings determine the method that the Cameras and Reflection Probes using
241241
<td></td>
242242
<td>Select which material quality level to use when rendering from this Camera.<br>•From <strong>Quality Settings</strong>: The Camera uses the <strong>Material Quality Level</strong> property from your Unity Project's <strong>Quality Settings</strong>. To change this value, open the <strong>Project Settings</strong> window (menu: <strong>Edit</strong> &gt; <strong>Project Settings</strong>…), go to <strong>Quality</strong> &gt; <strong>HDRP</strong> &gt; <strong>Rendering</strong> and set the <strong>Material Quality Level</strong> to the value you want.</td>
243243
</tr>
244+
<tr>
245+
<td><strong>Asymmetric Projection</strong></td>
246+
<td></td>
247+
<td>Enable the checkbox to allow HDRP to account for asymmetric projection when evaluating the view direction based on pixel coordinates.</td>
248+
</tr>
249+
<tr>
250+
<td><strong>Screen Coordinates Override</strong></td>
251+
<td></td>
252+
<td>Enable the checkbox to allow HDRP to use Screen Coordinates Override for post processing and custom passes. This allows post effects to be compatible with Cluster Display for example.</td>
253+
</tr>
244254
</tbody>
245255
</table>
246256

Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FinalPass.shader

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Shader "Hidden/HDRP/FinalPass"
66
#pragma editor_sync_compilation
77
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
88

9+
#pragma multi_compile_fragment _ SCREEN_COORD_OVERRIDE
910
#pragma multi_compile_local_fragment _ FXAA
1011
#pragma multi_compile_local_fragment _ GRAIN
1112
#pragma multi_compile_local_fragment _ DITHER
@@ -18,6 +19,7 @@ Shader "Hidden/HDRP/FinalPass"
1819

1920
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
2021
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
22+
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/ScreenCoordOverride.hlsl"
2123
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
2224
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl"
2325
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/PostProcessDefines.hlsl"
@@ -143,7 +145,7 @@ Shader "Hidden/HDRP/FinalPass"
143145
#if GRAIN
144146
{
145147
// Grain in range [0;1] with neutral at 0.5
146-
float grain = SAMPLE_TEXTURE2D(_GrainTexture, s_linear_repeat_sampler, (positionNDC * _GrainTextureParams.xy) + _GrainTextureParams.zw).w;
148+
float grain = SAMPLE_TEXTURE2D(_GrainTexture, s_linear_repeat_sampler, (SCREEN_COORD_APPLY_SCALEBIAS(positionNDC) * _GrainTextureParams.xy) + _GrainTextureParams.zw).w;
147149

148150
// Remap [-1;1]
149151
grain = (grain - 0.5) * 2.0;

Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/UberPost.compute

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
22
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
33
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Filtering.hlsl"
4+
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/ScreenCoordOverride.hlsl"
45
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
6+
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ScreenCoordOverride.hlsl"
57
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/UberPostFeatures.cs.hlsl"
68
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/BloomCommon.hlsl"
79
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
810

911
#pragma kernel Uber
1012

13+
#pragma multi_compile _ SCREEN_COORD_OVERRIDE
1114
#pragma multi_compile _ CHROMATIC_ABERRATION
1215
#pragma multi_compile _ VIGNETTE
1316
#pragma multi_compile _ LENS_DISTORTION
@@ -118,7 +121,7 @@ void Uber(uint3 dispatchThreadId : SV_DispatchThreadID)
118121
{
119122
UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadId.z);
120123
PositionInputs posInputs = GetPositionInput(float2(dispatchThreadId.xy), _PostProcessScreenSize.zw, uint2(GROUP_SIZE, GROUP_SIZE));
121-
float2 uv = posInputs.positionNDC;
124+
float2 uv = SCREEN_COORD_APPLY_SCALEBIAS(posInputs.positionNDC.xy);
122125
float2 uvDistorted = DistortUV(uv);
123126
CTYPE color = 0.0;
124127
CTYPE inputColor = 0.0;
@@ -130,15 +133,15 @@ void Uber(uint3 dispatchThreadId : SV_DispatchThreadID)
130133
float2 coords = 2.0 * uv - 1.0;
131134
float2 end = uv - coords * dot(coords, coords) * ChromaAmount;
132135
float2 diff = end - uv;
133-
int samples = clamp(int(length(_PostProcessScreenSize.xy * diff / 2.0)), 3, ChromaMaxSamples);
136+
int samples = clamp(int(length(SCREEN_SIZE_OVERRIDE.xy * diff / 2.0)), 3, ChromaMaxSamples);
134137
float2 delta = diff / samples;
135138
float2 pos = uv;
136139
float3 sum = 0.0, filterSum = 0.0;
137140

138141
for (int i = 0; i < samples; i++)
139142
{
140143
float t = (i + 0.5) / samples;
141-
float3 s = SAMPLE_TEXTURE2D_X_LOD(_InputTexture, sampler_LinearClamp, ClampAndScaleUVForBilinearPostProcessTexture(DistortUV(pos)), 0.0).xyz;
144+
float3 s = SAMPLE_TEXTURE2D_X_LOD(_InputTexture, sampler_LinearClamp, ClampAndScaleUVForBilinearPostProcessTexture(SCREEN_COORD_REMOVE_SCALEBIAS(DistortUV(pos))), 0.0).xyz;
142145
float3 filter = SAMPLE_TEXTURE2D_LOD(_ChromaSpectralLut, sampler_ChromaSpectralLut, float2(t, 0.0), 0).xyz;
143146

144147
sum += s * filter;
@@ -148,12 +151,12 @@ void Uber(uint3 dispatchThreadId : SV_DispatchThreadID)
148151

149152
color.xyz = sum / filterSum;
150153
#ifdef ENABLE_ALPHA
151-
inputColor = SAMPLE_TEXTURE2D_X_LOD(_InputTexture, sampler_LinearClamp, ClampAndScaleUVForBilinearPostProcessTexture(uvDistorted), 0.0);
154+
inputColor = SAMPLE_TEXTURE2D_X_LOD(_InputTexture, sampler_LinearClamp, ClampAndScaleUVForBilinearPostProcessTexture(SCREEN_COORD_REMOVE_SCALEBIAS(uvDistorted)), 0.0);
152155
color.w = inputColor.w;
153156
#endif
154157

155158
#else
156-
color = SAMPLE_TEXTURE2D_X_LOD(_InputTexture, sampler_LinearClamp, ClampAndScaleUVForBilinearPostProcessTexture(uvDistorted), 0.0).CTYPE_SWIZZLE;
159+
color = SAMPLE_TEXTURE2D_X_LOD(_InputTexture, sampler_LinearClamp, ClampAndScaleUVForBilinearPostProcessTexture(SCREEN_COORD_REMOVE_SCALEBIAS(uvDistorted)), 0.0).CTYPE_SWIZZLE;
157160
inputColor = color;
158161
#endif
159162

@@ -162,9 +165,9 @@ void Uber(uint3 dispatchThreadId : SV_DispatchThreadID)
162165
if (BloomEnabled)
163166
{
164167
#if 0 // Bilinear
165-
float3 bloom = SAMPLE_TEXTURE2D_X_LOD(_BloomTexture, sampler_LinearClamp, ClampAndScaleUVForBilinear(uvDistorted), 0.0).xyz;
168+
float3 bloom = SAMPLE_TEXTURE2D_X_LOD(_BloomTexture, sampler_LinearClamp, ClampAndScaleUVForBilinear(SCREEN_COORD_REMOVE_SCALEBIAS(uvDistorted)), 0.0).xyz;
166169
#else
167-
float3 bloom = SampleTexture2DBicubic(TEXTURE2D_X_ARGS(_BloomTexture, sampler_LinearClamp), uvDistorted * _RTHandlePostProcessScale.xy, _BloomBicubicParams, _RTHandlePostProcessScale.xy, unity_StereoEyeIndex).xyz;
170+
float3 bloom = SampleTexture2DBicubic(TEXTURE2D_X_ARGS(_BloomTexture, sampler_LinearClamp), SCREEN_COORD_REMOVE_SCALEBIAS(uvDistorted) * _RTHandlePostProcessScale.xy, _BloomBicubicParams, _RTHandlePostProcessScale.xy, unity_StereoEyeIndex).xyz;
168171
#endif
169172

170173
float3 thresholdedColor = QuadraticThreshold(color.xyz, _BloomThreshold.x, _BloomThreshold.yzw);
@@ -176,7 +179,7 @@ void Uber(uint3 dispatchThreadId : SV_DispatchThreadID)
176179
// UVs for the dirt texture should be DistortUV(uv * DirtScale + DirtOffset) but
177180
// considering we use a cover-style scale on the dirt texture the difference isn't massive
178181
// so we chose to save a few ALUs here instead in case lens distortion is active
179-
float3 dirt = SAMPLE_TEXTURE2D_LOD(_BloomDirtTexture, sampler_LinearClamp, uvDistorted * DirtScale + DirtOffset, 0.0).xyz;
182+
float3 dirt = SAMPLE_TEXTURE2D_LOD(_BloomDirtTexture, sampler_LinearClamp, SCREEN_COORD_REMOVE_SCALEBIAS(uvDistorted) * DirtScale + DirtOffset, 0.0).xyz;
180183
color.xyz += bloom * dirt * DirtIntensity;
181184
}
182185

@@ -193,14 +196,14 @@ void Uber(uint3 dispatchThreadId : SV_DispatchThreadID)
193196
if (VignetteMode == 0u) // Procedural
194197
{
195198
float2 d = abs(uvDistorted - VignetteCenter) * VignetteIntensity;
196-
d.x *= lerp(1.0, _PostProcessScreenSize.x / _PostProcessScreenSize.y, VignetteRounded);
199+
d.x *= lerp(1.0, SCREEN_SIZE_OVERRIDE.x / SCREEN_SIZE_OVERRIDE.y, VignetteRounded);
197200
d = pow(saturate(d), VignetteRoundness);
198201
float vfactor = pow(saturate(1.0 - dot(d, d)), VignetteSmoothness);
199202
color.xyz *= lerp(VignetteColor, (1.0).xxx, vfactor);
200203
}
201204
else // Masked
202205
{
203-
float vfactor = SAMPLE_TEXTURE2D_LOD(_VignetteMask, sampler_VignetteMask, uvDistorted, 0).w;
206+
float vfactor = SAMPLE_TEXTURE2D_LOD(_VignetteMask, sampler_VignetteMask, SCREEN_COORD_REMOVE_SCALEBIAS(uvDistorted), 0).w;
204207
vfactor = FastSRGBToLinear(vfactor);
205208
float3 newColor = color.xyz * lerp(VignetteColor, (1.0).xxx, vfactor);
206209
color.xyz = lerp(color.xyz, newColor, VignetteOpacity);

Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDAdditionalCameraData.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,12 @@ public enum TAAQualityLevel
363363
/// <summary>Enable to retain history buffers even if the camera is disabled.</summary>
364364
public bool hasPersistentHistory = false;
365365

366+
/// <summary>Screen size used when Screen Coordinates Override is active.</summary>
367+
public Vector4 screenSizeOverride;
368+
369+
/// <summary>Transform used when Screen Coordinates Override is active.</summary>
370+
public Vector4 screenCoordScaleBias;
371+
366372
/// <summary>Allow NVIDIA Deep Learning Super Sampling (DLSS) on this camera.</summary>
367373
[Tooltip("Allow NVIDIA Deep Learning Super Sampling (DLSS) on this camera")]
368374
public bool allowDeepLearningSuperSampling = true;
@@ -637,6 +643,9 @@ public void CopyTo(HDAdditionalCameraData data)
637643

638644
data.materialMipBias = materialMipBias;
639645

646+
data.screenSizeOverride = screenSizeOverride;
647+
data.screenCoordScaleBias = screenCoordScaleBias;
648+
640649
// We must not copy the following
641650
//data.m_IsDebugRegistered = m_IsDebugRegistered;
642651
//data.m_CameraRegisterName = m_CameraRegisterName;

Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,8 @@ unsafe internal void UpdateShaderVariablesGlobalCB(ref ShaderVariablesGlobal cb,
11501150
&& antialiasing == AntialiasingMode.TemporalAntialiasing
11511151
&& camera.cameraType == CameraType.Game;
11521152

1153+
var additionalCameraDataIsNull = m_AdditionalCameraData == null;
1154+
11531155
cb._ViewMatrix = mainViewConstants.viewMatrix;
11541156
cb._CameraViewMatrix = mainViewConstants.viewMatrix;
11551157
cb._InvViewMatrix = mainViewConstants.invViewMatrix;
@@ -1206,13 +1208,18 @@ unsafe internal void UpdateShaderVariablesGlobalCB(ref ShaderVariablesGlobal cb,
12061208
float exposureMultiplierForProbes = 1.0f / Mathf.Max(probeRangeCompressionFactor, 1e-6f);
12071209
cb._ProbeExposureScale = exposureMultiplierForProbes;
12081210

1209-
cb._DeExposureMultiplier = m_AdditionalCameraData == null ? 1.0f : m_AdditionalCameraData.deExposureMultiplier;
1211+
cb._DeExposureMultiplier = additionalCameraDataIsNull ? 1.0f : m_AdditionalCameraData.deExposureMultiplier;
12101212

12111213
// IMPORTANT NOTE: This checks if we have Movec and not Transparent Motion Vectors because in that case we need to write camera motion vectors
12121214
// for transparent objects, otherwise the transparent objects will look completely broken upon motion if Transparent Motion Vectors is off.
12131215
// If TransparentsWriteMotionVector the camera motion vectors are baked into the per object motion vectors.
12141216
cb._TransparentCameraOnlyMotionVectors = (frameSettings.IsEnabled(FrameSettingsField.MotionVectors) &&
12151217
!frameSettings.IsEnabled(FrameSettingsField.TransparentsWriteMotionVector)) ? 1 : 0;
1218+
1219+
cb._ScreenSizeOverride = additionalCameraDataIsNull ? cb._ScreenSize : m_AdditionalCameraData.screenSizeOverride;
1220+
1221+
// Default to identity scale-bias.
1222+
cb._ScreenCoordScaleBias = additionalCameraDataIsNull ? new Vector4(1, 1, 0, 0) : m_AdditionalCameraData.screenCoordScaleBias;
12161223
}
12171224

12181225
unsafe internal void UpdateShaderVariablesXRCB(ref ShaderVariablesXR cb)
@@ -1850,8 +1857,8 @@ internal Matrix4x4 GetJitteredProjectionMatrix(Matrix4x4 origProj)
18501857
/// <returns></returns>
18511858
Matrix4x4 ComputePixelCoordToWorldSpaceViewDirectionMatrix(ViewConstants viewConstants, Vector4 resolution, float aspect = -1)
18521859
{
1853-
// In XR mode, use a more generic matrix to account for asymmetry in the projection
1854-
var useGenericMatrix = xr.enabled;
1860+
// In XR mode, or if explicitely required, use a more generic matrix to account for asymmetry in the projection
1861+
var useGenericMatrix = xr.enabled || frameSettings.IsEnabled(FrameSettingsField.AsymmetricProjection);
18551862

18561863
// Asymmetry is also possible from a user-provided projection, so we must check for it too.
18571864
// Note however, that in case of physical camera, the lens shift term is the only source of

Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public RTHandle Allocator(string id, int frameIndex, RTHandleSystem rtHandleSyst
148148
bool m_FilmGrainFS;
149149
bool m_DitheringFS;
150150
bool m_AntialiasingFS;
151+
bool m_ScreenCoordOverride;
151152

152153
// Debug Exposure compensation (Drive by debug menu) to add to all exposure processed value
153154
float m_DebugExposureCompensation;
@@ -357,6 +358,7 @@ void BeginPostProcessFrame(CommandBuffer cmd, HDCamera camera, HDRenderPipeline
357358
m_FilmGrainFS = frameSettings.IsEnabled(FrameSettingsField.FilmGrain) && m_PostProcessEnabled;
358359
m_DitheringFS = frameSettings.IsEnabled(FrameSettingsField.Dithering) && m_PostProcessEnabled;
359360
m_AntialiasingFS = frameSettings.IsEnabled(FrameSettingsField.Antialiasing) || camera.IsTAAUEnabled();
361+
m_ScreenCoordOverride = frameSettings.IsEnabled(FrameSettingsField.ScreenCoordOverride) && m_PostProcessEnabled;
360362

361363
// Override full screen anti-aliasing when doing path tracing (which is naturally anti-aliased already)
362364
m_AntialiasingFS &= !camera.IsPathTracingEnabled();
@@ -4648,6 +4650,12 @@ TextureHandle UberPass(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle
46484650
passData.uberPostCS.shaderKeywords = null;
46494651

46504652
passData.uberPostKernel = passData.uberPostCS.FindKernel("Uber");
4653+
4654+
if (m_ScreenCoordOverride)
4655+
{
4656+
passData.uberPostCS.EnableKeyword("SCREEN_COORD_OVERRIDE");
4657+
}
4658+
46514659
if (PostProcessEnableAlpha())
46524660
{
46534661
passData.uberPostCS.EnableKeyword("ENABLE_ALPHA");

Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,8 @@ void ConfigureKeywords(bool enableBakeShadowMask, HDCamera hdCamera, CommandBuff
10621062

10631063
// Raise or remove the depth msaa flag based on the frame setting
10641064
CoreUtils.SetKeyword(cmd, "WRITE_MSAA_DEPTH", hdCamera.msaaEnabled);
1065+
1066+
CoreUtils.SetKeyword(cmd, "SCREEN_COORD_OVERRIDE", hdCamera.frameSettings.IsEnabled(FrameSettingsField.ScreenCoordOverride));
10651067
}
10661068
}
10671069

Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Settings/FrameSettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ public enum FrameSettingsField
159159
/// <summary>When enabled, Cameras using these Frame Settings render water surfaces.</summary>
160160
[FrameSettingsField(0, autoName: Water, customOrderInGroup: 106, tooltip: "When enabled, Cameras using these Frame Settings render water surfaces.")]
161161
Water = 99,
162+
/// <summary>When enabled, HDRP accounts for asymmetry in the projection matrix when evaluating the view direction based on pixel coordinates.</summary>
163+
[FrameSettingsField(0, displayedName: "Asymmetric Projection", customOrderInGroup: 107, tooltip: "When enabled HDRP will account for asymmetric projection when evaluating the view direction based on pixel coordinates.")]
164+
AsymmetricProjection = 78,
165+
/// <summary>When enabled, HDRP evaluates post effects using transformed screen space coordinates, this allows post effects to be compatible with Cluster Display for example.</summary>
166+
[FrameSettingsField(0, displayedName: "Screen Coordinates Override", customOrderInGroup: 108, tooltip: "When enabled HDRP will use Screen Coordinates Override for post processing and custom passes. This allows post effects to be compatible with Cluster Display for example.")]
167+
ScreenCoordOverride = 77,
162168

163169
/// <summary>When enabled, HDRP processes a motion vector pass for Cameras using these Frame Settings.</summary>
164170
[FrameSettingsField(0, autoName: MotionVectors, customOrderInGroup: 12, tooltip: "When enabled, HDRP processes a motion vector pass for Cameras using these Frame Settings (Depends on \"Motion Vectors\" in current HDRP Asset).")]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef UNITY_SCREEN_COORD_OVERRIDE_HDRP_INCLUDED
2+
#define UNITY_SCREEN_COORD_OVERRIDE_HDRP_INCLUDED
3+
4+
#ifndef UNITY_SCREEN_COORD_OVERRIDE_INCLUDED
5+
#error UNITY_SCREEN_COORD_OVERRIDE_INCLUDED not defined, you should include "Packages/com.unity.render-pipelines.core/ShaderLibrary/ScreenCoordOverride.hlsl"
6+
#else
7+
// We must redefine SCREEN_SIZE_OVERRIDE on HDRP to use _PostProcessScreenSize.
8+
#undef SCREEN_SIZE_OVERRIDE
9+
#if defined(SCREEN_COORD_OVERRIDE)
10+
#define SCREEN_SIZE_OVERRIDE _ScreenSizeOverride
11+
#else
12+
#define SCREEN_SIZE_OVERRIDE _PostProcessScreenSize
13+
#endif
14+
#endif
15+
16+
#endif // UNITY_SCREEN_COORD_OVERRIDE_HDRP_INCLUDED

Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ScreenCoordOverride.hlsl.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,9 @@ unsafe struct ShaderVariablesGlobal
253253
public float _GlobalTessellationFactorMultiplier;
254254
public float _SpecularOcclusionBlend;
255255
public float _DeExposureMultiplier;
256+
257+
// See ScreenCoordOverride.hlsl for details.
258+
public Vector4 _ScreenSizeOverride;
259+
public Vector4 _ScreenCoordScaleBias;
256260
}
257261
}

Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ GLOBAL_CBUFFER_START(ShaderVariablesGlobal, b0)
146146
float _GlobalTessellationFactorMultiplier;
147147
float _SpecularOcclusionBlend;
148148
float _DeExposureMultiplier;
149+
float4 _ScreenSizeOverride;
150+
float4 _ScreenCoordScaleBias;
149151
CBUFFER_END
150152

151153

0 commit comments

Comments
 (0)