Skip to content

Commit 3d53173

Browse files
authored
Merge pull request #8108 from Unity-Technologies/internal/2021.3/staging
Internal/2021.3/staging
2 parents 358299b + 77326a5 commit 3d53173

File tree

12 files changed

+80
-46
lines changed

12 files changed

+80
-46
lines changed

Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/VolumetricCloudsUtilities.hlsl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,12 @@ float EvaluateFinalTransmittance(float3 color, float transmittance)
511511
// reverse the tone mapping
512512
resultLuminance = resultLuminance / (1.0 - resultLuminance);
513513

514+
// By softening the transmittance attenuation curve for pixels adjacent to cloud boundaries when the luminance is super high,
515+
// We can prevent sun flicker and improve perceptual blending. (https://www.desmos.com/calculator/vmly6erwdo)
516+
float finalTransmittance = max(resultLuminance / luminance, pow(transmittance, 6));
517+
514518
// This approach only makes sense if the color is not black
515-
return luminance > 0.0 ? lerp(transmittance, resultLuminance / luminance, _ImprovedTransmittanceBlend) : transmittance;
519+
return luminance > 0.0 ? lerp(transmittance, finalTransmittance, _ImprovedTransmittanceBlend) : transmittance;
516520
}
517521

518522
// This function will return something strictly smaller than 0 if any of the lower res pixels

Packages/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/UniversalRenderPipelineAssetUI.Skin.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ public static class Styles
4343

4444
// Main light
4545
public static GUIContent mainLightRenderingModeText = EditorGUIUtility.TrTextContent("Main Light", "Main light is the brightest directional light.");
46-
public static GUIContent supportsMainLightShadowsText = EditorGUIUtility.TrTextContent("Cast Shadows", "If enabled the main light can be a shadow casting light.");
46+
public static GUIContent supportsMainLightShadowsText = EditorGUIUtility.TrTextContent("Cast Shadows", "If enabled, the main light can be a shadow casting light.");
4747
public static GUIContent mainLightShadowmapResolutionText = EditorGUIUtility.TrTextContent("Shadow Resolution", "Resolution of the main light shadowmap texture. If cascades are enabled, cascades will be packed into an atlas and this setting controls the maximum shadows atlas resolution.");
4848

4949
// Additional lights
5050
public static GUIContent addditionalLightsRenderingModeText = EditorGUIUtility.TrTextContent("Additional Lights", "Additional lights support.");
5151
public static GUIContent perObjectLimit = EditorGUIUtility.TrTextContent("Per Object Limit", "Maximum amount of additional lights. These lights are sorted and culled per-object.");
52-
public static GUIContent supportsAdditionalShadowsText = EditorGUIUtility.TrTextContent("Cast Shadows", "If enabled shadows will be supported for spot lights.\n");
52+
public static GUIContent supportsAdditionalShadowsText = EditorGUIUtility.TrTextContent("Cast Shadows", "If enabled, shadows will be supported for spot and point lights.");
5353
public static GUIContent additionalLightsShadowmapResolution = EditorGUIUtility.TrTextContent("Shadow Atlas Resolution", "All additional lights are packed into a single shadowmap atlas. This setting controls the atlas size.");
5454
public static GUIContent additionalLightsShadowResolutionTiers = EditorGUIUtility.TrTextContent("Shadow Resolution Tiers", $"Additional Lights Shadow Resolution Tiers. Rounded to the next power of two, and clamped to be at least {UniversalAdditionalLightData.AdditionalLightsShadowMinimumResolution}.");
5555
public static GUIContent[] additionalLightsShadowResolutionTierNames =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
3030
if (m_IsActiveTargetBackBuffer)
3131
cmd.SetViewport(renderingData.cameraData.xr.GetViewport());
3232

33-
renderingData.cameraData.xr.RenderOcclusionMesh(cmd);
33+
renderingData.cameraData.xr.RenderOcclusionMesh(cmd, renderIntoTexture: !m_IsActiveTargetBackBuffer);
3434

