Skip to content

Conversation

nigeljw-unity
Copy link
Contributor

@nigeljw-unity nigeljw-unity commented May 4, 2021

Chicken bit for the minimal enclosing sphere frustum cascade culling stabilization fix, and also user control over the number of iterations for the iterative method for finding the minimal enclosing sphere from the 8 frustum cascade points. This fix makes it so that the culling spheres appropriately fully enclose the cascade. Since this is an iterative method, it is conservative. This fixes URP so there are not false positives when culling shadows.

image

https://jira.unity3d.com/browse/URP-782

Checklist for PR maker

  • Have you added a backport label (if needed)? For example, the need-backport-* label. After you backport the PR, the label changes to backported-*.
  • Have you updated the changelog? Each package has a CHANGELOG.md file.
  • Have you updated or added the documentation for your PR? When you add a new feature, change a property name, or change the behavior of a feature, it's best practice to include related documentation changes in the same PR. If you do add documentation, make sure to add the relevant Graphics Docs team member as a reviewer of the PR. If you are not sure which person to add, see the Docs team contacts sheet.
  • Have you added a graphic test for your PR (if needed)? When you add a new feature, or discover a bug that tests don't cover, please add a graphic test.

Purpose of this PR

Fixes bug where shadows disappear in the frustum corners from false positives in the shadow culling.
https://fogbugz.unity3d.com/f/cases/1153151

culling_bug

Also fixes inherent bug with shadow fade where the shadows will be culled with a hard line across the fade which is due to the same problem.

CullingSphere


Testing status

Tested with URP default template and custom cascade positioning.

culling_fix


Comments to reviewers

This PR is dependent on the following change to trunk:
https://github.cds.internal.unity3d.com/unity/unity/pull/2418

Design doc:
https://docs.google.com/document/d/10YxFKdA8YFS7QS8Owg2dvnYaM-t9tsLXWQLtiEXZQvQ

@nigeljw-unity nigeljw-unity requested a review from a team as a code owner May 4, 2021 20:13
@nigeljw-unity nigeljw-unity changed the base branch from universal/debug-cull-features to master May 4, 2021 20:13
@nigeljw-unity nigeljw-unity requested review from a team as code owners May 4, 2021 20:13
@github-actions github-actions bot added the sdet label May 4, 2021
@github-actions
Copy link

github-actions bot commented May 4, 2021

It appears that you made a non-draft PR!
Please convert your PR to draft (button on the right side of the page)
and cancel any jobs that started on Yamato.
See the PR template for more information.
Thank you!

@nigeljw-unity nigeljw-unity changed the title Debug culling render feature Minimal enclosing sphere fix May 4, 2021
@nigeljw-unity nigeljw-unity removed the request for review from a team May 4, 2021 21:11
@nigeljw-unity

This comment has been minimized.

@nigeljw-unity nigeljw-unity removed the sdet label May 5, 2021
@nigeljw-unity nigeljw-unity changed the base branch from master to universal/debug-cull-features May 7, 2021 08:01
@nigeljw-unity nigeljw-unity requested a review from a team July 7, 2021 13:11
@nigeljw-unity
Copy link
Contributor Author

@Unity-Technologies/gfx-qa-urp could I get a performance analysis of this change? I am curious if this potentially improves the rendering time of shadows due to the cascade culling sphere overlap removal.

Copy link
Contributor

@erikabar erikabar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URP QA got re-added again, approving

@nigeljw-unity
Copy link
Contributor Author

@nigeljw-unity nigeljw-unity requested a review from oleks-k August 5, 2021 09:38
@github-actions
Copy link

Hi! This comment will help you figure out which jobs to run before merging your PR. The suggestions are dynamic based on what files you have changed.
Link to Yamato: https://yamato.cds.internal.unity3d.com/jobs/902-Graphics
Search for your PR branch using the sidebar on the left, then add the following segment(s) to the end of the URL (you may need multiple tabs depending on how many packages you change)

URP
/.yamato%252Fall-urp.yml%2523PR_URP_2021.2

Depending on the scope of your PR, you may need to run more jobs than what has been suggested. Please speak to your lead or a Graphics SDET (#devs-graphics-automation) if you are unsure.

@nigeljw-unity
Copy link
Contributor Author

nigeljw-unity commented Aug 19, 2021

@simon-engelbrecht-soerensen @erikabar would either of you be able to do a quick sanity test of this latest PR? None of the logic changed so no need to test in depth, but there was a big merge conflict that I had to resolve.

Could you also verify that creating a new project has this enabled, and when upgrading old project, this is disabled?

instance.m_EditorResourcesAsset = instance.editorResources;

// Only enable for new URP assets by default
instance.m_ConservativeEnclosingSphere = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Verasl @phi-lira @eh-unity This is how I am enabling it only for new projects. Let me know if this is the right approach.

Copy link
Contributor

@eh-unity eh-unity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

public static GUIContent shadowDepthBias = EditorGUIUtility.TrTextContent("Depth Bias", "Controls the distance at which the shadows will be pushed away from the light. Useful for avoiding false self-shadowing artifacts.");
public static GUIContent shadowNormalBias = EditorGUIUtility.TrTextContent("Normal Bias", "Controls distance at which the shadow casting surfaces will be shrunk along the surface normal. Useful for avoiding false self-shadowing artifacts.");
public static GUIContent supportsSoftShadows = EditorGUIUtility.TrTextContent("Soft Shadows", "If enabled pipeline will perform shadow filtering. Otherwise all lights that cast shadows will fallback to perform a single shadow sample.");
public static GUIContent conservativeEnclosingSphere = EditorGUIUtility.TrTextContent("Conservative Enclosing Sphere", "If enabled, a conservative enclosing sphere is used. If disabled, the sphere will be smaller than the cascade size, and shadows will be culled in the corners of the cascades.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion:
EditorGUIUtility.TrTextContent("Conservative Enclosing Sphere", "Enable this option to improve shadow frustum culling. Enabling this option prevents Unity from excessively culling shadows in the corners of the shadow cascades. Disable this option only for compatibility purposes of projects created in previous Unity versions.");

Copy link
Contributor

@oleks-k oleks-k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@ellioman ellioman merged commit 9fd657c into master Sep 17, 2021
@ellioman ellioman deleted the universal/tight_enclosing_sphere branch September 17, 2021 15:14
nigeljw-unity added a commit that referenced this pull request Sep 20, 2021
Backport of minimal enclosing sphere solution for shadow frustum culling.

#4436

Co-authored-by: Erik Hakala <erik.hakala@unity3d.com>
Co-authored-by: Oleksandr Kokoshyn <oleksandr.kokoshyn@unity3d.com>
set { m_ConservativeEnclosingSphere = value; }
}

public int numItertionsEnclosingSphere
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit late to the party but there's a small spelling mistake here:

numItertionsEnclosingSphere -> numIterationsEnclosingSphere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants