PS1/PSX PostProcessing

Usage:

 

  1.  Set up the scene as follows:
    SubViewportContainer -> SubViewport -> Spatial
    where Spatial is your 3D scene.
  2. In the SubViewportContainer  add a new ShaderMaterial
  3. In the ShaderMaterial add a new Shader
  4. Copy the script below into the Shader-Editor.

 

Documentation

 

  • enabled: Easy option to switch off the shader.
  • dither_size: Defines the pixel size that is used for dithering
  • dithering: Use the dithering pattern.
  • colors: Amount of colors that will be used.

 

Hint

 

This shader is written for Godot 4.

 

Shader code
shader_type canvas_item;

render_mode unshaded;

#define MAXCOLORS 16

uniform bool enabled = true;
uniform bool dithering = true;
uniform int colors : hint_range(1, MAXCOLORS) = 12;
uniform int dither_size: hint_range(1, 8) = 1;

float dithering_pattern(ivec2 fragcoord) {
	const float pattern[] = {
		0.00, 0.50, 0.10, 0.65, 
		0.75, 0.25, 0.90, 0.35, 
		0.20, 0.70, 0.05, 0.50, 
		0.95, 0.40, 0.80, 0.30
	};
	
	int x = fragcoord.x % 4;
	int y = fragcoord.y % 4;
	
	return pattern[y * 4 + x];
}

float reduce_color(float raw, float dither, int depth) {
	float div = 1.0 / float(depth);
	float val = 0.0;
	int i = 0;

	while (i <= MAXCOLORS)
	{
		if (raw > div * (float(i + 1))) {
			i = i + 1;
			continue;
		}

		if (raw * float(depth) - float(i) <= dither * 0.999)
		{
			val = div * float(i);
		} 
		else
		{
			val = div * float(i + 1);
		}
		return val;

		i = i+1;
	}

	return val;
}

void fragment() {
	vec4 raw = texture(TEXTURE, SCREEN_UV);
	ivec2 uv = ivec2(FRAGCOORD.xy / float(dither_size));

	if (enabled == true){
		float dithering_value = 1.0;
		if (dithering)
		{
			dithering_value = dithering_pattern(uv);
		}
		
		COLOR.r = reduce_color(raw.r, (dithering_value - 0.5) * dithering_value + 0.5, colors - 1);
		COLOR.g = reduce_color(raw.g, (dithering_value - 0.5) * dithering_value + 0.5, colors - 1);
		COLOR.b = reduce_color(raw.b, (dithering_value - 0.5) * dithering_value + 0.5, colors - 1);

	} else {
		COLOR.rgb = raw.rgb;
	}
}
Live Preview
Tags
godot4, lowpoly, ps1, psx, 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.

More from Grau

Related shaders

Comments 15

  1. The only dithering shader I ever got to work. Thank you very much for this great work.

    3
    1. skyth

      if you think most canvas item shaders dont work in 3d.. they do. just add colorrect select anchor preset and check top level in visible
      it'll work
      btw feel free to ask me questions if you want
      tis my discord username "skyth_."

      -4
    2. Orrte

      Hola perdona que lo escriba en español, pero con spatial se refiere a un nodo3D osea el nivel debe estar dentro del subviewport

      5
  2. cortrano

    Is that possible to use this shader with ColorRect/TextureRect Instead?

    10
    1. shader_type canvas_item;

       

      render_mode unshaded;

       

      #define MAXCOLORS 16

       

      uniform bool enabled = true;

       

      ...

       

      // add a line
      uniform sampler2D SCREEN_TEXTURE: hint_screen_texture, filter_linear_mipmap, repeat_disable;

       

      ...

       

      void fragment() {
      // replace 'TEXTURE' with 'SCREEN_TEXTURE'
      vec4 raw = texture(SCREEN_TEXTURE, SCREEN_UV);
      ivec2 uv = ivec2(FRAGCOORD.xy / float(dither_size));

       

      ...
      }

      2
  3. iwin

    How do i make a canvaslayer not to show pixelated, ive got a paper with writing on it that gets pixelated too, but i need it in it's original form.

    0
  4. You can fix the gray/white issue by:
    Adding this line near the top of the file: uniform sampler2D screen_texture: hint_screen_texture;Replacing "TEXTURE" with "screen_texture" in the line vec4 raw = texture(TEXTURE, SCREEN_UV);

    3
  5. Replace reduce_color function with this for simplicity and efficiency

    float reduce_color(float raw, float dither, int depth) {
        float scaled = raw * float(depth) + dither - 0.5;
        return clamp(floor(scaled) / float(depth), 0.0, 1.0);
    }
    
    1
  6. aneuen2002

    Hi, I applied this effect to a personal project and I really liked it, but I have a question, considering I'm new to programming with Godot. How do I make the view 320x240 while using this effect in a 1280x720 window? I'm confused about SubViewportContainer and SubViewport. I tried changing the project settings, the sizes of the SubViewport container and subViewport, etc., but I haven't been able to get it to work.

    0