3535
context.ExecuteCommandBuffer(cmd);
3636
CommandBufferPool.Release(cmd);

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ private void SetupFinalPassDebug(ref CameraData cameraData)
412412
}
413413
}
414414

415+
private static bool IsOffscreenDepthTexture(ref CameraData cameraData) => cameraData.targetTexture != null && cameraData.targetTexture.format == RenderTextureFormat.Depth;
416+
415417
bool IsDepthPrimingEnabled(ref CameraData cameraData)
416418
{
417419
// depth priming requires an extra depth copy, disable it on platforms not supporting it (like GLES when MSAA is on)
@@ -424,7 +426,10 @@ bool IsDepthPrimingEnabled(ref CameraData cameraData)
424426
// Enabled Depth priming when baking Reflection Probes causes artefacts (UUM-12397)
425427
bool isNotReflectionCamera = cameraData.cameraType != CameraType.Reflection;
426428

427-
return depthPrimingRequested && isForwardRenderingMode && isFirstCameraToWriteDepth && isNotReflectionCamera && !GL.wireframe ;
429+
// Depth is not rendered in a depth-only camera setup with depth priming (UUM-38158)
430+
bool isNotOffscreenDepthTexture = !IsOffscreenDepthTexture(ref cameraData);
431+
432+
return depthPrimingRequested && isForwardRenderingMode && isFirstCameraToWriteDepth && isNotReflectionCamera && isNotOffscreenDepthTexture && !GL.wireframe ;
428433
}
429434

430435
/// <inheritdoc />
@@ -441,9 +446,11 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
441446
if (cameraData.cameraType != CameraType.Game)
442447
useRenderPassEnabled = false;
443448

449+
// Because of the shortcutting done by depth only offscreen cameras, useDepthPriming must be computed early
450+
useDepthPriming = IsDepthPrimingEnabled(ref cameraData);
451+
444452
// Special path for depth only offscreen cameras. Only write opaques + transparents.
445-
bool isOffscreenDepthTexture = cameraData.targetTexture != null && cameraData.targetTexture.format == RenderTextureFormat.Depth;
446-
if (isOffscreenDepthTexture)
453+
if (IsOffscreenDepthTexture(ref cameraData))
447454
{
448455
ConfigureCameraTarget(BuiltinRenderTextureType.CameraTarget, BuiltinRenderTextureType.CameraTarget);
449456
AddRenderPasses(ref renderingData);
@@ -496,7 +503,7 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
496503
// TODO: We could cache and generate the LUT before rendering the stack
497504
bool generateColorGradingLUT = cameraData.postProcessEnabled && m_PostProcessPasses.isCreated;
498505
bool isSceneViewOrPreviewCamera = cameraData.isSceneViewCamera || cameraData.cameraType == CameraType.Preview;
499-
useDepthPriming = IsDepthPrimingEnabled(ref cameraData);
506+
500507
// This indicates whether the renderer will output a depth texture.
501508
bool requiresDepthTexture = cameraData.requiresDepthTexture || renderPassInputs.requiresDepthTexture || useDepthPriming;
502509

@@ -943,7 +950,7 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
943950
// Turning off unnecessary NRP in Editor because of MSAA mistmatch between CameraTargetDescriptor vs camera backbuffer
944951
// NRP layer considers this being a pass with MSAA samples by checking CameraTargetDescriptor taken from RP asset
945952
// while the camera backbuffer has a single sample
946-
m_FinalDepthCopyPass.useNativeRenderPass = false;
953+
m_FinalDepthCopyPass.useNativeRenderPass = false;
947954
EnqueuePass(m_FinalDepthCopyPass);
948955
}
949956
#endif

Packages/com.unity.render-pipelines.universal/Runtime/XR/XRPass.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ internal struct XRPassCreateInfo
2121
public bool renderTargetIsRenderTexture;
2222
public ScriptableCullingParameters cullingParameters;
2323
public XRPass.CustomMirrorView customMirrorView;
24+
public float occlusionMeshScale;
2425
}
2526

