diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index 6d37045ca6a..9c8cf0745cc 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -8,7 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Added public api and updated docs for Light2D shape properties. -- Depth Texture setting for Overlay Camera. +- Added Depth Texture setting for Overlay Camera. +- Added Depth Priming support for Vulkan with MSAA. +- Added Shadows and Additional Lights off variants stripping. ### Changed @@ -18,7 +20,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Fixed the LensFlare flicker with TAA on SceneView (case 1356734). - Fixed an issue where Unlit and ParticlesUnlit shaders did not have HDR color selection for albedo [case 1283767](https://issuetracker.unity3d.com/issues/built-in-unlit-particle-shader-has-hdr-color-selection-for-albedo-urp-unlit-particles-do-not) +- Fixed a regression where ShaderGraph screen position was not correct in game view and when using XR [1369450] - Fixed overwriting of preview camera background color. [case 1357004](https://issuetracker.unity3d.com/product/unity/issues/guid/1361557/) +- Fixed ShadowCaster now requires varying normalWS to include changed normals from vertex shader in shader graph. +- Fixed typo in numIterationsEnclosingSphere api name ## [13.0.0] - 2021-09-01 ### Added @@ -29,6 +34,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - Removed experimental tile deferred code. - VFX: New shadergraph support directly on Universal target. +- Main light shadow, additional light shadow and additional light keywords are now enabled based on urp setting instead of existence in scene. This allows better variant stripping. ### Fixed - Added warning for lit shader detailed abledo, if texture is not linear. [1342011](https://issuetracker.unity3d.com/issues/detail-maps-packed-differently-in-built-in-vs-urp) @@ -40,6 +46,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed a bug with Sprite Targets in ShaderGraph not rendering correctly in game view [1352225] - Fix for rendering thumbnails. [case 1348209](https://issuetracker.unity3d.com/issues/preview-of-assets-do-not-show-in-the-project-window) - Fixed a regression bug where XR camera postion can not be modified in beginCameraRendering [case 1365000] +- Fixed an issue in where installing the Adaptive Performance package caused errors to the inspector UI [1368161](https://issuetracker.unity3d.com/issues/urp-package-throws-compilation-error-cs1525-when-imported-together-with-adaptive-performance-package) ## [12.0.0] - 2021-01-11 ### Added @@ -214,6 +221,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed graphical artefact when terrain height map is used with rendering layer mask for lighting. - Fixed an issue where screen space shadows has flickering with deferred mode [case 1354681](https://issuetracker.unity3d.com/issues/screen-space-shadows-flicker-in-scene-view-when-using-deferred-rendering) - Fixed shadowCascadeBlendCullingFactor to be 1.0 +- Fixed missing property values in a RendererFeature of screen space shadows by adding tooltip for it instead of showing them. [case 1327356] ### Changed - Change Asset/Create/Shader/Universal Render Pipeline/Lit Shader Graph to Asset/Create/Shader Graph/URP/Lit Shader Graph diff --git a/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-cast-shadow-totransparent.png b/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-cast-shadow-totransparent.png new file mode 100644 index 00000000000..febb826d9f4 --- /dev/null +++ b/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-cast-shadow-totransparent.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1dd722fbf9a4d421c79d0268deb6d87b3ee521ca83015fbad9861554bfec4b15 +size 124823 diff --git a/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-cast-shadow-using-cascades.png b/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-cast-shadow-using-cascades.png new file mode 100644 index 00000000000..a554f0aeecb --- /dev/null +++ b/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-cast-shadow-using-cascades.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4305f436505801c1de58c95b69d04c76648d4fce5dbfb9847667801b176c5e95 +size 117093 diff --git a/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-cast-shadow-using-screenspace.png b/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-cast-shadow-using-screenspace.png new file mode 100644 index 00000000000..473c13427cd --- /dev/null +++ b/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-cast-shadow-using-screenspace.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:27fce9027fb66ccf091c59905cefe21e01f13c69df70d63a401e49fe287b756a +size 148745 diff --git a/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-framedebugger.png b/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-framedebugger.png new file mode 100644 index 00000000000..29060b06419 --- /dev/null +++ b/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-framedebugger.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d50ac884c4aedd248d33648eaee620db8e19ca41f6d18de9610c35e99914a87f +size 106816 diff --git a/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-result.png b/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-result.png new file mode 100644 index 00000000000..46301367893 --- /dev/null +++ b/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-result.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8dcbef7182db2dd24ee09b64f4d2e2f6f2b5cc476e4df0c2035b521760c06811 +size 1602863 diff --git a/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-shadow-texture.png b/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-shadow-texture.png new file mode 100644 index 00000000000..b3ed67c0c98 --- /dev/null +++ b/com.unity.render-pipelines.universal/Documentation~/Images/ssshadows/ssshadows-shadow-texture.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d00bcb6e88a04fafdd8d5e2ca932aa4e3421333adb0be88d84b4209d5c342c6 +size 125362 diff --git a/com.unity.render-pipelines.universal/Documentation~/lighting.md b/com.unity.render-pipelines.universal/Documentation~/lighting.md index c3440c12fd8..9ffb6b53ea8 100644 --- a/com.unity.render-pipelines.universal/Documentation~/lighting.md +++ b/com.unity.render-pipelines.universal/Documentation~/lighting.md @@ -8,7 +8,7 @@ Areas where the Universal Render Pipeline (URP) differs from Unity's common ligh * The [Light component inspector](light-component.md), which displays some URP-specific controls. * The [Universal Additional Light Data](universal-additional-light-data.md) component, which allows Unity to store Light-related data that is specific to URP. -* Enlighten Realtime Global Illumination is supported in URP from version 12. For more information, see the forum post [Update on Global Illumination 2021](https://forum.unity.com/threads/update-on-global-illumination-2021.1067015/). +* Enlighten Realtime Global Illumination is supported in URP from version 12. For more information, see [Realtime Global Illumination using Enlighten](https://docs.unity3d.com/2021.2/Documentation/Manual/realtime-gi-using-enlighten.html). For a full comparison of lighting features between Unity's Built-in Render Pipeline and URP, and an up to date list of lighting features that are currently under research, see [this feature comparison chart](universalrp-builtin-feature-comparison.md). diff --git a/com.unity.render-pipelines.universal/Documentation~/renderer-feature-screen-space-shadows.md b/com.unity.render-pipelines.universal/Documentation~/renderer-feature-screen-space-shadows.md new file mode 100644 index 00000000000..e21c84233f9 --- /dev/null +++ b/com.unity.render-pipelines.universal/Documentation~/renderer-feature-screen-space-shadows.md @@ -0,0 +1,24 @@ +# Screen Space Shadows Renderer Feature + +The Screen Space Shadows [Renderer Feature](urp-renderer-feature.md) calculates screen-space shadows for opaque objects affected by the main directional light and draws them in the scene. To render screen-space shadows, URP requires an additional render target. This increases the amount of memory your application requires, but if your project uses forward rendering, screen-space shadows can benefit the runtime resource intensity. This is because if you use screen-space shadows, URP doesn't need to access the cascade shadow maps multiple times. +![Show screen space shadows](Images/ssshadows/ssshadows-result.png)
*Screen-space shadows in a sample Scene.* + +![Show screen space shadows texture](Images/ssshadows/ssshadows-shadow-texture.png)
*The screen-space shadows texture for the above image.* + +## Enabling screen-space shadows + +To add screen space shadows to your project, [add the Screen Space Shadows Renderer Feature ](urp-renderer-feature-how-to-add.md) to the URP Renderer. + +## Viewing screen-space shadows in the Frame Debugger + +After you enable this Renderer Feature, URP renders screen-space shadows in your scene. To distinguish between shadow map shadows and screen-space shadows, you can view the render passes that draws the shadows in the [Frame Debugger](https://docs.unity3d.com/Manual/FrameDebugger.html). +![Show main light shadows in frame debugger](Images/ssshadows/ssshadows-framedebugger.png)
*Screen Space Shadows pass in frame debugger.* + +You can compare shadows cast on opaque objects from the screen-space shadow texture or the cascade shadow maps. +![Cast Shadows using screen space shadow stexture](Images/ssshadows/ssshadows-cast-shadow-using-screenspace.png)
*The Frame Debugger shows the screen-space shadows texture.* + +![Cast shadows using cascade shadowmaps](Images/ssshadows/ssshadows-cast-shadow-using-cascades.png)
*The Frame Debugger shows shadows from a shadow map.* + +## **Requirements and compatibility** + +This Renderer Feature uses a depth texture and invokes a depth prepass before it draws opaque objects. It calculates the shadows in screen space before the `DrawOpaqueObjects` render pass. URP doesn't calculate or apply screen-space shadows for transparent objects; it uses [shadow maps](urp-shadows.md) for transparent objects instead. ![Won't cast shadows on transparent from screen space shadow texture](Images/ssshadows/ssshadows-cast-shadow-totransparent.png)*
The Frame Debugger showing that Unity uses shadow maps for transparent objects and screen-space shadows for opaque objects.* diff --git a/com.unity.render-pipelines.universal/Editor/RendererFeatures/ScreenSpaceShadowsEditor.cs b/com.unity.render-pipelines.universal/Editor/RendererFeatures/ScreenSpaceShadowsEditor.cs new file mode 100644 index 00000000000..ba30993c0cb --- /dev/null +++ b/com.unity.render-pipelines.universal/Editor/RendererFeatures/ScreenSpaceShadowsEditor.cs @@ -0,0 +1,36 @@ +using UnityEngine; +using UnityEngine.Rendering.Universal; + +namespace UnityEditor.Rendering.Universal +{ + [CustomEditor(typeof(ScreenSpaceShadows))] + internal class ScreenSpaceShadowsEditor : Editor + { + #region Serialized Properties + private SerializedProperty m_SettingsProp; + #endregion + + private bool m_IsInitialized = false; + + private struct Styles + { + public static GUIContent Description = EditorGUIUtility.TrTextContent("Description", "This feature resolves the cascaded shadows in screen space, so there is no options now. It might have additional settings later."); + } + + private void Init() + { + m_SettingsProp = serializedObject.FindProperty("m_Settings"); + m_IsInitialized = true; + } + + public override void OnInspectorGUI() + { + if (!m_IsInitialized) + { + Init(); + } + + EditorGUILayout.PropertyField(m_SettingsProp, Styles.Description); + } + } +} diff --git a/com.unity.render-pipelines.universal/Editor/RendererFeatures/ScreenSpaceShadowsEditor.cs.meta b/com.unity.render-pipelines.universal/Editor/RendererFeatures/ScreenSpaceShadowsEditor.cs.meta new file mode 100644 index 00000000000..8b9a03effff --- /dev/null +++ b/com.unity.render-pipelines.universal/Editor/RendererFeatures/ScreenSpaceShadowsEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d79f23692575f9d4f894c5b5a4b0ccad +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs index 9fc4dfa43f4..52847c9e051 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs @@ -1083,7 +1083,7 @@ static class CoreRequiredFields { public static readonly FieldCollection ShadowCaster = new FieldCollection() { - StructFields.Attributes.normalOS, + StructFields.Varyings.normalWS, }; public static readonly FieldCollection DepthNormals = new FieldCollection() diff --git a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Templates/SharedCode.template.hlsl b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Templates/SharedCode.template.hlsl index ccada955348..261b502f37b 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderGraph/Templates/SharedCode.template.hlsl +++ b/com.unity.render-pipelines.universal/Editor/ShaderGraph/Templates/SharedCode.template.hlsl @@ -55,7 +55,16 @@ SurfaceDescriptionInputs BuildSurfaceDescriptionInputs(Varyings input) $SurfaceDescriptionInputs.AbsoluteWorldSpacePositionPredisplacement:output.AbsoluteWorldSpacePositionPredisplacement = GetAbsolutePositionWS(input.positionWS); $SurfaceDescriptionInputs.ScreenPosition: output.ScreenPosition = ComputeScreenPos(TransformWorldToHClip(input.positionWS), _ProjectionParams.x); $SurfaceDescriptionInputs.PixelPosition: output.PixelPosition = input.positionCS.xy; + $SurfaceDescriptionInputs.NDCPosition: #if defined(USING_STEREO_MATRICES) + $SurfaceDescriptionInputs.NDCPosition: output.NDCPosition = output.ScreenPosition.xy / output.ScreenPosition.w; + $SurfaceDescriptionInputs.NDCPosition: #else $SurfaceDescriptionInputs.NDCPosition: output.NDCPosition = output.PixelPosition.xy / _ScreenParams.xy; + $SurfaceDescriptionInputs.NDCPosition: #if UNITY_UV_STARTS_AT_TOP + $SurfaceDescriptionInputs.NDCPosition: output.NDCPosition.y = (0.5f - output.NDCPosition.y) * _ProjectionParams.x + 0.5f; + $SurfaceDescriptionInputs.NDCPosition: #else + $SurfaceDescriptionInputs.NDCPosition: output.NDCPosition.y = (output.NDCPosition.y - 0.5f) * _ProjectionParams.x + 0.5f; + $SurfaceDescriptionInputs.NDCPosition: #endif + $SurfaceDescriptionInputs.NDCPosition: #endif $SurfaceDescriptionInputs.uv0: output.uv0 = input.texCoord0; $SurfaceDescriptionInputs.uv1: output.uv1 = input.texCoord1; $SurfaceDescriptionInputs.uv2: output.uv2 = input.texCoord2; diff --git a/com.unity.render-pipelines.universal/Editor/ShaderPreprocessor.cs b/com.unity.render-pipelines.universal/Editor/ShaderPreprocessor.cs index 281ff34c047..e87cb5fa551 100644 --- a/com.unity.render-pipelines.universal/Editor/ShaderPreprocessor.cs +++ b/com.unity.render-pipelines.universal/Editor/ShaderPreprocessor.cs @@ -48,6 +48,8 @@ enum ShaderFeatures MainLightShadowsCascade = (1 << 26), DrawProcedural = (1 << 27), ScreenSpaceOcclusionAfterOpaque = (1 << 28), + AdditionalLightsKeepOffVariants = (1 << 29), + ShadowsKeepOffVariants = (1 << 30), } [Flags] @@ -358,12 +360,22 @@ bool StripUnusedFeatures(ShaderFeatures features, Shader shader, ShaderSnippetDa var stripTool = new StripTool(features, shader, snippetData, compilerData.shaderKeywordSet, stripUnusedVariants); // strip main light shadows, cascade and screen variants - // TODO: Strip disabled keyword once no light will re-use same variant - if (stripTool.StripMultiCompileKeepOffVariant( - m_MainLightShadows, ShaderFeatures.MainLightShadows, - m_MainLightShadowsCascades, ShaderFeatures.MainLightShadowsCascade, - m_MainLightShadowsScreen, ShaderFeatures.ScreenSpaceShadows)) - return true; + if (IsFeatureEnabled(ShaderFeatures.ShadowsKeepOffVariants, features)) + { + if (stripTool.StripMultiCompileKeepOffVariant( + m_MainLightShadows, ShaderFeatures.MainLightShadows, + m_MainLightShadowsCascades, ShaderFeatures.MainLightShadowsCascade, + m_MainLightShadowsScreen, ShaderFeatures.ScreenSpaceShadows)) + return true; + } + else + { + if (stripTool.StripMultiCompile( + m_MainLightShadows, ShaderFeatures.MainLightShadows, + m_MainLightShadowsCascades, ShaderFeatures.MainLightShadowsCascade, + m_MainLightShadowsScreen, ShaderFeatures.ScreenSpaceShadows)) + return true; + } // TODO: Strip off variants once we have global soft shadows option for forcing instead as support if (stripTool.StripMultiCompileKeepOffVariant(m_SoftShadows, ShaderFeatures.SoftShadows)) @@ -400,9 +412,16 @@ bool StripUnusedFeatures(ShaderFeatures features, Shader shader, ShaderSnippetDa return true; // No additional light shadows - // TODO: Strip off variants once we support no shadow lights re-use same variant - if (stripTool.StripMultiCompileKeepOffVariant(m_AdditionalLightShadows, ShaderFeatures.AdditionalLightShadows)) - return true; + if (IsFeatureEnabled(ShaderFeatures.ShadowsKeepOffVariants, features)) + { + if (stripTool.StripMultiCompileKeepOffVariant(m_AdditionalLightShadows, ShaderFeatures.AdditionalLightShadows)) + return true; + } + else + { + if (stripTool.StripMultiCompile(m_AdditionalLightShadows, ShaderFeatures.AdditionalLightShadows)) + return true; + } if (stripTool.StripMultiCompile(m_ReflectionProbeBlending, ShaderFeatures.ReflectionProbeBlending)) return true; @@ -425,10 +444,18 @@ bool StripUnusedFeatures(ShaderFeatures features, Shader shader, ShaderSnippetDa } // Additional light are shaded per-vertex or per-pixel. - // TODO: Strip off variants once we support no additional lights re-used variants - if (stripTool.StripMultiCompileKeepOffVariant(m_AdditionalLightsVertex, ShaderFeatures.VertexLighting, - m_AdditionalLightsPixel, ShaderFeatures.AdditionalLights)) - return true; + if (IsFeatureEnabled(ShaderFeatures.AdditionalLightsKeepOffVariants, features)) + { + if (stripTool.StripMultiCompileKeepOffVariant(m_AdditionalLightsVertex, ShaderFeatures.VertexLighting, + m_AdditionalLightsPixel, ShaderFeatures.AdditionalLights)) + return true; + } + else + { + if (stripTool.StripMultiCompile(m_AdditionalLightsVertex, ShaderFeatures.VertexLighting, + m_AdditionalLightsPixel, ShaderFeatures.AdditionalLights)) + return true; + } if (stripTool.StripMultiCompile(m_ClusteredRendering, ShaderFeatures.ClusteredRendering)) return true; @@ -921,6 +948,12 @@ private static ShaderFeatures GetSupportedShaderFeatures(UniversalRenderPipeline } } + if (!renderer.stripShadowsOffVariants) + shaderFeatures |= ShaderFeatures.ShadowsKeepOffVariants; + + if (!renderer.stripAdditionalLightOffVariants) + shaderFeatures |= ShaderFeatures.AdditionalLightsKeepOffVariants; + var rendererClustered = false; ScriptableRendererData rendererData = pipelineAsset.m_RendererDataList[rendererIndex]; diff --git a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/SerializedUniversalRenderPipelineAsset.cs b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/SerializedUniversalRenderPipelineAsset.cs index 71103e44ba1..caac1f9b20b 100644 --- a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/SerializedUniversalRenderPipelineAsset.cs +++ b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/SerializedUniversalRenderPipelineAsset.cs @@ -61,8 +61,9 @@ internal class SerializedUniversalRenderPipelineAsset public SerializedProperty colorGradingLutSize { get; } public SerializedProperty useFastSRGBLinearConversion { get; } +#if ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER public SerializedProperty useAdaptivePerformance { get; } - +#endif public UniversalRenderPipelineAsset asset { get; } public SerializedObject serializedObject { get; } @@ -129,8 +130,9 @@ public SerializedUniversalRenderPipelineAsset(SerializedObject serializedObject) useFastSRGBLinearConversion = serializedObject.FindProperty("m_UseFastSRGBLinearConversion"); +#if ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER useAdaptivePerformance = serializedObject.FindProperty("m_UseAdaptivePerformance"); - +#endif string Key = "Universal_Shadow_Setting_Unit:UI_State"; state = new EditorPrefBoolFlags(Key); } diff --git a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/UniversalRenderPipelineAssetUI.Drawers.cs b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/UniversalRenderPipelineAssetUI.Drawers.cs index 5ed4f8566d0..33cc3ee2758 100644 --- a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/UniversalRenderPipelineAssetUI.Drawers.cs +++ b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/UniversalRenderPipelineAssetUI.Drawers.cs @@ -107,7 +107,7 @@ static bool ValidateRendererGraphicsAPIs(UniversalRenderPipelineAsset pipelineAs CED.AdditionalPropertiesFoldoutGroup(Styles.shadowSettingsText, Expandable.Shadows, k_ExpandedState, ExpandableAdditional.Shadows, k_AdditionalPropertiesState, DrawShadows, DrawShadowsAdditional), CED.AdditionalPropertiesFoldoutGroup(Styles.postProcessingSettingsText, Expandable.PostProcessing, k_ExpandedState, ExpandableAdditional.PostProcessing, k_AdditionalPropertiesState, DrawPostProcessing, DrawPostProcessingAdditional) #if ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER - , CED.FoldoutGroup(Styles.adaptivePerformanceText, Expandable.AdaptivePerformance, k_ExpandedState, CED.Group(DrawAdvanced)), + , CED.FoldoutGroup(Styles.adaptivePerformanceText, Expandable.AdaptivePerformance, k_ExpandedState, CED.Group(DrawAdaptivePerformance)) #endif ); @@ -472,9 +472,8 @@ static void DrawPostProcessingAdditional(SerializedUniversalRenderPipelineAsset #if ADAPTIVE_PERFORMANCE_2_0_0_OR_NEWER static void DrawAdaptivePerformance(SerializedUniversalRenderPipelineAsset serialized, Editor ownerEditor) { - EditorGUILayout.PropertyField(m_UseAdaptivePerformance, Styles.useAdaptivePerformance); + EditorGUILayout.PropertyField(serialized.useAdaptivePerformance, Styles.useAdaptivePerformance); } - #endif } } diff --git a/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs b/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs index f874bfad563..4f87708853c 100644 --- a/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs +++ b/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs @@ -918,13 +918,20 @@ public bool useAdaptivePerformance set { m_UseAdaptivePerformance = value; } } + /// + /// Set to true to enable a conservative method for calculating the size and position of the minimal enclosing sphere around the frustum cascade corner points for shadow culling. + /// public bool conservativeEnclosingSphere { get { return m_ConservativeEnclosingSphere; } set { m_ConservativeEnclosingSphere = value; } } - public int numItertionsEnclosingSphere + /// + /// Set the number of iterations to reduce the cascade culling enlcosing sphere to be closer to the absolute minimun enclosing sphere, but will also require more CPU computation for increasing values. + /// This parameter is used only when conservativeEnclosingSphere is set to true. Default value is 64. + /// + public int numIterationsEnclosingSphere { get { return m_NumIterationsEnclosingSphere; } set { m_NumIterationsEnclosingSphere = value; } diff --git a/com.unity.render-pipelines.universal/Runtime/ForwardLights.cs b/com.unity.render-pipelines.universal/Runtime/ForwardLights.cs index 1dc4a6cd8ba..7a4f6ecb50c 100644 --- a/com.unity.render-pipelines.universal/Runtime/ForwardLights.cs +++ b/com.unity.render-pipelines.universal/Runtime/ForwardLights.cs @@ -353,10 +353,11 @@ public void Setup(ScriptableRenderContext context, ref RenderingData renderingDa SetupShaderLightConstants(cmd, ref renderingData); + bool lightCountCheck = (renderingData.cameraData.renderer.stripAdditionalLightOffVariants && renderingData.lightData.supportsAdditionalLights) || additionalLightsCount > 0; CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.AdditionalLightsVertex, - additionalLightsCount > 0 && additionalLightsPerVertex && !useClusteredRendering); + lightCountCheck && additionalLightsPerVertex && !useClusteredRendering); CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.AdditionalLightsPixel, - additionalLightsCount > 0 && !additionalLightsPerVertex && !useClusteredRendering); + lightCountCheck && !additionalLightsPerVertex && !useClusteredRendering); CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.ClusteredRendering, useClusteredRendering); diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/AdditionalLightsShadowCasterPass.cs b/com.unity.render-pipelines.universal/Runtime/Passes/AdditionalLightsShadowCasterPass.cs index 0d7b638fd26..c7050766841 100644 --- a/com.unity.render-pipelines.universal/Runtime/Passes/AdditionalLightsShadowCasterPass.cs +++ b/com.unity.render-pipelines.universal/Runtime/Passes/AdditionalLightsShadowCasterPass.cs @@ -48,6 +48,12 @@ public ShadowResolutionRequest(int _visibleLightIndex, int _perLightShadowSliceI } } + /// + /// x is used in RenderAdditionalShadowMapAtlas to skip shadow map rendering for non-shadow-casting lights. + /// w is perLightFirstShadowSliceIndex, used in Lighting shader to find if Additional light casts shadows. + /// + readonly static Vector4 c_DefaultShadowParams = new Vector4(0, 0, 0, -1); + static int m_AdditionalLightsWorldToShadow_SSBO; static int m_AdditionalShadowParams_SSBO; bool m_UseStructuredBuffer; @@ -76,6 +82,8 @@ public ShadowResolutionRequest(int _visibleLightIndex, int _perLightShadowSliceI int[] m_VisibleLightIndexToSortedShadowResolutionRequestsFirstSliceIndex = null; // for each visible light, store the index of its first shadow slice in m_SortedShadowResolutionRequests (for quicker access) List m_UnusedAtlasSquareAreas = new List(); // this list tracks space available in the atlas + bool m_CreateEmptyShadowmap; + bool m_SupportsBoxFilterForShadows; ProfilingSampler m_ProfilingSetupSampler = new ProfilingSampler("Setup Additional Shadows"); @@ -608,11 +616,8 @@ public bool Setup(ref RenderingData renderingData) m_AdditionalLightShadowSliceIndexTo_WorldShadowMatrix = new Matrix4x4[totalShadowSlicesCount]; // initialize _AdditionalShadowParams - Vector4 defaultShadowParams = new Vector4(0 /*shadowStrength*/, 0, 0, -1 /*perLightFirstShadowSliceIndex*/); - // shadowParams.x is used in RenderAdditionalShadowMapAtlas to skip shadow map rendering for non-shadow-casting lights - // shadowParams.w is used in Lighting shader to find if Additional light casts shadows for (int i = 0; i < maxAdditionalLightShadowParams; ++i) - m_AdditionalLightIndexToShadowParams[i] = defaultShadowParams; + m_AdditionalLightIndexToShadowParams[i] = c_DefaultShadowParams; int validShadowCastingLightsCount = 0; bool supportsSoftShadows = renderingData.shadowData.supportsSoftShadows; @@ -731,7 +736,7 @@ public bool Setup(ref RenderingData renderingData) // Lights that need to be rendered in the shadow map atlas if (validShadowCastingLightsCount == 0) - return false; + return SetupForEmptyRendering(ref renderingData); int shadowCastingLightsBufferCount = m_ShadowSliceToAdditionalLightIndex.Count; @@ -786,6 +791,24 @@ public bool Setup(ref RenderingData renderingData) m_AdditionalLightsShadowmapTexture = ShadowUtils.GetTemporaryShadowTexture(renderTargetWidth, renderTargetHeight, k_ShadowmapBufferBits); m_MaxShadowDistanceSq = renderingData.cameraData.maxShadowDistance * renderingData.cameraData.maxShadowDistance; m_CascadeBorder = renderingData.shadowData.mainLightShadowCascadeBorder; + m_CreateEmptyShadowmap = false; + useNativeRenderPass = true; + + return true; + } + + bool SetupForEmptyRendering(ref RenderingData renderingData) + { + if (!renderingData.cameraData.renderer.stripShadowsOffVariants) + return false; + + m_AdditionalLightsShadowmapTexture = ShadowUtils.GetTemporaryShadowTexture(1, 1, k_ShadowmapBufferBits); + m_CreateEmptyShadowmap = true; + useNativeRenderPass = false; + + // initialize _AdditionalShadowParams + for (int i = 0; i < m_AdditionalLightIndexToShadowParams.Length; ++i) + m_AdditionalLightIndexToShadowParams[i] = c_DefaultShadowParams; return true; } @@ -799,6 +822,12 @@ public override void Configure(CommandBuffer cmd, RenderTextureDescriptor camera /// public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { + if (m_CreateEmptyShadowmap) + { + SetEmptyAdditionalShadowmapAtlas(ref context); + return; + } + if (renderingData.shadowData.supportsAdditionalLightShadows) RenderAdditionalShadowmapAtlas(ref context, ref renderingData.cullResults, ref renderingData.lightData, ref renderingData.shadowData); } @@ -832,6 +861,24 @@ void Clear() m_AdditionalLightsShadowmapTexture = null; } + void SetEmptyAdditionalShadowmapAtlas(ref ScriptableRenderContext context) + { + CommandBuffer cmd = CommandBufferPool.Get(); + CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.AdditionalLightShadows, true); + if (RenderingUtils.useStructuredBuffer) + { + var shadowParamsBuffer = ShaderData.instance.GetAdditionalLightShadowParamsStructuredBuffer(m_AdditionalLightIndexToShadowParams.Length); + shadowParamsBuffer.SetData(m_AdditionalLightIndexToShadowParams); + cmd.SetGlobalBuffer(m_AdditionalShadowParams_SSBO, shadowParamsBuffer); + } + else + { + cmd.SetGlobalVectorArray(AdditionalShadowsConstantBuffer._AdditionalShadowParams, m_AdditionalLightIndexToShadowParams); + } + context.ExecuteCommandBuffer(cmd); + CommandBufferPool.Release(cmd); + } + void RenderAdditionalShadowmapAtlas(ref ScriptableRenderContext context, ref CullingResults cullResults, ref LightData lightData, ref ShadowData shadowData) { NativeArray visibleLights = lightData.visibleLights; diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/MainLightShadowCasterPass.cs b/com.unity.render-pipelines.universal/Runtime/Passes/MainLightShadowCasterPass.cs index 93f653a3846..5afe3b6a859 100644 --- a/com.unity.render-pipelines.universal/Runtime/Passes/MainLightShadowCasterPass.cs +++ b/com.unity.render-pipelines.universal/Runtime/Passes/MainLightShadowCasterPass.cs @@ -38,6 +38,8 @@ private static class MainLightShadowConstantBuffer ShadowSliceData[] m_CascadeSlices; Vector4[] m_CascadeSplitDistances; + bool m_CreateEmptyShadowmap; + ProfilingSampler m_ProfilingSetupSampler = new ProfilingSampler("Setup Main Shadowmap"); public MainLightShadowCasterPass(RenderPassEvent evt) @@ -71,17 +73,17 @@ public bool Setup(ref RenderingData renderingData) using var profScope = new ProfilingScope(null, m_ProfilingSetupSampler); if (!renderingData.shadowData.supportsMainLightShadows) - return false; + return SetupForEmptyRendering(ref renderingData); Clear(); int shadowLightIndex = renderingData.lightData.mainLightIndex; if (shadowLightIndex == -1) - return false; + return SetupForEmptyRendering(ref renderingData); VisibleLight shadowLight = renderingData.lightData.visibleLights[shadowLightIndex]; Light light = shadowLight.light; if (light.shadows == LightShadows.None) - return false; + return SetupForEmptyRendering(ref renderingData); if (shadowLight.lightType != LightType.Directional) { @@ -90,7 +92,7 @@ public bool Setup(ref RenderingData renderingData) Bounds bounds; if (!renderingData.cullResults.GetShadowCasterBounds(shadowLightIndex, out bounds)) - return false; + return SetupForEmptyRendering(ref renderingData); m_ShadowCasterCascadesCount = renderingData.shadowData.mainLightShadowCascadesCount; @@ -108,12 +110,26 @@ public bool Setup(ref RenderingData renderingData) out m_CascadeSplitDistances[cascadeIndex], out m_CascadeSlices[cascadeIndex]); if (!success) - return false; + return SetupForEmptyRendering(ref renderingData); } m_MainLightShadowmapTexture = ShadowUtils.GetTemporaryShadowTexture(renderTargetWidth, renderTargetHeight, k_ShadowmapBufferBits); m_MaxShadowDistanceSq = renderingData.cameraData.maxShadowDistance * renderingData.cameraData.maxShadowDistance; m_CascadeBorder = renderingData.shadowData.mainLightShadowCascadeBorder; + m_CreateEmptyShadowmap = false; + useNativeRenderPass = true; + + return true; + } + + bool SetupForEmptyRendering(ref RenderingData renderingData) + { + if (!renderingData.cameraData.renderer.stripShadowsOffVariants) + return false; + + m_MainLightShadowmapTexture = ShadowUtils.GetTemporaryShadowTexture(1, 1, k_ShadowmapBufferBits); + m_CreateEmptyShadowmap = true; + useNativeRenderPass = false; return true; } @@ -127,6 +143,12 @@ public override void Configure(CommandBuffer cmd, RenderTextureDescriptor camera /// public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { + if (m_CreateEmptyShadowmap) + { + SetEmptyMainLightCascadeShadowmap(ref context); + return; + } + RenderMainLightCascadeShadowmap(ref context, ref renderingData.cullResults, ref renderingData.lightData, ref renderingData.shadowData); } @@ -157,6 +179,19 @@ void Clear() m_CascadeSlices[i].Clear(); } + void SetEmptyMainLightCascadeShadowmap(ref ScriptableRenderContext context) + { + CommandBuffer cmd = CommandBufferPool.Get(); + CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MainLightShadows, true); + cmd.SetGlobalTexture(m_MainLightShadowmap.id, m_MainLightShadowmapTexture); + cmd.SetGlobalVector(MainLightShadowConstantBuffer._ShadowParams, + new Vector4(1, 0, 1, 0)); + cmd.SetGlobalVector(MainLightShadowConstantBuffer._ShadowmapSize, + new Vector4(1f / m_MainLightShadowmapTexture.width, 1f / m_MainLightShadowmapTexture.height, m_MainLightShadowmapTexture.width, m_MainLightShadowmapTexture.height)); + context.ExecuteCommandBuffer(cmd); + CommandBufferPool.Release(cmd); + } + void RenderMainLightCascadeShadowmap(ref ScriptableRenderContext context, ref CullingResults cullResults, ref LightData lightData, ref ShadowData shadowData) { int shadowLightIndex = lightData.mainLightIndex; diff --git a/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs b/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs index 13b7921386e..a69f7b6d9d2 100644 --- a/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs +++ b/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs @@ -489,6 +489,10 @@ internal static void ConfigureActiveTarget(RenderTargetIdentifier colorAttachmen internal bool useDepthPriming { get; set; } = false; + internal bool stripShadowsOffVariants { get; set; } = false; + + internal bool stripAdditionalLightOffVariants { get; set; } = false; + public ScriptableRenderer(ScriptableRendererData data) { if (Debug.isDebugBuild) diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs index ec7279ff438..be5915726cf 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs @@ -1100,6 +1100,7 @@ static void InitializeLightData(UniversalRenderPipelineAsset settings, NativeArr lightData.maxPerObjectAdditionalLightsCount = 0; } + lightData.supportsAdditionalLights = settings.additionalLightsRenderingMode != LightRenderingMode.Disabled; lightData.shadeAdditionalLightsPerVertex = settings.additionalLightsRenderingMode == LightRenderingMode.PerVertex; lightData.visibleLights = visibleLights; lightData.supportsMixedLighting = settings.supportsMixedLighting; diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs index 41f07e5c61a..504730cf2fe 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs @@ -43,6 +43,11 @@ public struct LightData public bool reflectionProbeBoxProjection; public bool reflectionProbeBlending; public bool supportsLightLayers; + + /// + /// True if additional lights enabled. + /// + public bool supportsAdditionalLights; } public struct CameraData diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs index b3b0496438f..e55c91b7d64 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs @@ -158,6 +158,9 @@ public UniversalRenderer(UniversalRendererData data) : base(data) m_LightCookieManager = new LightCookieManager(ref settings); } + this.stripShadowsOffVariants = true; + this.stripAdditionalLightOffVariants = true; + ForwardLights.InitParams forwardInitParams; forwardInitParams.lightCookieManager = m_LightCookieManager; forwardInitParams.clusteredRendering = data.clusteredRendering; @@ -179,6 +182,7 @@ public UniversalRenderer(UniversalRendererData data) : base(data) // we inject the builtin passes in the before events. m_MainLightShadowCasterPass = new MainLightShadowCasterPass(RenderPassEvent.BeforeRenderingShadows); m_AdditionalLightsShadowCasterPass = new AdditionalLightsShadowCasterPass(RenderPassEvent.BeforeRenderingShadows); + #if ENABLE_VR && ENABLE_XR_MODULE m_XROcclusionMeshPass = new XROcclusionMeshPass(RenderPassEvent.BeforeRenderingOpaques); // Schedule XR copydepth right after m_FinalBlitPass(AfterRendering + 1) @@ -509,9 +513,6 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re bool useDepthPriming = (m_DepthPrimingRecommended && m_DepthPrimingMode == DepthPrimingMode.Auto) || (m_DepthPrimingMode == DepthPrimingMode.Forced); useDepthPriming &= requiresDepthPrepass && (createDepthTexture || createColorTexture) && m_RenderingMode == RenderingMode.Forward && (cameraData.renderType == CameraRenderType.Base || cameraData.clearDepth); - // Temporarily disable depth priming on certain platforms such as Vulkan because we lack proper depth resolve support. - useDepthPriming &= SystemInfo.graphicsDeviceType != GraphicsDeviceType.Vulkan || cameraTargetDescriptor.msaaSamples == 1; - if (useRenderPassEnabled || useDepthPriming) { createDepthTexture |= createColorTexture; @@ -909,7 +910,7 @@ public override void SetupCullingParameters(ref ScriptableCullingParameters cull cullingParameters.conservativeEnclosingSphere = UniversalRenderPipeline.asset.conservativeEnclosingSphere; - cullingParameters.numIterationsEnclosingSphere = UniversalRenderPipeline.asset.numItertionsEnclosingSphere; + cullingParameters.numIterationsEnclosingSphere = UniversalRenderPipeline.asset.numIterationsEnclosingSphere; } /// diff --git a/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLit.shader b/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLit.shader index 6873d0b9b0d..756c1c10d03 100644 --- a/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLit.shader +++ b/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLit.shader @@ -177,7 +177,7 @@ Shader "Universal Render Pipeline/Particles/Simple Lit" // Universal Pipeline keywords #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN //#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS - #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS + //#pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS #pragma multi_compile_fragment _ _SHADOWS_SOFT #pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT #pragma multi_compile_fragment _ _RENDER_PASS_ENABLED diff --git a/com.unity.render-pipelines.universal/Shaders/Utils/ScreenSpaceShadows.shader b/com.unity.render-pipelines.universal/Shaders/Utils/ScreenSpaceShadows.shader index ff8d122af33..ed8620e3f39 100644 --- a/com.unity.render-pipelines.universal/Shaders/Utils/ScreenSpaceShadows.shader +++ b/com.unity.render-pipelines.universal/Shaders/Utils/ScreenSpaceShadows.shader @@ -56,15 +56,14 @@ Shader "Hidden/Universal Render Pipeline/ScreenSpaceShadows" deviceDepth = deviceDepth * 2.0 - 1.0; #endif - float3 wpos = ComputeWorldSpacePosition(input.uv.xy, deviceDepth, unity_MatrixInvVP); - //Fetch shadow coordinates for cascade. + float3 wpos = ComputeWorldSpacePosition(input.uv.xy, deviceDepth, unity_MatrixInvVP); float4 coords = TransformWorldToShadowCoord(wpos); // Screenspace shadowmap is only used for directional lights which use orthogonal projection. - ShadowSamplingData shadowSamplingData = GetMainLightShadowSamplingData(); - half4 shadowParams = GetMainLightShadowParams(); - return SampleShadowmap(TEXTURE2D_ARGS(_MainLightShadowmapTexture, sampler_MainLightShadowmapTexture), coords, shadowSamplingData, shadowParams, false); + half realtimeShadow = MainLightRealtimeShadow(coords); + + return realtimeShadow; } ENDHLSL diff --git a/com.unity.shadergraph/Editor/Generation/TargetResources/FieldDependencies.cs b/com.unity.shadergraph/Editor/Generation/TargetResources/FieldDependencies.cs index 6d7e76e86ad..1e5ca9ddeaa 100644 --- a/com.unity.shadergraph/Editor/Generation/TargetResources/FieldDependencies.cs +++ b/com.unity.shadergraph/Editor/Generation/TargetResources/FieldDependencies.cs @@ -101,8 +101,8 @@ internal static class FieldDependencies new FieldDependency(StructFields.SurfaceDescriptionInputs.TangentSpaceViewDirection, StructFields.SurfaceDescriptionInputs.WorldSpaceNormal), new FieldDependency(StructFields.SurfaceDescriptionInputs.ScreenPosition, StructFields.SurfaceDescriptionInputs.WorldSpacePosition), - // new FieldDependency(StructFields.SurfaceDescriptionInputs.PixelPosition, StructFields.Varyings.vpos), - new FieldDependency(StructFields.SurfaceDescriptionInputs.NDCPosition, StructFields.SurfaceDescriptionInputs.PixelPosition), + new FieldDependency(StructFields.SurfaceDescriptionInputs.NDCPosition, StructFields.SurfaceDescriptionInputs.PixelPosition), // for non-XR + new FieldDependency(StructFields.SurfaceDescriptionInputs.NDCPosition, StructFields.SurfaceDescriptionInputs.ScreenPosition), // for XR new FieldDependency(StructFields.SurfaceDescriptionInputs.uv0, StructFields.Varyings.texCoord0), new FieldDependency(StructFields.SurfaceDescriptionInputs.uv1, StructFields.Varyings.texCoord1), diff --git a/com.unity.testing.urp/Scripts/Runtime/CustomRenderPipeline/CustomRenderer.cs b/com.unity.testing.urp/Scripts/Runtime/CustomRenderPipeline/CustomRenderer.cs index c31e61e99a9..363abb1bd00 100644 --- a/com.unity.testing.urp/Scripts/Runtime/CustomRenderPipeline/CustomRenderer.cs +++ b/com.unity.testing.urp/Scripts/Runtime/CustomRenderPipeline/CustomRenderer.cs @@ -4,14 +4,21 @@ namespace UnityEngine.Rendering.Universal { public class CustomRenderer : ScriptableRenderer { - private DrawObjectsPass m_RenderOpaqueForwardPass; - + DrawObjectsPass m_RenderOpaqueForwardPass; ForwardLights m_ForwardLights; + MainLightShadowCasterPass m_MainLightShadowCasterPass; + AdditionalLightsShadowCasterPass m_AdditionalLightsShadowCasterPass; public CustomRenderer(CustomRenderGraphData data) : base(data) { - m_RenderOpaqueForwardPass = new DrawObjectsPass("Render Opaques", true, RenderPassEvent.BeforeRenderingOpaques + 1, RenderQueueRange.opaque, -1, StencilState.defaultValue, 0); + stripShadowsOffVariants = true; + stripAdditionalLightOffVariants = true; + m_ForwardLights = new ForwardLights(); + + m_RenderOpaqueForwardPass = new DrawObjectsPass("Render Opaques", true, RenderPassEvent.BeforeRenderingOpaques + 1, RenderQueueRange.opaque, -1, StencilState.defaultValue, 0); + m_MainLightShadowCasterPass = new MainLightShadowCasterPass(RenderPassEvent.BeforeRenderingShadows); + m_AdditionalLightsShadowCasterPass = new AdditionalLightsShadowCasterPass(RenderPassEvent.BeforeRenderingShadows); } public override void Setup(ScriptableRenderContext context, ref RenderingData renderingData) @@ -21,6 +28,14 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re foreach (var feature in rendererFeatures) feature.AddRenderPasses(this, ref renderingData); EnqueuePass(m_RenderOpaqueForwardPass); + + bool mainLightShadows = m_MainLightShadowCasterPass.Setup(ref renderingData); + bool additionalLightShadows = m_AdditionalLightsShadowCasterPass.Setup(ref renderingData); + + if (mainLightShadows) + EnqueuePass(m_MainLightShadowCasterPass); + if (additionalLightShadows) + EnqueuePass(m_AdditionalLightsShadowCasterPass); } public override void SetupLights(ScriptableRenderContext context, ref RenderingData renderingData)