Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal/2021.3/staging #8108

Merged
merged 7 commits into from
Nov 1, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,12 @@ float EvaluateFinalTransmittance(float3 color, float transmittance)
// reverse the tone mapping
resultLuminance = resultLuminance / (1.0 - resultLuminance);

// By softening the transmittance attenuation curve for pixels adjacent to cloud boundaries when the luminance is super high,
// We can prevent sun flicker and improve perceptual blending. (https://www.desmos.com/calculator/vmly6erwdo)
float finalTransmittance = max(resultLuminance / luminance, pow(transmittance, 6));

// This approach only makes sense if the color is not black
return luminance > 0.0 ? lerp(transmittance, resultLuminance / luminance, _ImprovedTransmittanceBlend) : transmittance;
return luminance > 0.0 ? lerp(transmittance, finalTransmittance, _ImprovedTransmittanceBlend) : transmittance;
}

// This function will return something strictly smaller than 0 if any of the lower res pixels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public static class Styles

// Main light
public static GUIContent mainLightRenderingModeText = EditorGUIUtility.TrTextContent("Main Light", "Main light is the brightest directional light.");
public static GUIContent supportsMainLightShadowsText = EditorGUIUtility.TrTextContent("Cast Shadows", "If enabled the main light can be a shadow casting light.");
public static GUIContent supportsMainLightShadowsText = EditorGUIUtility.TrTextContent("Cast Shadows", "If enabled, the main light can be a shadow casting light.");
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.");

// Additional lights
public static GUIContent addditionalLightsRenderingModeText = EditorGUIUtility.TrTextContent("Additional Lights", "Additional lights support.");
public static GUIContent perObjectLimit = EditorGUIUtility.TrTextContent("Per Object Limit", "Maximum amount of additional lights. These lights are sorted and culled per-object.");
public static GUIContent supportsAdditionalShadowsText = EditorGUIUtility.TrTextContent("Cast Shadows", "If enabled shadows will be supported for spot lights.\n");
public static GUIContent supportsAdditionalShadowsText = EditorGUIUtility.TrTextContent("Cast Shadows", "If enabled, shadows will be supported for spot and point lights.");
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.");
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}.");
public static GUIContent[] additionalLightsShadowResolutionTierNames =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
if (m_IsActiveTargetBackBuffer)
cmd.SetViewport(renderingData.cameraData.xr.GetViewport());

renderingData.cameraData.xr.RenderOcclusionMesh(cmd);
renderingData.cameraData.xr.RenderOcclusionMesh(cmd, renderIntoTexture: !m_IsActiveTargetBackBuffer);

context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ private void SetupFinalPassDebug(ref CameraData cameraData)
}
}

private static bool IsOffscreenDepthTexture(ref CameraData cameraData) => cameraData.targetTexture != null && cameraData.targetTexture.format == RenderTextureFormat.Depth;

bool IsDepthPrimingEnabled(ref CameraData cameraData)
{
// depth priming requires an extra depth copy, disable it on platforms not supporting it (like GLES when MSAA is on)
Expand All @@ -424,7 +426,10 @@ bool IsDepthPrimingEnabled(ref CameraData cameraData)
// Enabled Depth priming when baking Reflection Probes causes artefacts (UUM-12397)
bool isNotReflectionCamera = cameraData.cameraType != CameraType.Reflection;

return depthPrimingRequested && isForwardRenderingMode && isFirstCameraToWriteDepth && isNotReflectionCamera && !GL.wireframe ;
// Depth is not rendered in a depth-only camera setup with depth priming (UUM-38158)
bool isNotOffscreenDepthTexture = !IsOffscreenDepthTexture(ref cameraData);

return depthPrimingRequested && isForwardRenderingMode && isFirstCameraToWriteDepth && isNotReflectionCamera && isNotOffscreenDepthTexture && !GL.wireframe ;
}

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

// Because of the shortcutting done by depth only offscreen cameras, useDepthPriming must be computed early
useDepthPriming = IsDepthPrimingEnabled(ref cameraData);

