Skip to content

Add material debanding for use in Mobile rendering method.#109084

Merged
Repiteo merged 1 commit into
godotengine:masterfrom
allenwp:add-spatial-shader-debanding
Oct 9, 2025
Merged

Add material debanding for use in Mobile rendering method.#109084
Repiteo merged 1 commit into
godotengine:masterfrom
allenwp:add-spatial-shader-debanding

Conversation

@allenwp

@allenwp allenwp commented Jul 29, 2025

Copy link
Copy Markdown
Contributor

This PR is a trimmed down and slightly modified version of @Calinou's #87350 -- Calinou should take most of the credit for this!

This PR adds a new RenderingServer.material_use_debanding property that is configured at project startup by the existing rendering/anti_aliasing/quality/use_debanding project setting. This RenderingServer property can also be toggled at runtime. This new debanding mode only functions with the Mobile rendering method, but can be extended to the Compatibility rendering method in the future.

Screenshots (view at 100% size for correct appearance)

Material Debanding Off Material Debanding On
Viewport Debanding Off image image
Viewport Debanding On image image
Material Debanding Off Material Debanding On
Viewport Debanding Off image image
Viewport Debanding On image image

Comparison to original PR

Compared to Calinou's original PR, I have changed the following:

  • Corrected Mobile material debanding to be applied as the last step before quantization from floating point to integer values and corrected the scale to align to 10-bit integer values
  • Disabled material debanding entirely when using the Forward+ or Compatibility rendering method
    • Because Forward+ uses floating point buffers for rendering materials, there is never a need for material debanding
    • It is difficult to get flawless results with the additive lights and the Compatibility rendering method. Calinou did a fantastic job getting close, but I think it is better to explore this in a followup PR instead.
  • Consolidated the project setting for use_debanding so that it affects both viewport and material debanding
    • Viewport and material debanding can still be individually controlled through scripting
    • I don't see any issue with combining material and viewport debanding on the Mobile rendering method. I think most users would want this behaviour and if they don't, they can turn individual settings on/off at run-time.
  • Updated documentation, including a simplified project setting description that simply states that the dithering filter is applied at different steps of the rendering process depending on the rendering method and HDR 2D setting. Details about when viewport/material debanding apply are included in their documentation.
  • Added an offset to Mobile material debanding

Dither offset

Here is the tool that I used to determine a good offset for the material debanding:
dither-offset-test.zip
In this image the top and bottom bars are the original colour, the left is the base dither pattern, the right is the offset dither pattern, and the middle is the left and right added to each other (in linear space):
468825058-8467669d-97fc-42f1-b414-e2590c6d6252

For reviewers

Test projects

@clayjohn

Copy link
Copy Markdown
Member

See my comment on the original PR #87350 (review)

I don't think making this a material/shader setting is a good idea. The cases where you need this, you need it on every object and having to manually enable it on every material will be painful.

@allenwp

allenwp commented Jul 29, 2025

Copy link
Copy Markdown
Contributor Author

See my comment on the original PR #87350 (review)

I don't think making this a material/shader setting is a good idea. The cases where you need this, you need it on every object and having to manually enable it on every material will be painful.

This PR is built on top of the latest version of #87350 which, as I understand it, only has a global setting RenderingServer.material_use_debanding that turns on and off "material debanding" for all 3D materials (BaseMaterial3D and ShaderMaterial). It cannot be configured per-material.

This was all done before I first looked at this PR and I've mostly focused on improving the shader code, so maybe I'm misunderstanding something, but I believe Calinou fully addressed this concern already in the original PR?

@Calinou

Calinou commented Jul 31, 2025

Copy link
Copy Markdown
Member

This was all done before I first looked at this PR and I've mostly focused on improving the shader code, so maybe I'm misunderstanding something, but I believe Calinou fully addressed this concern already in the original PR?

Indeed, I already switched it to a project setting a while ago.

@allenwp allenwp force-pushed the add-spatial-shader-debanding branch 3 times, most recently from 61b4049 to 8014b6f Compare September 5, 2025 02:39
@allenwp allenwp changed the title Add use_debanding render mode and property to spatial shaders [allenwp update] Add material debanding for use in Mobile rendering method. Sep 5, 2025
Comment thread doc/classes/RenderingServer.xml Outdated
@allenwp allenwp marked this pull request as ready for review September 5, 2025 15:38
@allenwp allenwp requested a review from a team as a code owner September 5, 2025 15:38
@allenwp allenwp requested a review from a team September 5, 2025 15:38
@allenwp allenwp requested a review from a team as a code owner September 5, 2025 15:38
Comment thread servers/rendering/shader_types.cpp Outdated
Comment thread servers/rendering_server.cpp Outdated
@allenwp allenwp force-pushed the add-spatial-shader-debanding branch from 8014b6f to 8e063f0 Compare September 16, 2025 14:11
Comment thread doc/classes/RenderingServer.xml Outdated

@Calinou Calinou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tested locally, it works as expected (both with HDR 2D disabled and enabled). Code looks good to me.

Comment thread servers/rendering_server.h Outdated
@allenwp allenwp force-pushed the add-spatial-shader-debanding branch from 8e063f0 to cc881f4 Compare September 17, 2025 13:31
@allenwp

