Godot Version
4.3
Question
Seam apearing when using CanvasGroups for pixelization
Description
I’ve written a pixelization shader for groups that rounds the calculated screen UV coordinates. Needing to get rid of pixel creep when moving the viewport, I’m snapping positions to the pixel grid and then modifying the vertexes in a shader. It partially fixes the issue, but a cross-like “seam” appears at the center of the screen. Better shown than explained:
Snapping code:
@tool
extends CanvasGroup
func _process(delta: float) -> void:
var t: Vector2 = get_viewport_transform().get_origin()
var z: Vector2 = get_viewport_transform().get_scale()
var add: Vector2 = Vector2(snappedf(t.x, 5), snappedf(t.y, 5))-t
self.global_position = (add/z)+...
material.set_shader_parameter("offset", -(add/z))
Shader:
shader_type canvas_item;
render_mode world_vertex_coords;
uniform highp float pixel_size = 5;
uniform sampler2D screen: hint_screen_texture, filter_nearest;
uniform highp vec2 offset;
varying highp vec2 screen_uv;
varying float zoom;
void vertex() {
screen_uv = (CANVAS_MATRIX*vec4(VERTEX,0,1)).xy / vec2(textureSize(screen,0));
VERTEX += offset;
}
void fragment() {
vec2 puv = round(screen_uv/SCREEN_PIXEL_SIZE/pixel_size)*pixel_size*SCREEN_PIXEL_SIZE;
vec4 c = textureLod(screen, puv,0);
c.rgb /= max(0.1, c.a);
//vec4 lookup = texture(screen, puv);
//c.rgb = max(c.rgb, lookup.rgb/max(0.0001, lookup.a)-0.0);
COLOR *= c;
}
How do i fix it? please help!