Godot Version
v4.1.3.stable.official [f06b6836a]
Question
Hey y’all, I’ve been trying to get into shaders and post processing, however no matter what I try to do, i get these weird square artifacts on my shaders. I’m really not sure whats going on though. I’ve had this issue when implementing cel and blinn phong shading, but I’m attaching an example with a downscaling postprocessing effect I made with the help of godot shaders. I feel pretty confident this is correctly written, but for some reason these unsightly blocky squares appear. If anyone knows this issue, lmk. Thanks!
P.S. Heres a photo, and I’m attaching the shader code at the bottom.
Downscaling.gdshader
shader_type spatial;
render_mode unshaded;
const int pixel_size = 16;
uniform sampler2D DEPTH_TEXTURE : hint_depth_texture;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture;
void vertex() {
POSITION = vec4(VERTEX.xy, 1.0, 1.0);
}
void fragment() {
float depth = texture(DEPTH_TEXTURE, SCREEN_UV).x;
vec3 ndc = vec3(SCREEN_UV * 2.0 - 1.0, depth);
vec4 view = INV_PROJECTION_MATRIX * vec4(ndc, 1.0);
float x = float(int(FRAGCOORD.x) % pixel_size);
float y = float(int(FRAGCOORD.y) % pixel_size);
x = FRAGCOORD.x + floor(float(pixel_size) / 2.0) - x;
y = FRAGCOORD.y + floor(float(pixel_size) / 2.0) - y;
ALBEDO = texture(SCREEN_TEXTURE, vec2(x, y) / VIEWPORT_SIZE).xyz;
}