Skip to content

Commit 759d3e2

Browse files
Merge pull request #8296 from Unity-Technologies/internal/6000.0/staging
Internal/6000.0/staging
2 parents 4b012d2 + df6ac0f commit 759d3e2

10 files changed

Lines changed: 61 additions & 46 deletions

File tree

Packages/com.unity.render-pipelines.core/Runtime/XR/XRBuiltinShaderConstants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public static class XRBuiltinShaderConstants
5252
/// </summary>
5353
static public readonly int unity_StereoWorldSpaceCameraPos = Shader.PropertyToID("unity_StereoWorldSpaceCameraPos");
5454

55+
/// <summary>
56+
/// Cached unique id for unity_StereoEyeIndex
57+
/// </summary>
58+
static public readonly int unity_StereoEyeIndex = Shader.PropertyToID("unity_StereoEyeIndex");
59+
5560
// Pre-allocate arrays to avoid GC
5661
static Matrix4x4[] s_cameraProjMatrix = new Matrix4x4[2];
5762
static Matrix4x4[] s_invCameraProjMatrix = new Matrix4x4[2];

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,11 @@ void RecordRenderGraph(RenderRequest renderRequest,
293293
GenerateColorPyramid(m_RenderGraph, hdCamera, colorBuffer, distortionColorPyramid, FullScreenDebugMode.PreRefractionColorPyramid, distortionRendererList);
294294
currentColorPyramid = distortionColorPyramid;
295295

296-
297-
// The color pyramid for distortion is not an history, so it need to be sampled appropriate RT handle scale. Thus we need to update it
298-
var newScale = new Vector4(RTHandles.rtHandleProperties.rtHandleScale.x, RTHandles.rtHandleProperties.rtHandleScale.y, 0, 0);
299-
m_ShaderVariablesGlobalCB._ColorPyramidUvScaleAndLimitCurrentFrame = newScale;
296+
// The color pyramid for distortion is not an history buffer, so it needs to be sampled using an appropriate RT handle scale. Thus we need to update the scale and the limit.
297+
// It's relatively straightforward to update the scale because we store it in rtHandleScale but we miss the limit values. For now, we approximate them by setting them to the scale value.
298+
// This is imperfect but resetting limit at (0, 0) gives worse results (UUM-130925).
299+
var newScaleLimits = new Vector4(RTHandles.rtHandleProperties.rtHandleScale.x, RTHandles.rtHandleProperties.rtHandleScale.y, RTHandles.rtHandleProperties.rtHandleScale.x, RTHandles.rtHandleProperties.rtHandleScale.y);
300+
m_ShaderVariablesGlobalCB._ColorPyramidUvScaleAndLimitCurrentFrame = newScaleLimits;
300301
PushGlobalCameraParams(m_RenderGraph, hdCamera);
301302
}
302303

Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/IndirectDiffuse/RaytracingIndirectDiffuse.compute

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,8 @@ NeighborTapData GetNeighborTapDataSample_HR(uint2 groupThreadId, int2 offset)
222222
return GetNeighborTapDataSample_HR(OffsetToLDSAdress_HR(groupThreadId, offset));
223223
}
224224