allenwp commented Sep 17, 2025

Copy link
Copy Markdown
Contributor Author

I'm converting this to draft to make sure it doesn't get merged just yet because I've discovered a warning that is thrown when the game launches:

W 0:00:00:191   get_setting_with_override: Property not found: 'rendering/anti_aliasing/quality/use_debanding'.
  <C++ Source>  core/config/project_settings.cpp:404 @ get_setting_with_override()

It is triggered by this line in void RendererSceneRenderRD::init():

material_set_use_debanding(GLOBAL_GET("rendering/anti_aliasing/quality/use_debanding"));

@allenwp allenwp marked this pull request as draft September 17, 2025 13:34
@clayjohn

Copy link
Copy Markdown
Member

I'm converting this to draft to make sure it doesn't get merged just yet because I've discovered a warning that is thrown when the game launches:

W 0:00:00:191   get_setting_with_override: Property not found: 'rendering/anti_aliasing/quality/use_debanding'.
  <C++ Source>  core/config/project_settings.cpp:404 @ get_setting_with_override()

It is triggered by this line in void RendererSceneRenderRD::init():

material_set_use_debanding(GLOBAL_GET("rendering/anti_aliasing/quality/use_debanding"));

The GLOBAL_DEF must happen afterwards.

I can see for debanding the DEF is in scene/main/scene_tree.cpp while for the bicubic setting the DEF is in rendering_server.cpp

You will likely need to just move it to the RenderingServer to ensure it is defined before RendererSceneRenderRD::init() is called

@allenwp allenwp force-pushed the add-spatial-shader-debanding branch from cc881f4 to 365e8c0 Compare September 17, 2025 21:43
@allenwp allenwp marked this pull request as ready for review September 17, 2025 21:43
@allenwp allenwp requested a review from a team as a code owner September 17, 2025 21:43
@allenwp

allenwp commented Sep 17, 2025

Copy link
Copy Markdown
Contributor Author

You will likely need to just move it to the RenderingServer to ensure it is defined before RendererSceneRenderRD::init() is called

Thanks for figuring this out for me, @clayjohn! I've pushed the fix. I believe there are no more outstanding issues with this PR.

@allenwp allenwp force-pushed the add-spatial-shader-debanding branch from 365e8c0 to b150467 Compare September 17, 2025 21:48
@allenwp allenwp force-pushed the add-spatial-shader-debanding branch from b150467 to 7ca3276 Compare September 30, 2025 14:24
@Ivorforce

Ivorforce commented Sep 30, 2025

Copy link
Copy Markdown
Member

Calinou should take most of the credit for this!

Note that you can share authorship to a git commit using co-authored-by in the commit message. See https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors

@allenwp

allenwp commented Sep 30, 2025

Copy link
Copy Markdown
Contributor Author

Calinou should take most of the credit for this!

Note that you can share authorship to a git commit using co-authored-by in the commit message. See https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors

Thanks! This one I actually knew about 😅 -- I think I've done it correctly on this commit; please let me know if I botched it somehow!

@Calinou

Calinou commented Sep 30, 2025

Copy link
Copy Markdown
Member

I think I've done it correctly on this commit; please let me know if I botched it somehow!

You need to add one more blank line before Co-authored-by (or any other Git entitlements), otherwise it won't be recognized. tig still highlights it in this case, which is probably a bug:

image

@allenwp allenwp force-pushed the add-spatial-shader-debanding branch from 7ca3276 to 8a5ac45 Compare September 30, 2025 17:28
@allenwp

allenwp commented Sep 30, 2025

Copy link
Copy Markdown
Contributor Author

I think I've done it correctly on this commit; please let me know if I botched it somehow!

You need to add one more blank line before Co-authored-by (or any other Git entitlements), otherwise it won't be recognized. tig still highlights it in this case, which is probably a bug:
image

Oh! Thanks! I had no idea. Should be fixed now.

Edit: Just re-pushed with no changes to trigger checks to run again (they failed with a timeout for no apparent reason).

@allenwp allenwp force-pushed the add-spatial-shader-debanding branch 2 times, most recently from e5cd339 to c8a5817 Compare September 30, 2025 22:32

@clayjohn clayjohn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Implementation is good. Just need to rebase since rendering_server.cpp/h were moved recently

Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
@allenwp allenwp force-pushed the add-spatial-shader-debanding branch from c8a5817 to bd9d1bf Compare October 8, 2025 20:23
@allenwp

allenwp commented Oct 8, 2025

Copy link
Copy Markdown
Contributor Author

Implementation is good. Just need to rebase since rendering_server.cpp/h were moved recently

Rebased, thanks!

@clayjohn clayjohn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great! Let's merge this now and then I will rebase on top of it with my HDR 3D buffer PR

@clayjohn clayjohn modified the milestones: 4.x, 4.6 Oct 8, 2025
@Repiteo Repiteo merged commit 91a1798 into godotengine:master Oct 9, 2025
20 checks passed
@Repiteo

Repiteo commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

Thanks!

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.

Dither colors in any intermediate write to color framebuffer when using the mobile renderer

6 participants