Where to apply dithering shadermaterial

Godot Version

4.2.2

Question

I’m working on a dithering shader which works by sampling the screen texture, comparing it to a noise texture, and thresholding that value to generate a 1-bit image. This is designed to work in a 3D space. My shader code is as follows:


shader_type canvas_item;

uniform sampler2D noise_texture: repeat_enable;
uniform float noise_scale : hint_range(1.0, 20.0) = 10.0;
uniform float threshold : hint_range(0.0, 1.0) = 0.5;
uniform vec3 color1 : source_color = vec3(0.0, 0.0, 0.0);
uniform vec3 color2 : source_color = vec3(1.0, 1.0, 1.0);

void fragment() {
    vec2 uv = FRAGCOORD.xy / SCREEN_PIXEL_SIZE;
    vec3 texture_color = texture(TEXTURE, uv).rgb;
    float noise_value = texture(noise_texture, uv * noise_scale).r;
    float luminance = dot(texture_color, vec3(0.299, 0.587, 0.114));
    float dither_value = luminance + noise_value - threshold;
    float thresholded = step(0.5, dither_value);

    vec3 final_color = mix(color1, color2, thresholded);

    COLOR = vec4(final_color, 1.0);
}

It seems good to me, but i’m not sure whether it should be applied as the shadermaterial to the SubViewportContainer or to a ColorRect which is the child of said SubViewportContainer. I’ve seen others achieve a similar effect using one or the other and I know how either of them work, but I’m unsure which I should be using with the attached code. I’m also unsure if this even works because of that.