225-
NeighborTapData GetNeighborTapDataSample_HR_NOLDS(uint2 fulLResCoord, int2 offset)
225+
NeighborTapData GetNeighborTapDataSample_HR_NOLDS(uint2 tapCoord)
226226
{
227-
int2 tapCoord = (fulLResCoord / 2 + offset) * 2;
228-
tapCoord = int2(clamp(tapCoord.x, 0, (int)_ScreenSize.x - 1), clamp(tapCoord.y, 0, (int)_ScreenSize.y - 1));
229-
230227
NeighborTapData outVal;
231228
outVal.lighting = LOAD_TEXTURE2D_X(_IndirectDiffuseTexture, tapCoord / 2).xyz;
232229
outVal.linearDepth = Linear01Depth(LOAD_TEXTURE2D_X(_DepthTexture, tapCoord).x, _ZBufferParams);
@@ -278,11 +275,15 @@ void IndirectDiffuseIntegrationUpscaleHalfRes(uint3 dispatchThreadId : SV_Dispat
278275
{
279276
for(int x = -HALF_RES_OUT_REGION_SIZE; x < HALF_RES_OUT_REGION_SIZE; ++x)
280277
{
278+
int2 tapCoord = (targetCoord / 2 + int2(x,y)) * 2;
279+
if (any(tapCoord < 0) || any(tapCoord >= _ScreenSize.xy))
280+
continue;
281+
281282
#ifndef WITHOUT_LDS
282283
// Grab the neighbor data
283284
NeighborTapData neighborData = GetNeighborTapDataSample_HR(groupThreadId, int2(x,y));
284285
#else
285-
NeighborTapData neighborData = GetNeighborTapDataSample_HR_NOLDS(targetCoord, int2(x,y));
286+
NeighborTapData neighborData = GetNeighborTapDataSample_HR_NOLDS(tapCoord);
286287
#endif
287288
// Evaluate the weight of this neighbor
288289
float weight = EvaluateNeighborWeight(neighborData, normalData.normalWS, linearDepth);
@@ -416,6 +417,10 @@ void IndirectDiffuseIntegrationUpscaleFullRes(uint3 dispatchThreadId : SV_Dispat
416417
{
417418
for(int x = -FULL_RES_OUT_REGION_SIZE; x < FULL_RES_OUT_REGION_SIZE; ++x)
418419
{
420+
int2 tapCoord = targetCoord + int2(x,y);
421+
if (any(tapCoord < 0) || any(tapCoord >= _ScreenSize.xy))
422+
continue;
423+
419424
#ifndef WITHOUT_LDS
420425
// Grab the neighbor data
421426
NeighborTapData neighborData = GetNeighborTapDataSample_FR(groupThreadId, int2(x,y));

Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawLight2DPass.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,12 @@ internal void Render(RenderGraph graph, ContextContainer frameData, Renderer2DDa
178178
Universal2DResourceData universal2DResourceData = frameData.Get<Universal2DResourceData>();
179179
UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();
180180

181-
DebugHandler debugHandler = ScriptableRenderPass.GetActiveDebugHandler(cameraData);
182-
var isDebugLightingActive = debugHandler?.IsLightingActive ?? true;
183-
184-
#if UNITY_EDITOR
185-
if (cameraData.isSceneViewCamera && UnityEditor.SceneView.currentDrawingSceneView != null)
186-
isDebugLightingActive &= UnityEditor.SceneView.currentDrawingSceneView.sceneLighting;
187-
188-
if (cameraData.camera.cameraType == CameraType.Preview)
189-
isDebugLightingActive = false;
190-
#endif
181+
// Check for lighting in scene/prefab/preview camera
182+
var isLightingActive = Renderer2D.s_IsLightingActive;
191183

192184
if (!layerBatch.lightStats.useLights ||
193185
isVolumetric && !layerBatch.lightStats.useVolumetricLights ||
194-
!isDebugLightingActive)
186+
!isLightingActive)
195187
return;
196188

197189
// Render single RTs by for apis that don't support MRTs

Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawRenderer2DPass.cs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private static void Execute(RasterGraphContext context, PassData passData)
3737
RendererLighting.SetLightShaderGlobals(cmd, passData.lightBlendStyles, passData.blendStyleIndices);
3838

3939
#if UNITY_EDITOR
40-
if (passData.isLitView)
40+
if (passData.isLightingActive)
4141
#endif
4242
{
4343
if (passData.layerUseLights)
@@ -85,7 +85,7 @@ class PassData
8585
internal bool activeDebugHandler;
8686

8787
#if UNITY_EDITOR
88-
internal bool isLitView; // Required for prefab view and preview camera
88+
internal bool isLightingActive; // Required for prefab view and preview camera
8989
#endif
9090
}
9191

@@ -98,35 +98,23 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData
9898
CommonResourceData commonResourceData = frameData.Get<CommonResourceData>();
9999

100100
var layerBatch = layerBatches[batchIndex];
101-
bool isLitView = true;
102101

103-
#if UNITY_EDITOR
104-
// Early out for prefabs
105-
if (cameraData.isSceneViewCamera && UnityEditor.SceneView.currentDrawingSceneView != null)
106-
isLitView = UnityEditor.SceneView.currentDrawingSceneView.sceneLighting;
107-
108-
// Early out for preview camera
109-
if (cameraData.cameraType == CameraType.Preview)
110-
isLitView = false;
111-
112-
DebugHandler debugHandler = GetActiveDebugHandler(cameraData);
113-
if (debugHandler != null)
114-
isLitView = debugHandler.IsLightingActive;
115-
#endif
102+
// Check for lighting in scene/prefab/preview camera
103+
var isLightingActive = Renderer2D.s_IsLightingActive;
116104

117105
// Preset global light textures for first batch
118106
if (batchIndex == 0)
119107
{
120108
using (var builder = graph.AddRasterRenderPass<SetGlobalPassData>(k_SetLightBlendTexture, out var passData, m_SetLightBlendTextureProfilingSampler))
121109
{
122-
if (layerBatch.lightStats.useLights && isLitView)
110+
if (layerBatch.lightStats.useLights && isLightingActive)
123111
{
124112
passData.lightTextures = universal2DResourceData.lightTextures[batchIndex];
125113
for (var i = 0; i < passData.lightTextures.Length; i++)
126114
builder.UseTexture(passData.lightTextures[i]);
127115
}
128116

129-
SetGlobalLightTextures(graph, builder, passData.lightTextures, ref layerBatch, rendererData, isLitView);
117+
SetGlobalLightTextures(graph, builder, passData.lightTextures, ref layerBatch, rendererData, isLightingActive);
130118

131119
builder.AllowPassCulling(false);
132120
builder.AllowGlobalStateModification(true);
@@ -146,7 +134,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData
146134
passData.isSceneLit = rendererData.lightCullResult.IsSceneLit();
147135
passData.layerUseLights = layerBatch.lightStats.useLights;
148136
#if UNITY_EDITOR
149-
passData.isLitView = isLitView;
137+
passData.isLightingActive = isLightingActive;
150138
#endif
151139

152140
var drawSettings = CreateDrawingSettings(k_ShaderTags, renderingData, cameraData, lightData, SortingCriteria.CommonTransparent);
@@ -171,7 +159,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData
171159
builder.UseRendererList(passData.rendererList);
172160
}
173161

174-
if (passData.layerUseLights && isLitView)
162+
if (passData.layerUseLights && isLightingActive)
175163
{
176164
passData.lightTextures = universal2DResourceData.lightTextures[batchIndex];
177165
for (var i = 0; i < passData.lightTextures.Length; i++)
@@ -192,7 +180,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData
192180
// Post set global light textures for next renderer pass
193181
var nextBatch = batchIndex + 1;
194182
if (nextBatch < universal2DResourceData.lightTextures.Length)
195-
SetGlobalLightTextures(graph, builder, universal2DResourceData.lightTextures[nextBatch], ref layerBatches[nextBatch], rendererData, isLitView);
183+
SetGlobalLightTextures(graph, builder, universal2DResourceData.lightTextures[nextBatch], ref layerBatches[nextBatch], rendererData, isLightingActive);
196184

197185
builder.SetRenderFunc((PassData data, RasterGraphContext context) =>
198186
{
@@ -201,9 +189,9 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData
201189
}
202190
}
203191

204-
void SetGlobalLightTextures(RenderGraph graph, IRasterRenderGraphBuilder builder, TextureHandle[] lightTextures, ref LayerBatch layerBatch, Renderer2DData rendererData, bool isLitView)
192+
void SetGlobalLightTextures(RenderGraph graph, IRasterRenderGraphBuilder builder, TextureHandle[] lightTextures, ref LayerBatch layerBatch, Renderer2DData rendererData, bool isLightingActive)
205193
{
206-
if (isLitView)
194+
if (isLightingActive)
207195
{
208196
if (layerBatch.lightStats.useLights)
209197
{

Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/Renderer2DRendergraph.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ internal sealed partial class Renderer2D : ScriptableRenderer
3131
int m_BatchCount;
3232

3333
bool ppcUpscaleRT = false;
34+
static internal bool s_IsLightingActive;
3435

3536
private struct ImportResourceSummary
3637
{
@@ -202,8 +203,10 @@ ImportResourceSummary GetImportResourceSummary(RenderGraph renderGraph, Universa
202203
void InitializeLayerBatches()
203204
{
204205
Universal2DResourceData resourceData = frameData.Get<Universal2DResourceData>();
206+
UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();
205207

206208
m_LayerBatches = LayerUtility.CalculateBatches(m_Renderer2DData, out m_BatchCount);
209+
s_IsLightingActive = IsSceneViewOrPreviewLightingActive(cameraData);
207210

208211
// Initialize textures dependent on batch size
209212
if (resourceData.normalsTexture.Length != m_BatchCount)
@@ -857,5 +860,21 @@ private void CleanupRenderGraphResources()
857860
m_CameraSortingLayerHandle?.Release();
858861
Light2DLookupTexture.Release();
859862
}
863+
864+
static internal bool IsSceneViewOrPreviewLightingActive(UniversalCameraData cameraData)
865+
{
866+
DebugHandler debugHandler = ScriptableRenderPass.GetActiveDebugHandler(cameraData);
867+
var isLightingActive = debugHandler?.IsLightingActive ?? true;
868+
869+
#if UNITY_EDITOR
870+
if (cameraData.isSceneViewCamera && UnityEditor.SceneView.currentDrawingSceneView != null)
871+
isLightingActive &= UnityEditor.SceneView.currentDrawingSceneView.sceneLighting;
872+
873+
if (cameraData.isPreviewCamera && cameraData.camera.name == "Preview Scene Camera")
874+
isLightingActive = false;
875+
#endif
876+
877+
return isLightingActive;
878+
}
860879
}
861880
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ void LensFlareDataDriven(ref UniversalCameraData cameraData, CommandBuffer cmd,
11061106
Matrix4x4 gpuVPXR = GL.GetGPUProjectionMatrix(cameraData.GetProjectionMatrixNoJitter(xrIdx), true) * cameraData.GetViewMatrix(xrIdx);
11071107

11081108
LensFlareCommonSRP.DoLensFlareDataDrivenCommon(
1109-
m_Materials.lensFlareDataDriven, camera, pixelRect, cameraData.xr, cameraData.xr.multipassId,
1109+
m_Materials.lensFlareDataDriven, camera, pixelRect, cameraData.xr, xrIdx,
11101110
(float)m_Descriptor.width, (float)m_Descriptor.height,
11111111
usePanini, paniniDistance, paniniCropToFit, true,
11121112
camera.transform.position,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ public void RenderLensFlareDataDriven(RenderGraph renderGraph, UniversalResource
12551255
Matrix4x4 nonJitteredViewProjMatrix_k = GL.GetGPUProjectionMatrix(data.cameraData.GetProjectionMatrixNoJitter(xrIdx), true) * data.cameraData.GetViewMatrix(xrIdx);
12561256

12571257
LensFlareCommonSRP.DoLensFlareDataDrivenCommon(
1258-
data.material, data.cameraData.camera, data.viewport, xr, data.cameraData.xr.multipassId,
1258+
data.material, data.cameraData.camera, data.viewport, xr, xrIdx,
12591259
data.width, data.height,
12601260
data.usePanini, data.paniniDistance, data.paniniCropToFit,
12611261
true,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ void SetPerCameraShaderVariables(RasterCommandBuffer cmd, UniversalCameraData ca
292292
cameraHeight = (float)cameraTargetSizeCopy.y;
293293

294294
useRenderPassEnabled = false;
295+
296+
// Multi-pass needs to set unity_StereoEyeIndex builtin param for skybox-panoramic.shader to work correctly (UUM-120719)
297+
if (!cameraData.xr.singlePassEnabled)
298+
cmd.SetGlobalVector(XRBuiltinShaderConstants.unity_StereoEyeIndex, new Vector4(cameraData.xr.multipassId, 0, 0, 0));
295299
}
296300

297301
if (camera.allowDynamicResolution)

Packages/com.unity.render-pipelines.universal/Samples~/URPPackageSamples/RendererFeatures/DepthBlit/DepthBlitCopyDepthPass.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
133133
builder.SetRenderFunc((PassData data, RasterGraphContext context) =>
134134
{
135135
// Enable an MSAA shader keyword based on the source texture MSAA sample count
136+
// when depth must be resolved manually in the copy shader
136137
RTHandle sourceTex = data.source;
137-
int cameraSamples = sourceTex.rt.antiAliasing;
138+
int cameraSamples = sourceTex.rt.bindTextureMS ? sourceTex.rt.antiAliasing : 1;
138139
context.cmd.SetKeyword(data.keyword_DepthMsaa2, cameraSamples == 2);
139140
context.cmd.SetKeyword(data.keyword_DepthMsaa4, cameraSamples == 4);
140141
context.cmd.SetKeyword(data.keyword_DepthMsaa8, cameraSamples == 8);

0 commit comments

Comments
 (0)