// Special path for depth only offscreen cameras. Only write opaques + transparents.
bool isOffscreenDepthTexture = cameraData.targetTexture != null && cameraData.targetTexture.format == RenderTextureFormat.Depth;
if (isOffscreenDepthTexture)
if (IsOffscreenDepthTexture(ref cameraData))
{
ConfigureCameraTarget(BuiltinRenderTextureType.CameraTarget, BuiltinRenderTextureType.CameraTarget);
AddRenderPasses(ref renderingData);
Expand Down Expand Up @@ -496,7 +503,7 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
// TODO: We could cache and generate the LUT before rendering the stack
bool generateColorGradingLUT = cameraData.postProcessEnabled && m_PostProcessPasses.isCreated;
bool isSceneViewOrPreviewCamera = cameraData.isSceneViewCamera || cameraData.cameraType == CameraType.Preview;
useDepthPriming = IsDepthPrimingEnabled(ref cameraData);

// This indicates whether the renderer will output a depth texture.
bool requiresDepthTexture = cameraData.requiresDepthTexture || renderPassInputs.requiresDepthTexture || useDepthPriming;

Expand Down Expand Up @@ -943,7 +950,7 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
// Turning off unnecessary NRP in Editor because of MSAA mistmatch between CameraTargetDescriptor vs camera backbuffer
// NRP layer considers this being a pass with MSAA samples by checking CameraTargetDescriptor taken from RP asset
// while the camera backbuffer has a single sample
m_FinalDepthCopyPass.useNativeRenderPass = false;
m_FinalDepthCopyPass.useNativeRenderPass = false;
EnqueuePass(m_FinalDepthCopyPass);
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal struct XRPassCreateInfo
public bool renderTargetIsRenderTexture;
public ScriptableCullingParameters cullingParameters;
public XRPass.CustomMirrorView customMirrorView;
public float occlusionMeshScale;
}

internal struct XRViewCreateInfo
Expand Down Expand Up @@ -84,7 +85,6 @@ class XRPass
internal bool isLateLatchEnabled { get; set; }
internal bool canMarkLateLatch { get; set; }
internal bool hasMarkedLateLatch { get; set; }

// Access to view information
internal Matrix4x4 GetProjMatrix(int viewIndex = 0) { return views[viewIndex].projMatrix; }
internal Matrix4x4 GetViewMatrix(int viewIndex = 0) { return views[viewIndex].viewMatrix; }
Expand All @@ -102,6 +102,7 @@ class XRPass
Material occlusionMeshMaterial = null;
Mesh occlusionMeshCombined = null;
int occlusionMeshCombinedHashCode = 0;
float occlusionMeshScale = 1.0f;

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

Expand Down Expand Up @@ -157,6 +158,7 @@ internal static XRPass Create(XRPassCreateInfo createInfo)
passInfo.occlusionMeshMaterial = null;
passInfo.xrSdkEnabled = false;
passInfo.copyDepth = false;
passInfo.occlusionMeshScale = createInfo.occlusionMeshScale;

return passInfo;
}
Expand Down Expand Up @@ -188,7 +190,7 @@ internal void AddView(Matrix4x4 proj, Matrix4x4 view, Rect vp, int textureArrayS
AddViewInternal(new XRView(proj, view, vp, textureArraySlice));
}

internal static XRPass Create(XRDisplaySubsystem.XRRenderPass xrRenderPass, int multipassId, ScriptableCullingParameters cullingParameters, Material occlusionMeshMaterial)
internal static XRPass Create(XRDisplaySubsystem.XRRenderPass xrRenderPass, int multipassId, ScriptableCullingParameters cullingParameters, Material occlusionMeshMaterial, float occlusionMeshScale)
{
XRPass passInfo = GenericPool<XRPass>.Get();

Expand Down Expand Up @@ -217,6 +219,7 @@ internal static XRPass Create(XRDisplaySubsystem.XRRenderPass xrRenderPass, int
passInfo.xrSdkEnabled = true;
passInfo.copyDepth = xrRenderPass.shouldFillOutDepth;
passInfo.customMirrorView = null;
passInfo.occlusionMeshScale = occlusionMeshScale;

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

Expand Down Expand Up @@ -404,7 +407,7 @@ internal void EndCamera(CommandBuffer cmd, CameraData cameraData)
}
}

