Skip to content

Conversation

Wilfrid-Unity
Copy link
Contributor

@Wilfrid-Unity Wilfrid-Unity commented Mar 11, 2021

Purpose of this PR

#2126 added to Universal RP support for custom shadow resolution for additional lights.
When a Universal RP project is upgraded to a Universal RP package containing those changes, its UniversalRenderPipeline Assets get new "Shadow Resolution Tiers" fields added with default values 256/512/1024 ; and its spot light shadows get assigned the lowest tier resolution.

The lower resolution might cause the visual quality of spot light shadows in a project to look worse after the upgrade.

This pull request ensures that after upgrade, spot light shadows will keep using the same resolution.
This is done by using the highest tier resolution as default.

Taking inspiration from@Verasl suggestion, during upgrade the 3 tier resolutions are also modified according to the additional light shadow atlas resolution set in the asset (respectively: full-res, half-res, quarter res if possible).


Testing status

In a test scene based on UniversalRP template scene added with shadowed spot lights, I locally checked that the changes in this pull request effectively conserve spot light shadow resolutions after the upgrade to Unity 2021.


Comments to reviewers

Effort tracked by internal ticket https://fogbugz.unity3d.com/f/cases/1316540

2021.1 backport pull-request: #3832

@github-actions
Copy link

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!

Copy link
Contributor

@Verasl Verasl left a comment

Choose a reason for hiding this comment

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

LGTM

@Verasl Verasl self-requested a review March 16, 2021 08:34
Copy link
Contributor

@Verasl Verasl left a comment

Choose a reason for hiding this comment

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

Some minor changes to the upgrader, seems like a merge issue, we really need to update this upgrader, a bunch of 'ifs' is not the way :(

k_AssetVersion = 7;
}

if (k_AssetVersion < 8)
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems there was a merge issue at some point and we have ended up with 2 version 8 upgraders, this one needs to be 9 and moved after the version 8 below it

Copy link
Contributor

Choose a reason for hiding this comment

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

and further down in static void UpgradeAsset(UniversalRenderPipelineAsset asset) we need to bump the last check to be version 9 not 8 too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for noticing this.

I fixed it in 1b2caec, can you please check the change?

Should I also bump the version numbers in UpgradeAsset in the 2021.1 backport PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Fix looks good, for now we have to hold off back porting to 21.1 since it seems there is another upgrader that hasn't been back ported, this would cause some severe issues with users so I'm looking to get answers on what to do here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the info about 21.1.
It seems that it would be better if both 2021.2 (this PR) and 2021.1 (backport PR) landed together at the same time?
Please notify when you know what more we should do for 21.1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lukaschod
Will #3089 be back-ported to branch https://github.com/Unity-Technologies/Graphics/tree/2021.1/staging ?

It seems that UniversalRenderPipelineAsset.k_AssetVersion = 8 means "UniversalRenderPipelineAsset version containing improved shadow fade settings".

(With the current PR, we would have UniversalRenderPipelineAsset.k_AssetVersion = 9 meaning "UniversalRenderPipelineAsset version containing auto-upgraded spot light shadow resolutions".)

Having "auto-upgraded spot light shadow resolutions" available in 2021.2 but not in 2021.1 might be surprising for users ("when upgrading project to 2021.1 nothing happened, but it changed when upgrading again to 2021.2!?"). Therefore I would like to land both pull requests #3831 and #3832 together.

@lukaschod
If you plan to back-port #3089 to 2021.1, then #3832 has to wait (because asset update must happen in increasing version order).
If you don't plan to back-port #3089 to 2021.1, then on 2021.1 we can directly skip UniversalRenderPipelineAsset.k_AssetVersion from 7 to 9, and we will be able to land #3831 and #3832.
Please tell us, so that we can decide which path to take.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nop I do not plan to backport #3089. It has some core changes and I do not want to introduce that risk.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot for the info Lukas.

I updated UniversalRenderPipelineAsset.k_AssetVersion in my 2021.1 backport pull request to match with this pull request (2021.2).

Copy link

Choose a reason for hiding this comment

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

Appears to be working.

Copy link
Contributor

@Verasl Verasl left a comment

Choose a reason for hiding this comment

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

LGTM

var fieldSlot = new Rect(contentRect.x + pixelShift, contentRect.y, num - labelWidth, contentRect.height); // Define the rectangle for the field
int value = EditorGUI.DelayedIntField(fieldSlot, values[index].intValue);
values[index].intValue = Mathf.Max(128, Mathf.NextPowerOfTwo(value));
values[index].intValue = Mathf.Max(UniversalAdditionalLightData.AdditionalLightsShadowMinimumResolution, Mathf.NextPowerOfTwo(value));
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't from this change, but we really need to get away from defaulting to power of two sizes. Most modern GPU architectures support non power of two sizes, and it is only really relevant for mipmaps and compressed formats.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it is a atlas fitting limitation, then it is a bit more understandable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, in the case of Additional Light shadows, it is a limitation of the current (simple) atlas fitting.

