Skip to content

Commit bd9d1bf

Browse files
allenwpCalinou
andcommitted
Add material debanding for use in Mobile rendering method.
Co-authored-by: Hugo Locurcio <[email protected]>
1 parent 9a5d6d1 commit bd9d1bf

20 files changed

+85
-14
lines changed

doc/classes/ProjectSettings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,9 +2770,9 @@
27702770
[b]Note:[/b] This property is only read when the project starts. There is currently no way to change this setting at run-time.
27712771
</member>
27722772
<member name="rendering/anti_aliasing/quality/use_debanding" type="bool" setter="" getter="" default="false">
2773-
If [code]true[/code], uses a fast post-processing filter to make banding significantly less visible. If [member rendering/viewport/hdr_2d] is [code]false[/code], 2D rendering is [i]not[/i] affected by debanding unless the [member Environment.background_mode] is [constant Environment.BG_CANVAS]. If [member rendering/viewport/hdr_2d] is [code]true[/code], debanding will affect all 2D and 3D rendering, including canvas items.
2773+
If [code]true[/code], uses a fast dithering filter just before transforming floating point color values to integer color values to make banding significantly less visible. Debanding is applied at different steps of the rendering process depending on the rendering method and [member rendering/viewport/hdr_2d] setting.
27742774
In some cases, debanding may introduce a slightly noticeable dithering pattern. It's recommended to enable debanding only when actually needed since the dithering pattern will make lossless-compressed screenshots larger.
2775-
[b]Note:[/b] This property is only read when the project starts. To set debanding at runtime, set [member Viewport.use_debanding] on the root [Viewport] instead, or use [method RenderingServer.viewport_set_use_debanding].
2775+
[b]Note:[/b] This property is only read when the project starts and configures [method RenderingServer.material_set_use_debanding] and [member Viewport.use_debanding] of the root [Viewport]. When [member rendering/viewport/hdr_2d] is disabled, you should additionally set the [member Viewport.use_debanding] of other viewports in your project. To set debanding at run-time, the property that should be set depends on the renderer: Forward+ only uses [member Viewport.use_debanding] and Mobile uses both [method RenderingServer.material_set_use_debanding] and [member Viewport.use_debanding].
27762776
</member>
27772777
<member name="rendering/anti_aliasing/quality/use_taa" type="bool" setter="" getter="" default="false">
27782778
Enables temporal antialiasing for the default screen [Viewport]. TAA works by jittering the camera and accumulating the images of the last rendered frames, motion vector rendering is used to account for camera and object motion. Enabling TAA can make the image blurrier, which is partially counteracted by automatically using a negative mipmap LOD bias (see [member rendering/textures/default_filters/texture_mipmap_bias]).

doc/classes/RenderingServer.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,6 +2360,15 @@
23602360
Sets a shader material's shader.
23612361
</description>
23622362
</method>
2363+
<method name="material_set_use_debanding">
2364+
<return type="void" />
2365+
<param index="0" name="enable" type="bool" />
2366+
<description>
2367+
When using the Mobile renderer, [method material_set_use_debanding] can be used to enable or disable the debanding feature of 3D materials ([BaseMaterial3D] and [ShaderMaterial]).
2368+
[method material_set_use_debanding] has no effect when using the Compatibility or Forward+ renderer. In Forward+, [Viewport] debanding can be used instead.
2369+
See also [member ProjectSettings.rendering/anti_aliasing/quality/use_debanding] and [method RenderingServer.viewport_set_use_debanding].
2370+
</description>
2371+
</method>
23632372
<method name="mesh_add_surface">
23642373
<return type="void" />
23652374
<param index="0" name="mesh" type="RID" />

doc/classes/Viewport.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,9 @@
457457
[b]Note:[/b] Due to technical limitations, certain rendering features are disabled when a viewport has a transparent background. This currently applies to screen-space reflections, subsurface scattering, and depth of field.
458458
</member>
459459
<member name="use_debanding" type="bool" setter="set_use_debanding" getter="is_using_debanding" default="false">
460-
If [code]true[/code], uses a fast post-processing filter to make banding significantly less visible. If [member use_hdr_2d] is [code]false[/code], 2D rendering is [i]not[/i] affected by debanding unless the [member Environment.background_mode] is [constant Environment.BG_CANVAS]. If [member use_hdr_2d] is [code]true[/code], debanding will only be applied if this is the root [Viewport] and will affect all 2D and 3D rendering, including canvas items.
461-
In some cases, debanding may introduce a slightly noticeable dithering pattern. It's recommended to enable debanding only when actually needed since the dithering pattern will make lossless-compressed screenshots larger.
462-
See also [member ProjectSettings.rendering/anti_aliasing/quality/use_debanding] and [method RenderingServer.viewport_set_use_debanding].
460+
When using the Mobile or Forward+ renderers, set [member use_debanding] to enable or disable the debanding feature of this [Viewport]. If [member use_hdr_2d] is [code]false[/code], 2D rendering is [i]not[/i] affected by debanding unless the [member Environment.background_mode] is [constant Environment.BG_CANVAS]. If [member use_hdr_2d] is [code]true[/code], debanding will only be applied if this is the root [Viewport] and will affect all 2D and 3D rendering, including canvas items.
461+
[member use_debanding] has no effect when using the Compatibility rendering method. The Mobile renderer can also use material debanding, which can be set with [method RenderingServer.material_set_use_debanding] or configured with [member ProjectSettings.rendering/anti_aliasing/quality/use_debanding].
462+
See also [member ProjectSettings.rendering/anti_aliasing/quality/use_debanding], [method RenderingServer.material_set_use_debanding], and [method RenderingServer.viewport_set_use_debanding].
463463
</member>
464464
<member name="use_hdr_2d" type="bool" setter="set_use_hdr_2d" getter="is_using_hdr_2d" default="false">
465465
If [code]true[/code], 2D rendering will use a high dynamic range (HDR) format framebuffer matching the bit depth of the 3D framebuffer. When using the Forward+ or Compatibility renderer, this will be an [code]RGBA16[/code] framebuffer. When using the Mobile renderer, it will be an [code]RGB10_A2[/code] framebuffer.

