(2D Shader) How to pixelate a shader?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Woon

Background
Working on a flag shader that makes a sprite look like it a flag in the wind, but I’m trying to head towards a more pixelated style.

Question
Is there a way to “pixelize” a shader?

Here’s a link to an example:

Here’s the code for the curious:

shader_type canvas_item;
//uniform vec3 shadow_color = texture(TEXTURE, UV + vec2(0.5,0.5)).rgb;// 
vec3(0.0,0.5,0.5);
uniform int OCTAVES = 1;
uniform float SPD_OF_FOG = 0.1;

float rand(vec2 coord) {
return fract(sin(dot(coord,vec2(12.9898, 78.233)))* 43758.5453123);
}

float noise(vec2 coord) {
vec2 i = floor(coord);
vec2 f = fract(coord);

float a = rand(i);
float b = rand(i + vec2(1.0, 0.0));
float c = rand(i + vec2(0.0, 1.0));
float d = rand(i + vec2(1.0, 1.0));

vec2 cubic = f * f * (3.0 - 2.0 * f);

return mix(a, b, cubic.x) + (c - a) * cubic.y * (1.0 - cubic.x) + (d - b) * cubic.x * cubic.y;
}


float fbm(vec2 coord) {
float value = 0.0; // color changer
float scale = 0.01;
//
for(int i = 0; i < OCTAVES; i++) 
{
	value += noise(coord) * scale;
	scale *= 0.0;
	coord *= 2.0;
}
return value;
}

void fragment() {

// Wavy Shader
vec2 sprite_scale = vec2(textureSize(TEXTURE, 0));

float jagged_scale = 40.0;
vec2 noisecoord1 = UV * sprite_scale / jagged_scale;
vec2 noisecoord2 = UV * sprite_scale / jagged_scale + 4.0;

vec2 motion1 = vec2(TIME * 1.3, TIME * -0.4); // vec2(TIME * 0.3, TIME * -0.4)
vec2 motion2 = vec2(TIME * 0.1, TIME * 1.5); // vec2(TIME * 0.1, TIME * 0.5);

vec2 distort1 = vec2(noise(noisecoord1 + motion1), noise(noisecoord2 + motion1)) - vec2(0.5);
vec2 distort2 = vec2(noise(noisecoord1 + motion2), noise(noisecoord2 + motion2)) - vec2(0.5);

float powerOfDistort = 15.0; //Higher = Less Distort 
vec2 distort_sum = (distort1 + distort2) / powerOfDistort * UV.y * UV.y; // Wavy at the bottom more
vec4 color = textureLod(TEXTURE, UV + distort_sum, 0.0);


float flag_sat = 1.0;
color.rgb = mix(vec3(0.5), color.rgb, flag_sat);

float near_top = (UV.y + distort_sum.y) / (0.2 / (sprite_scale.y / 30.0));
near_top = clamp(near_top, 0.0, 1.0);
near_top = 1.0 - near_top;

color = mix(color, vec4(1.0), near_top);

float edge_lower = 0.0;
float edge_upper = edge_lower + 0.1;

if (near_top > edge_lower) {
	color.a = 0.0;
	if (near_top < edge_upper) {
		color.a = 0.0;//(edge_upper - near_top) / (edge_upper - edge_lower);
		}
}

COLOR = color;
}