2627
internal struct XRViewCreateInfo
@@ -84,7 +85,6 @@ class XRPass
8485
internal bool isLateLatchEnabled { get; set; }
8586
internal bool canMarkLateLatch { get; set; }
8687
internal bool hasMarkedLateLatch { get; set; }
87-
8888
// Access to view information
8989
internal Matrix4x4 GetProjMatrix(int viewIndex = 0) { return views[viewIndex].projMatrix; }
9090
internal Matrix4x4 GetViewMatrix(int viewIndex = 0) { return views[viewIndex].viewMatrix; }
@@ -102,6 +102,7 @@ class XRPass
102102
Material occlusionMeshMaterial = null;
103103
Mesh occlusionMeshCombined = null;
104104
int occlusionMeshCombinedHashCode = 0;
105+
float occlusionMeshScale = 1.0f;
105106

106107
internal bool isOcclusionMeshSupported { get => enabled && xrSdkEnabled && occlusionMeshMaterial != null; }
107108

@@ -157,6 +158,7 @@ internal static XRPass Create(XRPassCreateInfo createInfo)
157158
passInfo.occlusionMeshMaterial = null;
158159
passInfo.xrSdkEnabled = false;
159160
passInfo.copyDepth = false;
161+
passInfo.occlusionMeshScale = createInfo.occlusionMeshScale;
160162

161163
return passInfo;
162164
}
@@ -188,7 +190,7 @@ internal void AddView(Matrix4x4 proj, Matrix4x4 view, Rect vp, int textureArrayS
188190
AddViewInternal(new XRView(proj, view, vp, textureArraySlice));
189191
}
190192

191-
internal static XRPass Create(XRDisplaySubsystem.XRRenderPass xrRenderPass, int multipassId, ScriptableCullingParameters cullingParameters, Material occlusionMeshMaterial)
193+
internal static XRPass Create(XRDisplaySubsystem.XRRenderPass xrRenderPass, int multipassId, ScriptableCullingParameters cullingParameters, Material occlusionMeshMaterial, float occlusionMeshScale)
192194
{
193195
XRPass passInfo = GenericPool<XRPass>.Get();
194196

@@ -217,6 +219,7 @@ internal static XRPass Create(XRDisplaySubsystem.XRRenderPass xrRenderPass, int
217219
passInfo.xrSdkEnabled = true;
218220
passInfo.copyDepth = xrRenderPass.shouldFillOutDepth;
219221
passInfo.customMirrorView = null;
222+
passInfo.occlusionMeshScale = occlusionMeshScale;
220223

221224
Debug.Assert(passInfo.renderTargetValid, "Invalid render target from XRDisplaySubsystem!");
222225

@@ -404,7 +407,7 @@ internal void EndCamera(CommandBuffer cmd, CameraData cameraData)
404407
}
405408
}
406409

