Skip to content

Commit 2e59cb4

Browse files
committed
Optimize glow and tonemap gather step in the mobile renderer
Mobile devices are typically bandwidth bound which means we need to do as few texture samples as possible. They typically use TBDR GPUs which means that all rendering takes place on special optimized tiles. As a side effect, reading back memory from tile to VRAM is really slow, especially on Mali devices. This commit uses a technique where you do a small blur while downsampling, and then another small blur while upsampling to get really high quality glow. While this doesn't reduce the renderpass count very much, it does reduce the texture read bandwidth by almost 10 times. Overall glow was more texture-read bound than memory write, bound, so this was a huge win. A side effect of this new technique is that we can gather the glow as we upsample instead of gathering the glow in the final tonemap pass. Doing so allows us to significantly reduce the cost of the tonemap pass as well.
1 parent 084d5d4 commit 2e59cb4

22 files changed

+1512
-507
lines changed

doc/classes/Environment.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@
143143
<member name="glow_hdr_scale" type="float" setter="set_glow_hdr_bleed_scale" getter="get_glow_hdr_bleed_scale" default="2.0">
144144
The bleed scale of the HDR glow.
145145
</member>
146-
<member name="glow_hdr_threshold" type="float" setter="set_glow_hdr_bleed_threshold" getter="get_glow_hdr_bleed_threshold" default="1.0">
146+
<member name="glow_hdr_threshold" type="float" setter="set_glow_hdr_bleed_threshold" getter="get_glow_hdr_bleed_threshold" default="0.0">
147147
The lower threshold of the HDR glow. When using the Mobile rendering method (which only supports a lower dynamic range up to [code]2.0[/code]), this may need to be below [code]1.0[/code] for glow to be visible. A value of [code]0.9[/code] works well in this case. This value also needs to be decreased below [code]1.0[/code] when using glow in 2D, as 2D rendering is performed in SDR.
148148
</member>
149149
<member name="glow_intensity" type="float" setter="set_glow_intensity" getter="get_glow_intensity" default="0.3">
150150
The overall brightness multiplier of the glow effect. When using the Mobile rendering method (which only supports a lower dynamic range up to [code]2.0[/code]), this should be increased to [code]1.5[/code] to compensate.
151151
</member>
152-
<member name="glow_levels/1" type="float" setter="set_glow_level" getter="get_glow_level" default="1.0">
152+
<member name="glow_levels/1" type="float" setter="set_glow_level" getter="get_glow_level" default="0.0">
153153
The intensity of the 1st level of glow. This is the most "local" level (least blurry).
154154
[b]Note:[/b] [member glow_levels/1] has no effect when using the Compatibility rendering method, due to this rendering method using a simpler glow implementation optimized for low-end devices.
155155
</member>

