Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shader_type canvas_item;
- uniform sampler2D palette; // The palette texture.
- uniform float shift; // The shift amount on the palette texture.
- // Rounds a value.
- float roundval(float value){
- float frac = value - floor(value);
- float result;
- if(frac < 0.5) { result = floor(value); }
- if(frac >= 0.5) { result = ceil(value); }
- return result;
- }
- void fragment()
- {
- vec4 pixcol;
- // The pixel coordinate being operated on.
- vec2 pixpos = SCREEN_UV;
- float over_x = ceil(UV.x * 16.0);
- float over_y = ceil(UV.y * 16.0);
- // Get dither pixel
- vec2 overlayCoord = vec2(over_x, over_y);
- // Get 1 or 0 based on the pixel location.
- float overlayPixelColor = mod(overlayCoord.x + overlayCoord.y, 2.0);
- // Dither is black and white every other pixel.
- vec4 overlayPixel = vec4(overlayPixelColor, overlayPixelColor, overlayPixelColor, 1);
- // Get base color.
- pixcol = vec4(texture(SCREEN_TEXTURE, SCREEN_UV).rgb, 0);
- // Mix dither texture.
- pixcol = mix(pixcol, overlayPixel, 0.1);
- // Determine the brightness of the pixel in a dumb way.
- float gray = (pixcol.r + pixcol.g + pixcol.b) / 3.0;
- // Round it to the nearest 0.25.
- gray = roundval(gray / 0.25) * 0.25;
- // Map the palette to the pixel based on the brightness and shift.
- pixcol = texture(palette, vec2(gray, shift));
- // Multiply through the gl_Color for final output.
- COLOR = pixcol;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement