Nifty Retroiztion Shader

A lovley shader I made and use in my current project and thought I might as well share it!

Add a ColorRect, give it a shader material, and paste the shader code from below.

It has:

– Color depth.

– A threshold for each channel (R, G, and B).

– Pixelation.

– Bloom.

– Dither.

All of which are adjustable!

 

NOTE: Outline shader is not mine it’s this shader (https://godotshaders.com/shader/depth-modulated-pixel-outline-in-screen-space/)

Shader code
shader_type canvas_item;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture;
uniform float bits_per_channel : hint_range(1.0, 8.0) = 4.0;
uniform float dither_strength : hint_range(0.0, 1.0) = 0.1;
uniform float bloom_threshold : hint_range(0.0, 1.0) = 0.5;
uniform float bloom_intensity : hint_range(0.0, 10.0) = 2.0;
uniform float pixelation : hint_range(1, 1000) = 10;
uniform float color_relaxation : hint_range(0.0, 1.0) = 0.5;
uniform vec3 relaxation_color = vec3(1.0, 1.0, 1.0);
uniform float threshold_r : hint_range(0.0, 1.0) = 0.5;
uniform float threshold_g : hint_range(0.0, 1.0) = 0.5;
uniform float threshold_b : hint_range(0.0, 1.0) = 0.5;
uniform vec3 threshold_color = vec3(1.0, 1.0, 1.0);

float noise(vec2 uv) {
    return fract(sin(dot(uv, vec2(12.9898, 78.233))) * 43758.5453);
}

void fragment() {
    vec2 pixel_uv = floor(UV * pixelation) / pixelation;
    vec4 col = texture(SCREEN_TEXTURE, pixel_uv);
    float max_val = pow(2.0, bits_per_channel) - 1.0;
    col.rgb = floor(col.rgb * max_val) / max_val;
    vec3 dither = vec3(
        noise(pixel_uv + TIME),
        noise(pixel_uv + TIME + vec2(1.0, 0.0)),
        noise(pixel_uv + TIME + vec2(0.0, 1.0))
    );
    col.rgb += dither * dither_strength;
    
    // Color relaxation
    col.rgb = mix(col.rgb, relaxation_color, color_relaxation);
    
    // Threshold
    if (col.r > threshold_r) {
        col.r = threshold_color.r;
    }
    if (col.g > threshold_g) {
        col.g = threshold_color.g;
    }
    if (col.b > threshold_b) {
        col.b = threshold_color.b;
    }
    
    // Bloom
    if (col.r > bloom_threshold || col.g > bloom_threshold || col.b > bloom_threshold) {
        col.rgb += (col.rgb - bloom_threshold) * bloom_intensity;
    }
    
    COLOR = col;
}
Tags
Color Depth, dither, pixelation, retro
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.

Related shaders

sine wave camera view shader

Useful Gradient Effects All-in-one Shader

Simple Ellipse Shader

Subscribe
Notify of
guest

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Atrix
Atrix
2 months ago

it doest work its just a white screen with random colored points

Atrix
Atrix
2 months ago
Reply to  Atrix

It works now

Altere
Altere
2 months ago
Reply to  Atrix

how did you make it work