drivers/gles3/effects/glow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Glow {
4949

5050
float glow_intensity = 1.0;
5151
float glow_bloom = 0.0;
52-
float glow_hdr_bleed_threshold = 1.0;
52+
float glow_hdr_bleed_threshold = 0.0;
5353
float glow_hdr_bleed_scale = 2.0;
5454
float glow_hdr_luminance_cap = 12.0;
5555

drivers/gles3/rasterizer_scene_gles3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2814,7 +2814,7 @@ void RasterizerSceneGLES3::_render_post_processing(const RenderDataGLES3 *p_rend
28142814
bool glow_enabled = false;
28152815
float glow_intensity = 1.0;
28162816
float glow_bloom = 0.0;
2817-
float glow_hdr_bleed_threshold = 1.0;
2817+
float glow_hdr_bleed_threshold = 0.0;
28182818
float glow_hdr_bleed_scale = 2.0;
28192819
float glow_hdr_luminance_cap = 12.0;
28202820
float srgb_white = 1.0;

scene/resources/environment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ Environment::Environment() {
15721572
set_camera_feed_id(bg_camera_feed_id);
15731573

15741574
glow_levels.resize(7);
1575-
glow_levels.write[0] = 1.0;
1575+
glow_levels.write[0] = 0.0;
15761576
glow_levels.write[1] = 0.8;
15771577
glow_levels.write[2] = 0.4;
15781578
glow_levels.write[3] = 0.1;

scene/resources/environment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class Environment : public Resource {
168168
float glow_mix = 0.05;
169169
float glow_bloom = 0.0;
170170
GlowBlendMode glow_blend_mode = GLOW_BLEND_MODE_SCREEN;
171-
float glow_hdr_bleed_threshold = 1.0;
171+
float glow_hdr_bleed_threshold = 0.0;
172172
float glow_hdr_bleed_scale = 2.0;
173173
float glow_hdr_luminance_cap = 12.0;
174174
float glow_map_strength = 0.8f;

servers/rendering/renderer_rd/effects/copy_effects.cpp

Lines changed: 59 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ CopyEffects::CopyEffects(bool p_prefer_raster_effects) {
5353
Vector<String> blur_modes;
5454
blur_modes.push_back("\n#define MODE_MIPMAP\n"); // BLUR_MIPMAP
5555
blur_modes.push_back("\n#define MODE_GAUSSIAN_BLUR\n"); // BLUR_MODE_GAUSSIAN_BLUR
56-
blur_modes.push_back("\n#define MODE_GAUSSIAN_GLOW\n"); // BLUR_MODE_GAUSSIAN_GLOW
57-
blur_modes.push_back("\n#define MODE_GAUSSIAN_GLOW\n#define GLOW_USE_AUTO_EXPOSURE\n"); // BLUR_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE
56+
blur_modes.push_back("\n#define MODE_GLOW_GATHER\n"); // BLUR_MODE_GAUSSIAN_GLOW_GATHER
57+
blur_modes.push_back("\n#define MODE_GLOW_DOWNSAMPLE\n"); // BLUR_MODE_GAUSSIAN_GLOW_DOWNSAMPLE
58+
blur_modes.push_back("\n#define MODE_GLOW_UPSAMPLE\n"); // BLUR_MODE_GAUSSIAN_GLOW_UPSAMPLE
5859
blur_modes.push_back("\n#define MODE_COPY\n"); // BLUR_MODE_COPY
5960
blur_modes.push_back("\n#define MODE_SET_COLOR\n"); // BLUR_MODE_SET_COLOR
6061

@@ -66,6 +67,15 @@ CopyEffects::CopyEffects(bool p_prefer_raster_effects) {
6667
blur_raster.pipelines[i].setup(blur_raster.shader.version_get_shader(blur_raster.shader_version, i), RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), RD::PipelineColorBlendState::create_disabled(), 0);
6768
}
6869

70+
RD::SamplerState sampler_state;
71+
sampler_state.mag_filter = RD::SAMPLER_FILTER_LINEAR;
72+
sampler_state.min_filter = RD::SAMPLER_FILTER_LINEAR;
73+
sampler_state.repeat_u = RD::SAMPLER_REPEAT_MODE_CLAMP_TO_BORDER;
74+
sampler_state.repeat_v = RD::SAMPLER_REPEAT_MODE_CLAMP_TO_BORDER;
75+
sampler_state.border_color = RD::SAMPLER_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
76+
77+
blur_raster.glow_sampler = RD::get_singleton()->sampler_create(sampler_state);
78+
6979
} else {
7080
// not used in clustered
7181
for (int i = 0; i < BLUR_MODE_MAX; i++) {
@@ -319,6 +329,7 @@ CopyEffects::~CopyEffects() {
319329

320330
if (prefer_raster_effects) {
321331
blur_raster.shader.version_free(blur_raster.shader_version);
332+
RD::get_singleton()->free_rid(blur_raster.glow_sampler);
322333
cubemap_downsampler.raster_shader.version_free(cubemap_downsampler.shader_version);
323334
filter.raster_shader.version_free(filter.shader_version);
324335
roughness.raster_shader.version_free(roughness.shader_version);
@@ -733,8 +744,8 @@ void CopyEffects::gaussian_blur_raster(RID p_source_rd_texture, RID p_dest_textu
733744

734745
BlurRasterMode blur_mode = BLUR_MODE_GAUSSIAN_BLUR;
735746

736-
blur_raster.push_constant.pixel_size[0] = 1.0 / float(p_size.x);
737-
blur_raster.push_constant.pixel_size[1] = 1.0 / float(p_size.y);
747+
blur_raster.push_constant.dest_pixel_size[0] = 1.0 / float(p_size.x);
748+
blur_raster.push_constant.dest_pixel_size[1] = 1.0 / float(p_size.y);
738749

739750
// setup our uniforms
740751
RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
@@ -805,24 +816,22 @@ void CopyEffects::gaussian_glow(RID p_source_rd_texture, RID p_back_texture, con
805816
RD::get_singleton()->compute_list_end();
806817
}
807818

808-
void CopyEffects::gaussian_glow_raster(RID p_source_rd_texture, RID p_half_texture, RID p_dest_texture, float p_luminance_multiplier, const Size2i &p_size, float p_strength, bool p_first_pass, float p_luminance_cap, float p_exposure, float p_bloom, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, RID p_auto_exposure, float p_auto_exposure_scale) {
819+
void CopyEffects::gaussian_glow_downsample_raster(RID p_source_rd_texture, RID p_dest_texture, float p_luminance_multiplier, const Size2i &p_size, float p_strength, bool p_first_pass, float p_luminance_cap, float p_exposure, float p_bloom, float p_hdr_bleed_threshold, float p_hdr_bleed_scale) {
809820
ERR_FAIL_COND_MSG(!prefer_raster_effects, "Can't use the raster version of the gaussian glow with the clustered renderer.");
810821

811822
UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
812823
ERR_FAIL_NULL(uniform_set_cache);
813824
MaterialStorage *material_storage = MaterialStorage::get_singleton();
814825
ERR_FAIL_NULL(material_storage);
815826

816-
RID half_framebuffer = FramebufferCacheRD::get_singleton()->get_cache(p_half_texture);
817827
RID dest_framebuffer = FramebufferCacheRD::get_singleton()->get_cache(p_dest_texture);
818828

819829
memset(&blur_raster.push_constant, 0, sizeof(BlurRasterPushConstant));
820830

821-
BlurRasterMode blur_mode = p_first_pass && p_auto_exposure.is_valid() ? BLUR_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE : BLUR_MODE_GAUSSIAN_GLOW;
822-
uint32_t base_flags = 0;
831+
BlurRasterMode blur_mode = p_first_pass ? BLUR_MODE_GAUSSIAN_GLOW_GATHER : BLUR_MODE_GAUSSIAN_GLOW_DOWNSAMPLE;
823832

824-
blur_raster.push_constant.pixel_size[0] = 1.0 / float(p_size.x);
825-
blur_raster.push_constant.pixel_size[1] = 1.0 / float(p_size.y);
833+
blur_raster.push_constant.source_pixel_size[0] = 1.0 / float(p_size.x);
834+
blur_raster.push_constant.source_pixel_size[1] = 1.0 / float(p_size.y);
826835

827836
blur_raster.push_constant.glow_strength = p_strength;
828837
blur_raster.push_constant.glow_bloom = p_bloom;
@@ -832,45 +841,62 @@ void CopyEffects::gaussian_glow_raster(RID p_source_rd_texture, RID p_half_textu
832841
blur_raster.push_constant.glow_white = 0; //actually unused
833842
blur_raster.push_constant.glow_luminance_cap = p_luminance_cap;
834843

835-
blur_raster.push_constant.glow_auto_exposure_scale = p_auto_exposure_scale; //unused also
836-
837844
blur_raster.push_constant.luminance_multiplier = p_luminance_multiplier;
838845

839846
// setup our uniforms
840-
RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
841-
842-
RD::Uniform u_source_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_rd_texture }));
843-
RD::Uniform u_half_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_half_texture }));
847+
RD::Uniform u_source_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ blur_raster.glow_sampler, p_source_rd_texture }));
844848

845849
RID shader = blur_raster.shader.version_get_shader(blur_raster.shader_version, blur_mode);
846850
ERR_FAIL_COND(shader.is_null());
847851

848-
//HORIZONTAL
849-
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(half_framebuffer);
850-
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blur_raster.pipelines[blur_mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(half_framebuffer)));
852+
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(dest_framebuffer);
853+
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blur_raster.pipelines[blur_mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(dest_framebuffer)));
851854
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 0, u_source_rd_texture), 0);
852-
if (p_auto_exposure.is_valid() && p_first_pass) {
853-
RD::Uniform u_auto_exposure(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_auto_exposure }));
854-
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 1, u_auto_exposure), 1);
855-
}
856855

