55 lines
1.7 KiB
Plaintext
55 lines
1.7 KiB
Plaintext
uniform highp float pixel = 1.0;
|
|
uniform highp vec2 red_offset = vec2(0.0, 0.0);
|
|
uniform highp vec2 green_offset = vec2(0.0, 0.0);
|
|
uniform highp vec2 blue_offset = vec2(0.0, 0.0);
|
|
uniform highp float alpha = 1.0;
|
|
uniform highp float rand_strength = 1.0;
|
|
|
|
uniform highp vec4 affected = vec4(0.0, 0.0, 1.0, 1.0);
|
|
|
|
highp float Hash21(highp vec2 p) {
|
|
p = fract(p*vec2(123.34, 456.21));
|
|
p += dot(p, p+45.32);
|
|
|
|
return fract(p.x*p.y);
|
|
}
|
|
|
|
highp vec2 pixelize(highp vec2 uv) {
|
|
highp float mult = 5000.0 / (pixel * pixel);
|
|
uv.x = floor(uv.x * mult) / mult;
|
|
uv.y = floor(uv.y * mult) / mult;
|
|
return uv;
|
|
}
|
|
|
|
highp vec4 chroma(highp vec2 uv, sampler2D tex) {
|
|
highp vec4 col = texture(tex, uv);
|
|
if (abs(red_offset.x) + abs(red_offset.y) > 0.001) {
|
|
col.r = texture(tex, vec2(uv.x + red_offset.x, uv.y + red_offset.y)).r;
|
|
}
|
|
if (abs(green_offset.x) + abs(green_offset.y) > 0.001) {
|
|
col.g = texture(tex, vec2(uv.x + green_offset.x, uv.y + green_offset.y)).g;
|
|
}
|
|
if (abs(blue_offset.x) + abs(blue_offset.y) > 0.001) {
|
|
col.b = texture(tex, vec2(uv.x + blue_offset.x, uv.y + blue_offset.y)).b;
|
|
}
|
|
|
|
return col;
|
|
}
|
|
|
|
void fragment() {
|
|
highp vec2 normal_uv = UV;
|
|
highp vec4 normal_col = texture(TEXTURE, UV);
|
|
if (normal_uv.x < affected.x || normal_uv.y < affected.y || normal_uv.x > affected.x + affected.z || normal_uv.y > affected.y + affected.a) {
|
|
COLOR = normal_col;
|
|
}
|
|
else {
|
|
highp vec2 uv = pixelize(UV);
|
|
highp vec4 col = chroma(uv, TEXTURE);
|
|
col.a = col.a * alpha;
|
|
highp vec2 id = floor(uv * 10.0);
|
|
highp float alpha_rand = Hash21(id + floor(TIME*10.0));
|
|
col = col * ( alpha_rand + (rand_strength * (1.0-alpha_rand)) );
|
|
COLOR = col;
|
|
}
|
|
}
|