Skip to content

[14.x.x] LOD Cross Fade #6754

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

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open

Conversation

alekseiunity
Copy link
Contributor

@alekseiunity alekseiunity commented Jan 14, 2022


Purpose of this PR

Currently in URP Mesh LOD switch inside LODGroup occurs immediately which frustrates the users as this ‘immediate’ switch looks like a sharp pop of a new object.
To improve that we need a mechanism to smooth transition or crossfade from one mesh to another. This could be achieved by using alpha test dithering mask crossfade https://en.wikipedia.org/wiki/Dither. Dithering mask, by using clip() or discard() function in a Pixel Shader, decreases total number of visible pixels of one Mesh LOD and increases total number of visible pixels of another Mesh LOD and smoothly crossfades two Meshes.

I propose to make 3 types of LOD Cross Fade dithering and allow user to choose the type in UniversalRenderPipelineAsset.

LOD Cross Fade types are:

  1. Bayer Matrix Dither
    This is used in Built In renderer and very cheap but has quite repetitive pattern.

  1. Blue Noise Dither
    This uses precomputed blue noise texture and provides best looking option but a bit more expensive than Bayer Matrix.

Test Scene Video: No Cross Fade - https://drive.google.com/file/d/1McO6CH33eNrBj3sCBtoOQHEUdXAuTdgf/view?usp=sharing
Test Scene Video: With Cross Fade - https://drive.google.com/file/d/1GNEjY3xh3DgzCslKawmfWGcwG3IDIHdp/view?usp=sharing


Testing status

Tested on PC, Mac, Android, iOS and PS5 using my own synthetic scene with lots of objects.
Performance results are here. https://docs.google.com/spreadsheets/d/1r4EmXtUQMD3EYhFsDjfA2AE1tcx-MzzC110StR_guII/edit?usp=sharing


Comments to reviewers


Additional Alpha To Coverage improvement

When MSAA is enabled in forward renderer. We can additionally use Alpha To Coverage to improve transition between LOD even more by writing dithering value to alpha. In that case transition looks a bit like alpha blended.
We can integrate that later as soon as #6312 will be merged.

@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://unity-ci.cds.internal.unity3d.com/project/902/
Search for your PR branch using the search bar at the top, 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
/jobDefinition/.yamato%252Fall-urp.yml%2523PR_URP_trunk
With changes to URP packages, you should also run
/jobDefinition/.yamato%2Fall-lightmapping.yml%23PR_Lightmapping_trunk

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.

@@ -1234,6 +1255,18 @@ static void UpgradeAsset(int assetInstanceID)
asset.k_AssetPreviousVersion = 10;
}

if(asset.k_AssetPreviousVersion < 11)
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this a correct way to Reload PostProcessingData asset that now has to have links to blue noise and bayer matrix texture?

Choose a reason for hiding this comment

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

Is this a correct way to Reload PostProcessingData asset that now has to have links to blue noise and bayer matrix texture?

Moved textures to the asset itself as post processing data might not be assigned at all.

@@ -59,6 +58,8 @@ float4 DepthNormalsFragment(Varyings input) : SV_TARGET
half alpha = texColor.a * _BaseColor.a;
AlphaDiscard(alpha, _Cutoff);

LODFadeCrossFade(input.positionCS);
Copy link
Contributor Author

@alekseiunity alekseiunity Jan 14, 2022

Choose a reason for hiding this comment

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

For some reason I have to put this always after alpha discard otherwise there is a weird behavior on iOS for AlphaTest shaders.

@Aydindeveloper

This comment has been minimized.

@Verasl Verasl self-requested a review January 28, 2022 09:05
# Conflicts:
#	com.unity.render-pipelines.universal/CHANGELOG.md
#	com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/UniversalRenderPipelineAssetUI.Drawers.cs
#	com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineAsset/UniversalRenderPipelineAssetUI.Skin.cs
#	com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs
@alekseiunity alekseiunity changed the title Graphics/URP LOD Cross Fade [14.x.x] LOD Cross Fade Jan 31, 2022
@alekseiunity alekseiunity marked this pull request as ready for review January 31, 2022 19:31
@alekseiunity alekseiunity requested a review from a team as a code owner January 31, 2022 19:31
@alekseiunity alekseiunity requested a review from a team January 31, 2022 19:33
@sebastienlagarde
Copy link
Contributor

Just a comment mainly for Universal team.

Due to the limit on number of shader permutations we can't afford to select Cross Fade Type based on a keyword like:
#pragma multi_compile _ LOD_FADE_CROSSFADE_TYPE_BAYER_MATRIX
(Or can we?)

in HDRP LOD_FADE is a build time killer as it affect all our passes (both deferred adn forward, shadow, depth prepass etc...). So it is the worse thing that we can do for build time and sadly with current fading algorithm use in unity we have no choice.
So for sure you don't want to add more variant with extra option, so good you used constant buffer. But you should also really consider the addition of an option to strip those variant in the RP settings.

in HDRP we have added a supportDitheringCrossFade to allow to discard all those extra variant AND on ShaderGraph we have added an option to generate or not this multicompile (sadly we can't do this with non shader graph shader).

So for reviewer of this PR, be really consicous about the build time involve by this change! :)

@alekseiunity
Copy link
Contributor Author

Just a comment mainly for Universal team.

Due to the limit on number of shader permutations we can't afford to select Cross Fade Type based on a keyword like:
#pragma multi_compile _ LOD_FADE_CROSSFADE_TYPE_BAYER_MATRIX
(Or can we?)

in HDRP LOD_FADE is a build time killer as it affect all our passes (both deferred adn forward, shadow, depth prepass etc...). So it is the worse thing that we can do for build time and sadly with current fading algorithm use in unity we have no choice. So for sure you don't want to add more variant with extra option, so good you used constant buffer. But you should also really consider the addition of an option to strip those variant in the RP settings.

in HDRP we have added a supportDitheringCrossFade to allow to discard all those extra variant AND on ShaderGraph we have added an option to generate or not this multicompile (sadly we can't do this with non shader graph shader).

So for reviewer of this PR, be really consicous about the build time involve by this change! :)

Yeah I think adding shader variant strip makes sense. Will add it.

@simon-engelbrecht-soerensen simon-engelbrecht-soerensen requested review from simon-engelbrecht-soerensen and removed request for a team February 8, 2022 16:03
Copy link

Choose a reason for hiding this comment

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

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.

6 participants