857-
blur_raster.push_constant.flags = base_flags | BLUR_FLAG_HORIZONTAL | (p_first_pass ? BLUR_FLAG_GLOW_FIRST_PASS : 0);
858856
RD::get_singleton()->draw_list_set_push_constant(draw_list, &blur_raster.push_constant, sizeof(BlurRasterPushConstant));
859857

860858
RD::get_singleton()->draw_list_draw(draw_list, false, 1u, 3u);
861859
RD::get_singleton()->draw_list_end();
860+
}
862861

863-
blur_mode = BLUR_MODE_GAUSSIAN_GLOW;
862+
void CopyEffects::gaussian_glow_upsample_raster(RID p_source_rd_texture, RID p_dest_texture, RID p_blend_texture, float p_luminance_multiplier, const Size2i &p_source_size, const Size2i &p_dest_size, float p_level, float p_base_strength, bool p_use_debanding) {
863+
ERR_FAIL_COND_MSG(!prefer_raster_effects, "Can't use the raster version of the gaussian glow with the clustered renderer.");
864864

865-
shader = blur_raster.shader.version_get_shader(blur_raster.shader_version, blur_mode);
865+
UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
866+
ERR_FAIL_NULL(uniform_set_cache);
867+
MaterialStorage *material_storage = MaterialStorage::get_singleton();
868+
ERR_FAIL_NULL(material_storage);
869+
870+
RID dest_framebuffer = FramebufferCacheRD::get_singleton()->get_cache(p_dest_texture);
871+
872+
memset(&blur_raster.push_constant, 0, sizeof(BlurRasterPushConstant));
873+
874+
BlurRasterMode blur_mode = BLUR_MODE_GAUSSIAN_GLOW_UPSAMPLE;
875+
876+
blur_raster.push_constant.source_pixel_size[0] = 1.0 / float(p_source_size.x);
877+
blur_raster.push_constant.source_pixel_size[1] = 1.0 / float(p_source_size.y);
878+
blur_raster.push_constant.dest_pixel_size[0] = 1.0 / float(p_dest_size.x);
879+
blur_raster.push_constant.dest_pixel_size[1] = 1.0 / float(p_dest_size.y);
880+
blur_raster.push_constant.luminance_multiplier = p_luminance_multiplier;
881+
blur_raster.push_constant.level = p_level * 0.5;
882+
blur_raster.push_constant.glow_strength = p_base_strength;
883+
884+
uint32_t spec_constant = p_use_debanding ? 1 : 0;
885+
spec_constant |= p_level > 0.01 ? 2 : 0;
886+
887+
// setup our uniforms
888+
RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
889+
RD::Uniform u_source_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_rd_texture }));
890+
RD::Uniform u_blend_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_blend_texture }));
891+
892+
RID shader = blur_raster.shader.version_get_shader(blur_raster.shader_version, blur_mode);
866893
ERR_FAIL_COND(shader.is_null());
867894

