Warning: Undefined variable $post_id in /var/www/godotshaders.com/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(663) : eval()'d code on line 7

Bayer Dithering

An implementation of Bayer Dithering.

Works as Control Overlay with a ColorRect. There are no values to set here.

Look at Test_CRT.tscn in the Github to see how it works.

Shader code
// Based on: https://www.shadertoy.com/view/WstXR8
shader_type canvas_item;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, repeat_disable, filter_nearest;

const mat4 bayerIndex = mat4(
    vec4(00.0/16.0, 12.0/16.0, 03.0/16.0, 15.0/16.0),
    vec4(08.0/16.0, 04.0/16.0, 11.0/16.0, 07.0/16.0),
    vec4(02.0/16.0, 14.0/16.0, 01.0/16.0, 13.0/16.0),
    vec4(10.0/16.0, 06.0/16.0, 09.0/16.0, 05.0/16.0));
	
void fragment() {
	 // sample the texture
	vec2 iResolution = 1.0 / SCREEN_PIXEL_SIZE;
    vec2 uv = FRAGCOORD.xy/iResolution.xy;
    vec4 col = texture(SCREEN_TEXTURE,uv);
    
    // gamma correction
    col = vec4(pow(col.rgb,vec3(2.2)) - 0.004,col.a);
    
    // find bayer matrix entry based on fragment position
    float bayerValue = bayerIndex[int(FRAGCOORD.x) % 4][int(FRAGCOORD.y) % 4];
    
    
        // output
     COLOR = vec4(
            step(bayerValue,col.r),
            step(bayerValue,col.g),
            step(bayerValue,col.b),
            col.a);
}
Live Preview

Warning: Undefined variable $post in /var/www/godotshaders.com/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(663) : eval()'d code on line 26

Warning: Attempt to read property "ID" on null in /var/www/godotshaders.com/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(663) : eval()'d code on line 26
Tags
canvas item, dither, dithering, Post processing
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from zuwiwano

Related shaders

guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
GDevLearn
11 months ago

It looks very nice