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;
}
Live Preview
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

guest

7 Comments
Oldest
Newest Most Voted
Atrix
Atrix
2 years ago

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

Atrix
Atrix
2 years ago
Reply to  Atrix

It works now

Altere
Altere
2 years ago
Reply to  Atrix

how did you make it work

Atrix
Atrix
1 year ago
Reply to  Altere

You might need to adjust some of the values like Color Relaxation and Threshold

Atrix
Atrix
1 year ago
Reply to  Atrix

Also sorry for not responding. i forgot the website existed

punchinelli
punchinelli
13 days ago

This shader does work – you have to adjust these variables to get it going properly so you can see what you’re doing:

Opacity to .5
Pixelation to 300
Threshold_R, G and B to 1
Bits per channel to 5.0

Lowering bits per channel gets some of the interesting effects in the screenshots the author submitted above. You can play around with the relaxation and threshold colors to do a “color replace” sort of deal with R, G and B as well.

The threshold and relaxation colors don’t have to be adjusted (yet)

Last edited 13 days ago by punchinelli