868-
//VERTICAL
869-
draw_list = RD::get_singleton()->draw_list_begin(dest_framebuffer);
870-
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blur_raster.pipelines[blur_mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(dest_framebuffer)));
871-
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 0, u_half_texture), 0);
895+
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(dest_framebuffer);
896+
RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blur_raster.pipelines[blur_mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(dest_framebuffer), false, 0, spec_constant));
897+
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 0, u_source_rd_texture), 0);
898+
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uniform_set_cache->get_cache(shader, 1, u_blend_rd_texture), 1);
872899

873-
blur_raster.push_constant.flags = base_flags;
874900
RD::get_singleton()->draw_list_set_push_constant(draw_list, &blur_raster.push_constant, sizeof(BlurRasterPushConstant));
875901

876902
RD::get_singleton()->draw_list_draw(draw_list, false, 1u, 3u);
@@ -925,8 +951,8 @@ void CopyEffects::make_mipmap_raster(RID p_source_rd_texture, RID p_dest_texture
925951

926952
BlurRasterMode mode = BLUR_MIPMAP;
927953

928-
blur_raster.push_constant.pixel_size[0] = 1.0 / float(p_size.x);
929-
blur_raster.push_constant.pixel_size[1] = 1.0 / float(p_size.y);
954+
blur_raster.push_constant.dest_pixel_size[0] = 1.0 / float(p_size.x);
955+
blur_raster.push_constant.dest_pixel_size[1] = 1.0 / float(p_size.y);
930956

931957
// setup our uniforms
932958
RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);

