Skip to content

Commit d720eb8

Browse files
committed
Clamp UV-coordinates to centers of outermost texels when configured to do so
In addition, fix region_filter_clip_enabled documentation to be consistent with AtlasTexture.xml, since that is the option whose behavior was fixed
1 parent 1fc8208 commit d720eb8

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

doc/classes/Sprite2D.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
If [code]true[/code], texture is cut from a larger atlas texture. See [member region_rect].
7777
</member>
7878
<member name="region_filter_clip_enabled" type="bool" setter="set_region_filter_clip_enabled" getter="is_region_filter_clip_enabled" default="false">
79-
If [code]true[/code], the outermost pixels get blurred out. [member region_enabled] must be [code]true[/code].
79+
If [code]true[/code], the area outside of the [member region_rect] is clipped to avoid bleeding of the surrounding texture pixels. [member region_enabled] must be [code]true[/code].
8080
</member>
8181
<member name="region_rect" type="Rect2" setter="set_region_rect" getter="get_region_rect" default="Rect2(0, 0, 0, 0)">
8282
The region of the atlas texture to display. [member region_enabled] must be [code]true[/code].

drivers/gles3/shaders/canvas.glsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,8 @@ void main() {
579579

580580
#endif
581581
if (bool(read_draw_data_flags & FLAGS_CLIP_RECT_UV)) {
582-
uv = clamp(uv, read_draw_data_src_rect.xy, read_draw_data_src_rect.xy + abs(read_draw_data_src_rect.zw));
582+
vec2 half_texpixel = read_draw_data_color_texture_pixel_size * 0.5;
583+
uv = clamp(uv, read_draw_data_src_rect.xy + half_texpixel, read_draw_data_src_rect.xy + abs(read_draw_data_src_rect.zw) - half_texpixel);
583584
}
584585

585586
#endif

servers/rendering/renderer_rd/shaders/canvas.glsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,8 @@ void main() {
493493

494494
#endif
495495
if (bool(draw_data.flags & FLAGS_CLIP_RECT_UV)) {
496-
uv = clamp(uv, draw_data.src_rect.xy, draw_data.src_rect.xy + abs(draw_data.src_rect.zw));
496+
vec2 half_texpixel = draw_data.color_texture_pixel_size * 0.5;
497+
uv = clamp(uv, draw_data.src_rect.xy + half_texpixel, draw_data.src_rect.xy + abs(draw_data.src_rect.zw) - half_texpixel);
497498
}
498499

499500
#endif

0 commit comments

Comments
 (0)