🔧 Tweak glitch effect
This commit is contained in:
@@ -15,23 +15,22 @@
|
||||
// The content from common.glsl is automatically prepended to each shader effect.
|
||||
|
||||
uniform vec3 uColor;
|
||||
uniform float uSeed;
|
||||
uniform float uScale;
|
||||
uniform float uStrength;
|
||||
uniform float uSpeed;
|
||||
|
||||
// Somewhat inspired by https://www.shadertoy.com/view/XtK3W3
|
||||
void main() {
|
||||
float progress = (uForOpening ? 1.0 - uProgress : uProgress);
|
||||
float time = 7.5 * progress * uDuration * uSpeed;
|
||||
float progress = easeInQuad(uForOpening ? 1.0 - uProgress : uProgress);
|
||||
float time = progress * uDuration * uSpeed;
|
||||
float strength = uStrength * progress;
|
||||
float displace = 750.0 * strength / uSize.x;
|
||||
float yPos = uScale * uSize.y * iTexCoord.y;
|
||||
float displace = 1000.0 * strength / uSize.x;
|
||||
float yPos = uScale * uSize.y * (iTexCoord.y + uSeed * 10.0);
|
||||
|
||||
// Create large, incidental noise waves.
|
||||
float noise = clamp(simplex2D(vec2(time, yPos * 0.002)) - 0.3, 0.0, 1.0);
|
||||
|
||||
// Offset by smaller, constant noise waves.
|
||||
noise = noise + (simplex2D(vec2(time * 10.0, yPos * 0.05)) - 0.5) * 0.15;
|
||||
// Create large noise waves and add some smaller noise waves.
|
||||
float noise = clamp(simplex2D(vec2(time, yPos * 0.002)) - 0.5, 0.0, 1.0);
|
||||
noise += (simplex2D(vec2(time * 10.0, yPos * 0.05)) - 0.5) * 0.15;
|
||||
|
||||
// Apply the noise as x displacement for every line.
|
||||
float xPos = clamp(iTexCoord.x - displace * noise * noise, 0.0, 1.0);
|
||||
@@ -42,21 +41,25 @@ void main() {
|
||||
float interferenceStrength = noise * min(strength, 1.0);
|
||||
oColor.rgb = mix(oColor.rgb, interference, interferenceStrength);
|
||||
|
||||
// Apply a line pattern every 4 pixels.
|
||||
// Mix in some grainy noise.
|
||||
vec3 grain = uColor * simplex2D(uSize * iTexCoord + vec2(time * 100.0));
|
||||
float grainStrength = 0.2 * min(strength, 1.0);
|
||||
oColor.rgb = mix(oColor.rgb, grain, grainStrength);
|
||||
|
||||
// Add a subtle line pattern every 4 pixels.
|
||||
if (floor(mod(yPos * 0.25, 2.0)) == 0.0) {
|
||||
oColor.rgb = mix(uColor, oColor.rgb, 1.0 - (0.15 * noise));
|
||||
}
|
||||
|
||||
// Shift green/blue channels.
|
||||
oColor.g = mix(oColor.g,
|
||||
getInputColor(vec2(xPos + noise * 0.1 * displace, iTexCoord.y)).g, 0.25);
|
||||
oColor.b = mix(oColor.b,
|
||||
getInputColor(vec2(xPos - noise * 0.1 * displace, iTexCoord.y)).b, 0.25);
|
||||
float offset = 0.1 * noise * displace;
|
||||
oColor.g = mix(oColor.g, getInputColor(vec2(xPos + offset, iTexCoord.y)).g, 0.25);
|
||||
oColor.b = mix(oColor.b, getInputColor(vec2(xPos - offset, iTexCoord.y)).b, 0.25);
|
||||
|
||||
// Dissolve the window.
|
||||
if (progress > mix(1.0 - noise, max(max(oColor.r, oColor.g), oColor.b), 0.5)) {
|
||||
oColor.a = 0.0;
|
||||
}
|
||||
float fadeDelay = 2.0;
|
||||
float alpha = clamp(noise + 1.0 + fadeDelay - (3.0 + fadeDelay) * progress, 0.0, 1.0);
|
||||
oColor.a *= alpha;
|
||||
|
||||
setOutputColor(oColor);
|
||||
}
|
||||
@@ -665,19 +665,19 @@ SPDX-License-Identifier: CC0-1.0
|
||||
</key>
|
||||
|
||||
<key name="glitch-strength" type="d">
|
||||
<default>1.0</default>
|
||||
<default>2.0</default>
|
||||
<summary>Glitch Strength</summary>
|
||||
<description>The intensity of the effect.</description>
|
||||
</key>
|
||||
|
||||
<key name="glitch-speed" type="d">
|
||||
<default>1.0</default>
|
||||
<default>2.0</default>
|
||||
<summary>Glitch Speed</summary>
|
||||
<description>The speed of the effect.</description>
|
||||
</key>
|
||||
|
||||
<key name="glitch-color" type="s">
|
||||
<default>"rgb(255, 200, 50)"</default>
|
||||
<default>"rgb(100, 160, 255)"</default>
|
||||
<summary>Glitch Color</summary>
|
||||
<description>The color of the effect.</description>
|
||||
</key>
|
||||
|
||||
@@ -43,6 +43,7 @@ var Glitch = class {
|
||||
const Clutter = imports.gi.Clutter;
|
||||
|
||||
// Store uniform locations of newly created shaders.
|
||||
shader._uSeed = shader.get_uniform_location('uSeed');
|
||||
shader._uColor = shader.get_uniform_location('uColor');
|
||||
shader._uScale = shader.get_uniform_location('uScale');
|
||||
shader._uStrength = shader.get_uniform_location('uStrength');
|
||||
@@ -52,7 +53,11 @@ var Glitch = class {
|
||||
shader.connect('begin-animation', (shader, settings) => {
|
||||
const c = Clutter.Color.from_string(settings.get_string('glitch-color'))[1];
|
||||
|
||||
// If we are performing an integration tests, we use a fixed seed.
|
||||
const testMode = settings.get_boolean('test-mode');
|
||||
|
||||
// clang-format off
|
||||
shader.set_uniform_float(shader._uSeed, 1, [testMode ? 0 : Math.random()]);
|
||||
shader.set_uniform_float(shader._uColor, 3, [c.red / 255, c.green / 255, c.blue / 255]);
|
||||
shader.set_uniform_float(shader._uScale, 1, [settings.get_double('glitch-scale')]);
|
||||
shader.set_uniform_float(shader._uStrength, 1, [settings.get_double('glitch-strength')]);
|
||||
|
||||
Reference in New Issue
Block a user