Skip to content
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

Add dithering blend option between visibility range LODs (as a faster alternative to alpha fade) #5240

Open
josefkaragoli opened this issue Aug 24, 2022 · 7 comments

Comments

@josefkaragoli
Copy link

josefkaragoli commented Aug 24, 2022

Describe the project you are working on

A semi-open world making use of LODs

Describe the problem or limitation you are having in your project

Currently when switching between LODs there is a sharp and jarring transition between different levels of detail.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

As of godotengine/godot#50297 dithered alpha has been reimplemented and is now more performant - this, used in combination with LODs can reduce the artifacts of LOD switching. It does come at a performance cost, as two consecutive LODs have to be rendered at once, but used sparingly, the impact is outweighed by the improved visuals.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

In the StandardMaterial3D a new boolen parameter can be added (to ShaderMaterial too) which enables this. It should result in visuals like this:
https://couchlearn.com/fading-between-lods-in-unreal-engine-4/

If this enhancement will not be used often, can it be worked around with a few lines of script?

It is not possible to load two levels of detail at once which is required for this; if it is possible, it is likely very cumbersome.

Is there a reason why this should be core and not an add-on in the asset library?

It leverages and interacts with the built-in LOD system.

@Calinou
Copy link
Member

Calinou commented Aug 24, 2022

cc @JFonS

This requires adding a transparency mode for dithered alpha to BaseMaterial3D, which doesn't exist yet. Once this is done, Visibility Range > Fade Mode should have 2 new fade modes added (for a total of 5):

  • Disabled
  • Self Alpha (rename from Self)
  • Dependencies Alpha (rename from Dependencies)
  • Self Dither
  • Dependencies Dither

See also godotengine/godot#61880.

It is not possible to load two levels of detail at once which is required for this; if it is possible, it is likely very cumbersome.

This can already be implemented in 4.0.alpha1 using two different materials (with two sets of different distance fade properties), which is both a good thing and bad thing. Configure the visibility ranges to fully hide the materials after the fade transition distance to avoid visible pop-in.

It's a good thing because it allows you to use simpler materials for distant LODs. For instance, you can disable height mapping or even normal mapping to further improve performance (especially on mobile).

It's also a bad thing because it requires more manual setup, and has a performance impact as a result of having more materials (instead of reusing the same material). The visibility range approach will require less setup and won't require duplicating the material, so it'll be a bit faster in scenarios where you don't need a simpler material. If you do need a simpler material, you'll need to use the manual approach as I mentioned.

Footnotes

  1. This can also be done in 3.x with an add-on.

@Calinou Calinou changed the title Dither between LODs Add dithering blend option between visibility range LODs (as a faster alternative to alpha fade) Aug 24, 2022
@josefkaragoli
Copy link
Author

I think it would be beneficial to have this documented, I just tried it now and it does mitigate the issue.

@josefkaragoli
Copy link
Author

This requires adding a transparency mode for dithered alpha to BaseMaterial3D, which doesn't exist yet.

Isn't this just hashed alpha? What makes it different?

@Calinou
Copy link
Member

Calinou commented Aug 30, 2022

Isn't this just hashed alpha? What makes it different?

Alpha hashing is intended to be used for different use cases, such as hair rendering with TAA enabled. See discussion in godotengine/godot#40364 and godotengine/godot#61880 (comment).

@Calinou
Copy link
Member

Calinou commented Jul 20, 2023

It looks like visibility range fade (as well as the GeometryInstance3D Transparency property) already obeys the material's existing transparency mode. If you set it to Alpha Hash, then the fadeout will use alpha hashing (same with alpha scissor).

However, this means you need to select the appropriate transparency mode on the material, which has a performance cost even if the material isn't currently being faded out (i.e. in its fully opaque state). As a result, there would still be a benefit of having a setting to configure how visibility range fade (and the Transparency property) should work.

@clayjohn For LOD fading, do you think we should go with Alpha Hash or interleaved gradient noise as an alternative to alpha blending? To clarify, this isn't meant to replace the current behavior, but provide an additional option.

@Arnklit
Copy link

Arnklit commented Feb 26, 2024

Relates to godotengine/godot#88854 - Visibility Range Fade does not work correctly with Alpha Clip and Alpha Hash Materials

@Arnklit
Copy link

Arnklit commented Feb 26, 2024

I did a test of a crossfade dither and it works well.
You have to invert the dither pattern on the two to be able to do a crossfade which would be needed for it to look good on stuff like alpha scissor and alpha hash.

Here the two spheres are low and high density meshes, but as you can see the fade is very smooth due to the dither crossfade.
Video:
https://github.com/godotengine/godot-proposals/assets/4955051/39693cd0-2cdb-4b2b-81d1-52b60217bf39

Test project:
dither_crossfade.zip

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

No branches or pull requests

3 participants