407-
internal void RenderOcclusionMesh(CommandBuffer cmd)
410+
internal void RenderOcclusionMesh(CommandBuffer cmd, bool renderIntoTexture = false)
408411
{
409412
#if DEVELOPMENT_BUILD || UNITY_EDITOR
410413
if (XRGraphicsAutomatedTests.enabled && XRGraphicsAutomatedTests.running)
@@ -417,12 +420,22 @@ internal void RenderOcclusionMesh(CommandBuffer cmd)
417420
{
418421
if (singlePassEnabled)
419422
{
420-
if (occlusionMeshCombined != null && SystemInfo.supportsRenderTargetArrayIndexFromVertexShader)
423+
// Prefer multiview draw
424+
if (occlusionMeshCombined != null && SystemInfo.supportsMultiview)
425+
{
426+
// For the multiview code path, keep the multiview state on to propagate geometries to all eye texture slices
427+
cmd.EnableShaderKeyword("XR_OCCLUSION_MESH_COMBINED");
428+
Vector3 scale = new Vector3(occlusionMeshScale, renderIntoTexture? occlusionMeshScale : -occlusionMeshScale, 1.0f);
429+
cmd.DrawMesh(occlusionMeshCombined, Matrix4x4.Scale(scale), occlusionMeshMaterial);
430+
cmd.DisableShaderKeyword("XR_OCCLUSION_MESH_COMBINED");
431+
}
432+
else if (occlusionMeshCombined != null && SystemInfo.supportsRenderTargetArrayIndexFromVertexShader)
421433
{
422434
StopSinglePass(cmd);
423435

424436
cmd.EnableShaderKeyword("XR_OCCLUSION_MESH_COMBINED");
425-
cmd.DrawMesh(occlusionMeshCombined, Matrix4x4.identity, occlusionMeshMaterial);
437+
Vector3 scale = new Vector3(occlusionMeshScale, renderIntoTexture ? occlusionMeshScale : -occlusionMeshScale, 1.0f);
438+
cmd.DrawMesh(occlusionMeshCombined, Matrix4x4.Scale(scale), occlusionMeshMaterial);
426439
cmd.DisableShaderKeyword("XR_OCCLUSION_MESH_COMBINED");
427440

428441
StartSinglePass(cmd);
@@ -503,7 +516,7 @@ internal class XRPass
503516
internal void StartSinglePass(CommandBuffer cmd) { }
504517
internal void StopSinglePass(CommandBuffer cmd) { }
505518
internal void EndCamera(CommandBuffer cmd, CameraData camera) { }
506-
internal void RenderOcclusionMesh(CommandBuffer cmd) { }
519+
internal void RenderOcclusionMesh(CommandBuffer cmd, bool yFlip) { }
507520
}
508521
}
509522
#endif

Packages/com.unity.render-pipelines.universal/Runtime/XR/XRSystem.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ internal partial class XRSystem
2626

2727
// Internal resources used by XR rendering
2828
Material occlusionMeshMaterial = null;
29+
float occlusionMeshScale = 1.0f;
2930
Material mirrorViewMaterial = null;
3031
MaterialPropertyBlock mirrorViewMaterialProperty = new MaterialPropertyBlock();
3132

@@ -325,7 +326,7 @@ bool CanUseSinglePass(XRDisplaySubsystem.XRRenderPass renderPass)
325326

326327
if (singlePassAllowed && CanUseSinglePass(renderPass))
327328
{
328-
var xrPass = XRPass.Create(renderPass, multipassId: framePasses.Count, cullingParams, occlusionMeshMaterial);
329+
var xrPass = XRPass.Create(renderPass, multipassId: framePasses.Count, cullingParams, occlusionMeshMaterial, occlusionMeshScale);
329330

330331
for (int renderParamIndex = 0; renderParamIndex < renderPass.GetRenderParameterCount(); ++renderParamIndex)
331332
{
@@ -341,7 +342,7 @@ bool CanUseSinglePass(XRDisplaySubsystem.XRRenderPass renderPass)
341342
{
342343
renderPass.GetRenderParameter(camera, renderParamIndex, out var renderParam);
343344

344-
var xrPass = XRPass.Create(renderPass, multipassId: framePasses.Count, cullingParams, occlusionMeshMaterial);
345+
var xrPass = XRPass.Create(renderPass, multipassId: framePasses.Count, cullingParams, occlusionMeshMaterial, occlusionMeshScale);
345346
xrPass.AddView(renderPass, renderParam);
346347

347348
AddPassToFrame(xrPass);

Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7.shader

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Shader "Universal Render Pipeline/Nature/SpeedTree7"
4343
#pragma multi_compile _ LOD_FADE_CROSSFADE
4444
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
4545
#pragma multi_compile_fragment _ _LIGHT_LAYERS
46-
#pragma multi_compile_vertex LOD_FADE_PERCENTAGE
46+
#pragma multi_compile LOD_FADE_PERCENTAGE
4747
#pragma multi_compile_fragment _ DEBUG_DISPLAY
4848
#pragma multi_compile_fragment _ _LIGHT_COOKIES
4949
#pragma multi_compile _ _CLUSTERED_RENDERING
@@ -141,7 +141,7 @@ Shader "Universal Render Pipeline/Nature/SpeedTree7"
141141
//#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
142142
#pragma multi_compile_fragment _ _SHADOWS_SOFT
143143
#pragma multi_compile _ LOD_FADE_CROSSFADE
144-
#pragma multi_compile_vertex LOD_FADE_PERCENTAGE
144+
#pragma multi_compile LOD_FADE_PERCENTAGE
145145
#pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
146146
#pragma multi_compile_fragment _ _LIGHT_LAYERS
147147
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED

Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8.shader

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Shader "Universal Render Pipeline/Nature/SpeedTree8"
6161
#pragma multi_compile _ LOD_FADE_CROSSFADE
6262
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
6363
#pragma multi_compile_fragment _ _LIGHT_LAYERS
64-
#pragma multi_compile_vertex LOD_FADE_PERCENTAGE
64+
#pragma multi_compile LOD_FADE_PERCENTAGE
6565
#pragma multi_compile_fragment _ _LIGHT_COOKIES
6666

6767
#pragma multi_compile_fog
@@ -131,7 +131,7 @@ Shader "Universal Render Pipeline/Nature/SpeedTree8"
131131
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION
132132
#pragma multi_compile_fragment _ _SHADOWS_SOFT
133133
#pragma multi_compile _ LOD_FADE_CROSSFADE
134-
#pragma multi_compile_vertex LOD_FADE_PERCENTAGE
134+
#pragma multi_compile LOD_FADE_PERCENTAGE
135135
#pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
136136
#pragma multi_compile_fragment _ _LIGHT_LAYERS
137137
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED

Packages/com.unity.render-pipelines.universal/Shaders/XR/XROcclusionMesh.shader

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ Shader "Hidden/Universal Render Pipeline/XR/XROcclusionMesh"
88

99
// Not all platforms properly support SV_RenderTargetArrayIndex
1010
#if defined(SHADER_API_D3D11) || defined(SHADER_API_VULKAN) || defined(SHADER_API_GLCORE) || defined(SHADER_API_GLES3) || defined(SHADER_API_PSSL)
11-
#define USE_XR_OCCLUSION_MESH_COMBINED XR_OCCLUSION_MESH_COMBINED
11+
#if defined (UNITY_STEREO_MULTIVIEW_ENABLED)
12+
#define USE_XR_OCCLUSION_MESH_COMBINED_MULTIVIEW XR_OCCLUSION_MESH_COMBINED
13+
#else
14+
#define USE_XR_OCCLUSION_MESH_COMBINED_RT_ARRAY_INDEX XR_OCCLUSION_MESH_COMBINED
15+
#endif
1216
#endif
1317

1418
struct Attributes
@@ -20,17 +24,22 @@ Shader "Hidden/Universal Render Pipeline/XR/XROcclusionMesh"
2024
{
2125
float4 vertex : SV_POSITION;
2226

23-
#if USE_XR_OCCLUSION_MESH_COMBINED
27+
#if USE_XR_OCCLUSION_MESH_COMBINED_RT_ARRAY_INDEX
2428
uint rtArrayIndex : SV_RenderTargetArrayIndex;
2529
#endif
2630
};
2731

2832
Varyings Vert(Attributes input)
2933
{
3034
Varyings output;
31-
output.vertex = float4(input.vertex.xy * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), UNITY_NEAR_CLIP_VALUE, 1.0f);
35+
output.vertex = mul(UNITY_MATRIX_M, float4(input.vertex.xy * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), UNITY_NEAR_CLIP_VALUE, 1.0f));
3236

33-
#if USE_XR_OCCLUSION_MESH_COMBINED
37+
#if USE_XR_OCCLUSION_MESH_COMBINED_MULTIVIEW
38+
if (unity_StereoEyeIndex != uint(input.vertex.z))
39+
{
40+
output.vertex = float4(0.0f, 0.0f, 0.0f, 0.0f);
41+
}
42+
#elif USE_XR_OCCLUSION_MESH_COMBINED_RT_ARRAY_INDEX
3443
output.rtArrayIndex = input.vertex.z;
3544
#endif
3645

0 commit comments

Comments
 (0)