servers/rendering/renderer_rd/effects/copy_effects.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ class CopyEffects {
5959
BLUR_MIPMAP,
6060

6161
BLUR_MODE_GAUSSIAN_BLUR,
62-
BLUR_MODE_GAUSSIAN_GLOW,
63-
BLUR_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE,
62+
BLUR_MODE_GAUSSIAN_GLOW_GATHER,
63+
BLUR_MODE_GAUSSIAN_GLOW_DOWNSAMPLE,
64+
BLUR_MODE_GAUSSIAN_GLOW_UPSAMPLE,
6465
BLUR_MODE_COPY,
6566

6667
BLUR_MODE_SET_COLOR,
@@ -69,15 +70,16 @@ class CopyEffects {
6970
};
7071

7172
enum {
72-
BLUR_FLAG_HORIZONTAL = (1 << 0),
7373
BLUR_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 1),
74-
BLUR_FLAG_GLOW_FIRST_PASS = (1 << 2),
7574
};
7675

7776
struct BlurRasterPushConstant {
78-
float pixel_size[2];
77+
float dest_pixel_size[2];
78+
float source_pixel_size[2];
79+
80+
float pad[2];
7981
uint32_t flags;
80-
uint32_t pad;
82+
float level;
8183

8284
//glow
8385
float glow_strength;
@@ -88,19 +90,15 @@ class CopyEffects {
8890
float glow_exposure;
8991
float glow_white;
9092
float glow_luminance_cap;
91-
float glow_auto_exposure_scale;
92-
9393
float luminance_multiplier;
94-
float res1;
95-
float res2;
96-
float res3;
9794
};
9895

9996
struct BlurRaster {
10097
BlurRasterPushConstant push_constant;
10198
BlurRasterShaderRD shader;
10299
RID shader_version;
103100
PipelineCacheRD pipelines[BLUR_MODE_MAX];
101+
RID glow_sampler;
104102
} blur_raster;
105103

106104
// Copy shader
@@ -337,7 +335,8 @@ class CopyEffects {
337335
void gaussian_blur(RID p_source_rd_texture, RID p_texture, const Rect2i &p_region, const Size2i &p_size, bool p_8bit_dst = false);
338336
void gaussian_blur_raster(RID p_source_rd_texture, RID p_dest_texture, const Rect2i &p_region, const Size2i &p_size);
339337
void gaussian_glow(RID p_source_rd_texture, RID p_back_texture, const Size2i &p_size, float p_strength = 1.0, bool p_first_pass = false, float p_luminance_cap = 16.0, float p_exposure = 1.0, float p_bloom = 0.0, float p_hdr_bleed_threshold = 1.0, float p_hdr_bleed_scale = 1.0, RID p_auto_exposure = RID(), float p_auto_exposure_scale = 1.0);
340-
void gaussian_glow_raster(RID p_source_rd_texture, RID p_half_texture, RID p_dest_texture, float p_luminance_multiplier, const Size2i &p_size, float p_strength = 1.0, bool p_first_pass = false, float p_luminance_cap = 16.0, float p_exposure = 1.0, float p_bloom = 0.0, float p_hdr_bleed_threshold = 1.0, float p_hdr_bleed_scale = 1.0, RID p_auto_exposure = RID(), float p_auto_exposure_scale = 1.0);
338+
void gaussian_glow_downsample_raster(RID p_source_rd_texture, RID p_dest_texture, float p_luminance_multiplier, const Size2i &p_size, float p_strength = 1.0, bool p_first_pass = false, float p_luminance_cap = 16.0, float p_exposure = 1.0, float p_bloom = 0.0, float p_hdr_bleed_threshold = 1.0, float p_hdr_bleed_scale = 1.0);
339+
void gaussian_glow_upsample_raster(RID p_source_rd_texture, RID p_dest_texture, RID p_blend_texture, float p_luminance_multiplier, const Size2i &p_source_size, const Size2i &p_dest_size, float p_level, float p_base_strength, bool p_use_debanding);
341340

342341
void make_mipmap(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size);
343342
void make_mipmap_raster(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size);

servers/rendering/renderer_rd/effects/smaa.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ void SMAA::allocate_render_targets(Ref<RenderSceneBuffersRD> p_render_buffers) {
157157
p_render_buffers->create_texture(RB_SCOPE_SMAA, RB_STENCIL, smaa.stencil_format, RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, RD::TEXTURE_SAMPLES_1, full_size, 1, 1, true, true);
158158
}
159159

160-
void SMAA::process(Ref<RenderSceneBuffersRD> p_render_buffers, RID p_source_color, RID p_dst_framebuffer) {
160+
void SMAA::process(Ref<RenderSceneBuffersRD> p_render_buffers, RID p_source_color, RID p_dst_framebuffer, bool p_use_debanding) {
161161
UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
162162
ERR_FAIL_NULL(uniform_set_cache);
163163
MaterialStorage *material_storage = MaterialStorage::get_singleton();
@@ -181,11 +181,7 @@ void SMAA::process(Ref<RenderSceneBuffersRD> p_render_buffers, RID p_source_colo
181181

182182
smaa.blend_push_constant.inv_size[0] = inv_size.x;
183183
smaa.blend_push_constant.inv_size[1] = inv_size.y;
184-
if (debanding_mode == DEBANDING_MODE_8_BIT) {
185-
smaa.blend_push_constant.flags |= SMAA_BLEND_FLAG_USE_8_BIT_DEBANDING;
186-
} else if (debanding_mode == DEBANDING_MODE_10_BIT) {
187-
smaa.blend_push_constant.flags |= SMAA_BLEND_FLAG_USE_10_BIT_DEBANDING;
188-
}
184+
smaa.blend_push_constant.use_debanding = p_use_debanding;
189185

190186
RID linear_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
191187

servers/rendering/renderer_rd/effects/smaa.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class SMAA {
7171

7272
struct SMAABlendPushConstant {
7373
float inv_size[2];
74-
uint32_t flags;
74+
uint32_t use_debanding;
7575
float pad;
7676
};
7777

@@ -108,14 +108,7 @@ class SMAA {
108108
~SMAA();
109109

110110
void allocate_render_targets(Ref<RenderSceneBuffersRD> p_render_buffers);
111-
void process(Ref<RenderSceneBuffersRD> p_render_buffers, RID p_source_color, RID p_dst_framebuffer);
112-
113-
enum DebandingMode {
114-
DEBANDING_MODE_DISABLED,
115-
DEBANDING_MODE_8_BIT,
116-
DEBANDING_MODE_10_BIT,
117-
};
118-
DebandingMode debanding_mode = DEBANDING_MODE_DISABLED;
111+
void process(Ref<RenderSceneBuffersRD> p_render_buffers, RID p_source_color, RID p_dst_framebuffer, bool p_use_debanding);
119112
};
120113

121114
} // namespace RendererRD

0 commit comments

Comments
 (0)