if (asset.k_AssetPreviousVersion < 8)
if (asset.k_AssetPreviousVersion < 9)
{
// The added feature was reverted, we keep this version to avoid breakage in case somebody already has version 7
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Comment needs updating. Should the comment be generic to say previous version instead of explicitly saying 7 or 8, etc.

Copy link
Contributor

@nigeljw-unity nigeljw-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

@Wilfrid-Unity Wilfrid-Unity requested a review from a team as a code owner March 25, 2021 10:30
…dditionalLightData.AdditionalLightsShadowMinimumResolution
…lues if it seems that they have never been customized (@Verasl suggestion)
…ltShadowResolutionTier... constant definitions outside of #if UNITY_EDITOR block
…nsparentReceiveShadow spot light shadow resolution to higher tier to match previous settings
@Verasl Verasl force-pushed the universal/additional-light-shadow-resolution-auto-upgrade branch from c92f728 to 43ed67d Compare March 25, 2021 10:48
@theopnv theopnv removed the request for review from a team March 25, 2021 16:16
internal const int k_ShadowCascadeMinCount = 1;
internal const int k_ShadowCascadeMaxCount = 4;

public static readonly int AdditionalLightsDefaultShadowResolutionTierLow = 256;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if I like constant tiers. It doesn't scale very well. IMO user should just be able to put a number or 2^N for pot. It' depends on the platform and content what's suitable.
This is not a deal breaker though.


if (k_AssetVersion < 9)
{
if (m_AdditionalLightsShadowResolutionTierHigh == AdditionalLightsDefaultShadowResolutionTierHigh &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a function "isCustomShadowResolution" or a local boolean at least.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, I added an intermediate variable in 82f939d

Wilfrid-Unity added a commit that referenced this pull request Apr 1, 2021
Copy link
Contributor

@lukaschod lukaschod 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

@phi-lira
Copy link
Contributor

phi-lira commented Apr 6, 2021

Lots of failed tests. Master should be failing only Hybrid Tests, maybe if you merge master and rerun it will give a better idea.

Wilfrid-Unity added a commit that referenced this pull request Apr 7, 2021
…ith the one in 2021.2 pull request - see conversation #3831 (comment)
@Wilfrid-Unity
Copy link
Contributor Author

Lots of failed tests. Master should be failing only Hybrid Tests, maybe if you merge master and rerun it will give a better idea.

Thanks for the info @phi-lira, I merged main branch and now there are no more failures, apart from Hybrid Tests (or Bokken test infrastructure issues not related to this pull request).

What about branch 2021.1/staging, are there some failures expected on that branch?

@Wilfrid-Unity
Copy link
Contributor Author

Everything looks OK on both 2021.2 and 2021.1, I'm merging the pull requests.

@Wilfrid-Unity Wilfrid-Unity merged commit db4edf6 into master Apr 9, 2021
@Wilfrid-Unity Wilfrid-Unity deleted the universal/additional-light-shadow-resolution-auto-upgrade branch April 9, 2021 03:58
Wilfrid-Unity added a commit that referenced this pull request Apr 9, 2021
…1 does not change Spot Light shadow resolutions (#3832)

* [UniversalRP] Replace some magic numbers by named variable UniversalAdditionalLightData.AdditionalLightsShadowMinimumResolution

* [UniversalRP] Make sure upgrading to Universal RP 2021 does not change Spot Light shadow resolutions (internal ticket https://fogbugz.unity3d.com/f/cases/1316540 )

* [UniversalRP] Only upgrade Additional Light Shadow Resolution Tier values if it seems that they have never been customized (@Verasl suggestion)

* [UniversalRP] Move UniversalRenderPipelineAsset.AdditionalLightsDefaultShadowResolutionTier... constant definitions outside of #if UNITY_EDITOR block

* [UniversalRP] Increase UniversalGraphicsTest_Foundation scene 105_TransparentReceiveShadow spot light shadow resolution to higher tier to match previous settings

* Fix asset that was incorrectly edited in e82aa3d

* Add local variable to make code easier to read (as suggested in #3831 (comment))

(cherry picked from commit 82f939d)

* Update UniversalRenderPipelineAsset.k_AssetPreviousVersion to match with the one in 2021.2 pull request - see conversation #3831 (comment)

* [UniversalRP] Increase UniversalGraphicsTest scene 105_TransparentReceiveShadow spot light shadow resolution to higher tier to match previous settings
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.

7 participants