Files
Burn-My-Windows/resources/shaders/pixelate.frag
T
Simon Schneegans 9c547e2771 🎉 Add pixelate effect
2022-08-27 13:39:27 +02:00

36 lines
1.8 KiB
GLSL

//////////////////////////////////////////////////////////////////////////////////////////
// ) ( //
// ( /( ( ( ) ( ( ( ( )\ ) ( ( //
// )\()) ))\ )( ( ( )\ ) )\))( )\ ( (()/( ( )\))( ( //
// ((_)\ /((_|()\ )\ ) )\ '(()/( ((_)()((_) )\ ) ((_)))\((_)()\ )\ //
// | |(_|_))( ((_)_(_/( _((_)) )(_)) _(()((_|_)_(_/( _| |((_)(()((_|(_) //
// | '_ \ || | '_| ' \)) | ' \()| || | \ V V / | ' \)) _` / _ \ V V (_-< //
// |_.__/\_,_|_| |_||_| |_|_|_| \_, | \_/\_/|_|_||_|\__,_\___/\_/\_//__/ //
// |__/ //
// Copyright (c) 2021 Simon Schneegans //
// Released under the GPLv3 or later. See LICENSE file for details. //
//////////////////////////////////////////////////////////////////////////////////////////
// The content from common.glsl is automatically prepended to each shader effect.
uniform float uNoise;
uniform float uPixelSize;
void main() {
// We simply inverse the progress for opening windows.
float progress = uForOpening ? 1.0 - uProgress : uProgress;
// The current level of pixelation increases with the progress.
float pixelSize = ceil(uPixelSize * progress + 1.0);
vec2 pixelGrid = vec2(pixelSize) / uSize;
vec2 texcoord = iTexCoord.st - mod(iTexCoord.st, pixelGrid) + pixelGrid * 0.5;
vec4 oColor = getInputColor(texcoord);
// Hide selected pixels based on some random noise.
float random = simplex2DFractal(texcoord * uNoise * uSize / 1000.0);
if (random * 1.5 - 0.25 < progress) {
oColor.a = 0.0;
}
setOutputColor(oColor);
}