shader_type canvas_item;

uniform sampler2D main_texture;
uniform float granularity : hint_range(5, 30)  = 15.0;
uniform float opacity_limit;

float random (vec2 uv) {
    return fract(sin(dot(uv.xy,
        vec2(12.9898,78.233))) * 43758.5453123);
}

void vertex() {
	// Called for every vertex the material is visible on.
	
}

void fragment() {
	// Called for every pixel the material is visible on.
	vec2 uv = UV;
	float g = ( pow(granularity, 2));
	uv = round((uv * g)) / g;
	uv.y = TIME * uv.y + TIME * .05;
	uv.x = 10.0 * TIME * uv.x + TIME * 1.0;
	float val = random(uv);
	float op = random(-uv) / val;
	float alpha = 1.0;
	if(op < opacity_limit){
		alpha = 0.0;
	}
	vec4 color = vec4(val, val, val, alpha * COLOR.a);
	COLOR = color;
}

//void light() {
//	// Called for every pixel for every light affecting the CanvasItem.
//	// Uncomment to replace the default light processing function with this one.
//}