drivers/gles3/rasterizer_scene_gles3.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4288,6 +4288,10 @@ void RasterizerSceneGLES3::lightmaps_set_bicubic_filter(bool p_enable) {
42884288
lightmap_bicubic_upscale = p_enable;
42894289
}
42904290

4291+
void RasterizerSceneGLES3::material_set_use_debanding(bool p_enable) {
4292+
// Material debanding not yet implemented.
4293+
}
4294+
42914295
RasterizerSceneGLES3::RasterizerSceneGLES3() {
42924296
singleton = this;
42934297

drivers/gles3/rasterizer_scene_gles3.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,7 @@ class RasterizerSceneGLES3 : public RendererSceneRender {
950950
void decals_set_filter(RS::DecalFilter p_filter) override;
951951
void light_projectors_set_filter(RS::LightProjectorFilter p_filter) override;
952952
virtual void lightmaps_set_bicubic_filter(bool p_enable) override;
953+
virtual void material_set_use_debanding(bool p_enable) override;
953954

954955
RasterizerSceneGLES3();
955956
~RasterizerSceneGLES3();

editor/editor_node.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ void EditorNode::_update_from_settings() {
527527
RS::get_singleton()->decals_set_filter(RS::DecalFilter(int(GLOBAL_GET("rendering/textures/decals/filter"))));
528528
RS::get_singleton()->light_projectors_set_filter(RS::LightProjectorFilter(int(GLOBAL_GET("rendering/textures/light_projectors/filter"))));
529529
RS::get_singleton()->lightmaps_set_bicubic_filter(GLOBAL_GET("rendering/lightmapping/lightmap_gi/use_bicubic_filter"));
530+
RS::get_singleton()->material_set_use_debanding(GLOBAL_GET("rendering/anti_aliasing/quality/use_debanding"));
530531

531532
SceneTree *tree = get_tree();
532533
tree->set_debug_collisions_color(GLOBAL_GET("debug/shapes/collision/shape_color"));

scene/main/scene_tree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2086,7 +2086,7 @@ SceneTree::SceneTree() {
20862086
const bool use_taa = GLOBAL_DEF_BASIC("rendering/anti_aliasing/quality/use_taa", false);
20872087
root->set_use_taa(use_taa);
20882088

2089-
const bool use_debanding = GLOBAL_DEF("rendering/anti_aliasing/quality/use_debanding", false);
2089+
const bool use_debanding = GLOBAL_GET("rendering/anti_aliasing/quality/use_debanding");
20902090
root->set_use_debanding(use_debanding);
20912091

20922092
const bool use_occlusion_culling = GLOBAL_DEF("rendering/occlusion_culling/use_occlusion_culling", false);

servers/rendering/dummy/rasterizer_scene_dummy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class RasterizerSceneDummy : public RendererSceneRender {
193193
virtual void decals_set_filter(RS::DecalFilter p_filter) override {}
194194
virtual void light_projectors_set_filter(RS::LightProjectorFilter p_filter) override {}
195195
virtual void lightmaps_set_bicubic_filter(bool p_enable) override {}
196+
virtual void material_set_use_debanding(bool p_enable) override {}
196197

197198
RasterizerSceneDummy() {}
198199
~RasterizerSceneDummy() {}

servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3329,6 +3329,7 @@ void RenderForwardMobile::_update_shader_quality_settings() {
33293329
light_projectors_get_filter() == RS::LIGHT_PROJECTOR_FILTER_LINEAR_MIPMAPS_ANISOTROPIC;
33303330

33313331
specialization.use_lightmap_bicubic_filter = lightmap_filter_bicubic_get();
3332+
specialization.use_material_debanding = material_use_debanding_get();
33323333
specialization.luminance_multiplier = 2.0f;
33333334
scene_shader.set_default_specialization(specialization);
33343335

servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,27 @@ class SceneShaderForwardMobile {
8989
uint32_t use_light_soft_shadows : 1;
9090
uint32_t use_directional_soft_shadows : 1;
9191
uint32_t decal_use_mipmaps : 1;
92+
9293
uint32_t projector_use_mipmaps : 1;
9394
uint32_t disable_fog : 1;
9495
uint32_t use_depth_fog : 1;
9596
uint32_t use_fog_aerial_perspective : 1;
97+
9698
uint32_t use_fog_sun_scatter : 1;
9799
uint32_t use_fog_height_density : 1;
98100
uint32_t use_lightmap_bicubic_filter : 1;
101+
uint32_t use_material_debanding : 1;
102+
99103
uint32_t multimesh : 1;
100104
uint32_t multimesh_format_2d : 1;
101105
uint32_t multimesh_has_color : 1;
102106
uint32_t multimesh_has_custom_data : 1;
107+
103108
uint32_t scene_use_ambient_cubemap : 1;
104109
uint32_t scene_use_reflection_cubemap : 1;
105110
uint32_t scene_roughness_limiter_enabled : 1;
106-
uint32_t padding_0 : 2;
111+
uint32_t padding_0 : 1;
112+
107113
uint32_t soft_shadow_samples : 6;
108114
uint32_t penumbra_shadow_samples : 6;
109115
};

0 commit comments

Comments
 (0)