-
Notifications
You must be signed in to change notification settings - Fork 855
Universal/custom shadow resolution for additional lights #2126
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
Conversation
…nt lights Like with spot lights, resolution for each shadow map is computed every frame in order to fit all of them in the common shadow atlas. Some of the current limitations: - ShadowBias possibly needs more precise values - FovBias possibly needs more precise values - Unused shadow faces allocate a slot in the common shadow atlas - Draw calls are generated even for shadow frustums that do not contain shadow casters - Not tested: Standalone players - Not tested: Dynamic scenes - Not tested: Performances - Not tested: Code path using Structured Buffers to pass shadow information to GPU (during shadow pass and lighting loop) - Not tested: Deferred Renderer
Normal bias for point lights now behaves similarly as for spot lights
…- This makes point light shadows look closer to spot light shadows
…dow normal bias - This fixes the issue of shadows that changed when point light was rotated. Built-In RP uses a similar approach to apply punctual light shadow normal bias. See UnityWorldSpaceLightDir called by UnityClipSpaceShadowCasterPos in UnityCG.cginc: https://github.cds.internal.unity3d.com/unity/unity/commit/93015b67a6e1afdfe00867fdd3a336eaa835f54d#diff-c2818feb2f37e566cf36ca5cab57a99eR533 https://github.cds.internal.unity3d.com/unity/unity/blob/93015b67a6e1afdfe00867fdd3a336eaa835f54d/External/shaderlab/CGIncludes/UnityCG.cginc#L76
…s, to avoid missing shadows at cube face boundaries
…adow data to the lighting shaders + Fixed indexing issue when using non-shadow-casting additional light Some known issues still happening: - If only a single light in the scene is set to use soft shadows, all punctual light shadows will be soft (even if their setting is "Hard") - Toggling setting "Soft Shadows" in UniversalRP asset also impacts shape of shadows from punctual light set to cast "Hard Shadows"
…salGraphicsTest suite
…ot light shadow's Normal Bias to match reference image - Since revision ed8fcbe Normal Bias is applied using actual spot light direction
… use per-vertex light direction when applying shadow normal bias)
… of Hard Shadows"
…t to ScriptableRenderContext.DrawShadows - Reduces the number of shadow casters rendered to the shadow map
…nd 143_SSAO_DepthNormals_Orthographic directional light shadows Normal Bias to match reference images - Since revision ed8fcbe formula to apply Normal Bias changed slightly
See also native-side changes introduced for Persistent Intermediate Renderer: https://github.cds.internal.unity3d.com/unity/unity/commit/89f4e3b https://github.cds.internal.unity3d.com/unity/unity/commit/fbe6025 https://github.cds.internal.unity3d.com/unity/unity/commit/8652678
…dditional light shadows Test fails if "hard shadows" setting is replaced by "soft shadows" setting Test fails if "soft shadows" setting is replaced by "hard shadows" setting Test fails if "no shadows" setting is replaced by "shadows" setting Test fails if one of the punctual lights in the scene is not rendered
…light angle" introduced in 1552692
…nstead of _ShadowCastingLightParameters from revision 6341928) This avoids deprecation of public variables, and makes code easier to understand Addresses comments: #1616 (comment) #1616 (comment) #1616 (comment)
Addresses comment #1616 (comment)
Addresses following comments: #1616 (comment) #1616 (comment) #1616 (comment)
Thanks @Verasl and @martint-unity for this suggestion, that makes a lot of sense when considering Universal RP restrictions. In this branch, I re-used the U.I implemented in HDRP in order to provide a unified experience between both Render Pipelines. When opening this pull request, I consulted @TheoWong-pixel who had commented the section about shadow resolution UI in the Tech Design Doc. Does this approach look OK to you? |
…order to match reference images
…ional Lights too Fixes "shadows popping" behavior illustrated by https://github.com/Unity-Technologies/BoatAttack/tree/testing/urp-pointlight-shadows, when changing PipelineAsset's "Shadows Max Distance" setting
…adow-resolution # Conflicts: # com.unity.render-pipelines.universal/Runtime/Passes/AdditionalLightsShadowCasterPass.cs
Solves issue described in https://docs.google.com/document/d/1tkQdYKx2bED5hp3dTmUlkeZS_moiUsRZeMS4hMXHfXk/edit#bookmark=id.dqn8fqx5f45 (i.e: repro by editing TestProjects/UniversalGraphicsTest/Assets/Scenes/010_AdditionalLightsSorted/SortedLightsTestPrefab.prefab to make the meshes cast shadows, and running UniversalGraphicsTest#010_AdditionalLightsSorted)
Solves issue happening when after procedure described in https://docs.google.com/document/d/1tkQdYKx2bED5hp3dTmUlkeZS_moiUsRZeMS4hMXHfXk/edit#bookmark=id.dqn8fqx5f45 (i.e: repro by editing TestProjects/UniversalGraphicsTest/Assets/Scenes/010_AdditionalLightsSorted/SortedLightsTestPrefab.prefab to make the meshes cast shadows, running UniversalGraphicsTest#010_AdditionalLightsSorted, and switching to Scene view)
See example in section "Unity function calls" of https://learn.unity.com/tutorial/fixing-performance-problems
# Conflicts: # TestProjects/UniversalGraphicsTest/Assets/Scenes/105_TransparentReceiveShadows.unity # com.unity.render-pipelines.universal/CHANGELOG.md # com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs # com.unity.render-pipelines.universal/Runtime/Passes/AdditionalLightsShadowCasterPass.cs
…hadow popping when scene uses more shadows than what the atlas can hold Mitigates issues illustrated by test scene https://github.com/Wilfrid-Unity/compare-rp-shadows/blob/master/urp-shadows/Assets/Scenes/010_ManyPointShadows.unity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAssetEditor.cs
Show resolved
Hide resolved
com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
We need to make sure we track the needed UX work in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found small issues (Addded as comments), but nothing serious to stop from merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Approved.
Purpose of this PR
This pull request allows Universal RP additional (i.e punctual) lights to specify custom shadow resolutions.
In current URP version, all additional (i.e punctual) shadowed lights use shadow maps of the same resolution (scaled to fit in the common shadow atlas).
Custom shadow resolutions make it possible to give more importance to some lights in the scene, ensuring their shadows will look as good as possible.
U.I and assets
The interface provided by this pull request to control shadow resolution ; is similar to the one used in HDRP.
Different shadow resolution tiers can be defined in the Universal RP asset file.
Each light in the scene can specify one of the different resolution tiers, or a custom resolution.
Assumptions and specs
Testing status
This pull request add test "146-AdditionalLightShadowCustomResolution" to the UniversalGraphicsTests suite, whose purpose is to check different shadow resolutions can be used.
Comments to reviewers
I started this work on top of branch universal/point-light-shadows.
Point Light Shadows branch has not yet been merged to trunk, pull request #1616 is still waiting for some approvals now.
To reduce the amount of changes to review, I created this draft pull request that currently only contains the commits related to custom shadow resolutions. The plan is to target it to trunk later (after #1616 has been merged).
I would appreciate reviews around the changes in UniversalRenderPipelineAsset.cs and the code that updates UniversalAdditionalLightData.