[14.x.x] LOD Cross Fade by alekseiunity · Pull Request #6754 · Unity-Technologies/Graphics · GitHub
Skip to content

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

Open
alekseiunity wants to merge 29 commits into
masterfrom
graphics/urp-lod-cross-fade
Open

[14.x.x] LOD Cross Fade#6754
alekseiunity wants to merge 29 commits into
masterfrom
graphics/urp-lod-cross-fade

Conversation

@alekseiunity

@alekseiunity alekseiunity commented Jan 14, 2022

Copy link
Copy Markdown
Contributor

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
Copy Markdown

}

if(asset.k_AssetPreviousVersion < 11)
{

Copy link
Copy Markdown
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?

Copy link
Copy Markdown

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.

half alpha = texColor.a * _BaseColor.a;
AlphaDiscard(alpha, _Cutoff);

LODFadeCrossFade(input.positionCS);

@alekseiunity alekseiunity Jan 14, 2022

Copy link
Copy Markdown
Contributor Author

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
Comment thread com.unity.render-pipelines.universal/Runtime/Data/PostProcessData.asset.meta Outdated
# 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
Copy Markdown
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
Copy Markdown
Contributor Author

@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
Copy Markdown

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