internal void RenderOcclusionMesh(CommandBuffer cmd)
internal void RenderOcclusionMesh(CommandBuffer cmd, bool renderIntoTexture = false)
{
#if DEVELOPMENT_BUILD || UNITY_EDITOR
if (XRGraphicsAutomatedTests.enabled && XRGraphicsAutomatedTests.running)
Expand All @@ -417,12 +420,22 @@ internal void RenderOcclusionMesh(CommandBuffer cmd)
{
if (singlePassEnabled)
{
if (occlusionMeshCombined != null && SystemInfo.supportsRenderTargetArrayIndexFromVertexShader)
// Prefer multiview draw
if (occlusionMeshCombined != null && SystemInfo.supportsMultiview)
{
// For the multiview code path, keep the multiview state on to propagate geometries to all eye texture slices
cmd.EnableShaderKeyword("XR_OCCLUSION_MESH_COMBINED");
Vector3 scale = new Vector3(occlusionMeshScale, renderIntoTexture? occlusionMeshScale : -occlusionMeshScale, 1.0f);
cmd.DrawMesh(occlusionMeshCombined, Matrix4x4.Scale(scale), occlusionMeshMaterial);
cmd.DisableShaderKeyword("XR_OCCLUSION_MESH_COMBINED");
}
else if (occlusionMeshCombined != null && SystemInfo.supportsRenderTargetArrayIndexFromVertexShader)
{
StopSinglePass(cmd);

cmd.EnableShaderKeyword("XR_OCCLUSION_MESH_COMBINED");
cmd.DrawMesh(occlusionMeshCombined, Matrix4x4.identity, occlusionMeshMaterial);
Vector3 scale = new Vector3(occlusionMeshScale, renderIntoTexture ? occlusionMeshScale : -occlusionMeshScale, 1.0f);
cmd.DrawMesh(occlusionMeshCombined, Matrix4x4.Scale(scale), occlusionMeshMaterial);
cmd.DisableShaderKeyword("XR_OCCLUSION_MESH_COMBINED");

StartSinglePass(cmd);
Expand Down Expand Up @@ -503,7 +516,7 @@ internal class XRPass
internal void StartSinglePass(CommandBuffer cmd) { }
internal void StopSinglePass(CommandBuffer cmd) { }
internal void EndCamera(CommandBuffer cmd, CameraData camera) { }
internal void RenderOcclusionMesh(CommandBuffer cmd) { }
internal void RenderOcclusionMesh(CommandBuffer cmd, bool yFlip) { }
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal partial class XRSystem

// Internal resources used by XR rendering
Material occlusionMeshMaterial = null;
float occlusionMeshScale = 1.0f;
Material mirrorViewMaterial = null;
MaterialPropertyBlock mirrorViewMaterialProperty = new MaterialPropertyBlock();

Expand Down Expand Up @@ -325,7 +326,7 @@ bool CanUseSinglePass(XRDisplaySubsystem.XRRenderPass renderPass)

if (singlePassAllowed && CanUseSinglePass(renderPass))
{
var xrPass = XRPass.Create(renderPass, multipassId: framePasses.Count, cullingParams, occlusionMeshMaterial);
var xrPass = XRPass.Create(renderPass, multipassId: framePasses.Count, cullingParams, occlusionMeshMaterial, occlusionMeshScale);

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

var xrPass = XRPass.Create(renderPass, multipassId: framePasses.Count, cullingParams, occlusionMeshMaterial);
var xrPass = XRPass.Create(renderPass, multipassId: framePasses.Count, cullingParams, occlusionMeshMaterial, occlusionMeshScale);
xrPass.AddView(renderPass, renderParam);

AddPassToFrame(xrPass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Shader "Universal Render Pipeline/Nature/SpeedTree7"
#pragma multi_compile _ LOD_FADE_CROSSFADE
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
#pragma multi_compile_fragment _ _LIGHT_LAYERS
#pragma multi_compile_vertex LOD_FADE_PERCENTAGE
#pragma multi_compile LOD_FADE_PERCENTAGE
#pragma multi_compile_fragment _ DEBUG_DISPLAY
#pragma multi_compile_fragment _ _LIGHT_COOKIES
#pragma multi_compile _ _CLUSTERED_RENDERING
Expand Down Expand Up @@ -141,7 +141,7 @@ Shader "Universal Render Pipeline/Nature/SpeedTree7"
//#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile_fragment _ _SHADOWS_SOFT
#pragma multi_compile _ LOD_FADE_CROSSFADE
#pragma multi_compile_vertex LOD_FADE_PERCENTAGE
#pragma multi_compile LOD_FADE_PERCENTAGE
#pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
#pragma multi_compile_fragment _ _LIGHT_LAYERS
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Shader "Universal Render Pipeline/Nature/SpeedTree8"
#pragma multi_compile _ LOD_FADE_CROSSFADE
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
#pragma multi_compile_fragment _ _LIGHT_LAYERS
#pragma multi_compile_vertex LOD_FADE_PERCENTAGE
#pragma multi_compile LOD_FADE_PERCENTAGE
#pragma multi_compile_fragment _ _LIGHT_COOKIES

#pragma multi_compile_fog
Expand Down Expand Up @@ -131,7 +131,7 @@ Shader "Universal Render Pipeline/Nature/SpeedTree8"
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION
#pragma multi_compile_fragment _ _SHADOWS_SOFT
#pragma multi_compile _ LOD_FADE_CROSSFADE
#pragma multi_compile_vertex LOD_FADE_PERCENTAGE
#pragma multi_compile LOD_FADE_PERCENTAGE
#pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
#pragma multi_compile_fragment _ _LIGHT_LAYERS
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ Shader "Hidden/Universal Render Pipeline/XR/XROcclusionMesh"

// Not all platforms properly support SV_RenderTargetArrayIndex
#if defined(SHADER_API_D3D11) || defined(SHADER_API_VULKAN) || defined(SHADER_API_GLCORE) || defined(SHADER_API_GLES3) || defined(SHADER_API_PSSL)
#define USE_XR_OCCLUSION_MESH_COMBINED XR_OCCLUSION_MESH_COMBINED
#if defined (UNITY_STEREO_MULTIVIEW_ENABLED)
#define USE_XR_OCCLUSION_MESH_COMBINED_MULTIVIEW XR_OCCLUSION_MESH_COMBINED
#else
#define USE_XR_OCCLUSION_MESH_COMBINED_RT_ARRAY_INDEX XR_OCCLUSION_MESH_COMBINED
#endif
#endif

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

#if USE_XR_OCCLUSION_MESH_COMBINED
#if USE_XR_OCCLUSION_MESH_COMBINED_RT_ARRAY_INDEX
uint rtArrayIndex : SV_RenderTargetArrayIndex;
#endif
};

Varyings Vert(Attributes input)
{
Varyings output;
output.vertex = float4(input.vertex.xy * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), UNITY_NEAR_CLIP_VALUE, 1.0f);
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));

#if USE_XR_OCCLUSION_MESH_COMBINED
#if USE_XR_OCCLUSION_MESH_COMBINED_MULTIVIEW
if (unity_StereoEyeIndex != uint(input.vertex.z))
{
output.vertex = float4(0.0f, 0.0f, 0.0f, 0.0f);
}
#elif USE_XR_OCCLUSION_MESH_COMBINED_RT_ARRAY_INDEX
output.rtArrayIndex = input.vertex.z;
#endif

Expand Down
Loading
Loading