Closed anissen closed 3 years ago
So you'd like to be able to trigger the glitch by, for example, calling RenderLayer.triggerGlitch()
?
Yeah, that was the idea. E.g. having a RenderLayer.randomGlitch()
and RenderLayer.glitch(x, y, strength, duration)
sort of like FlxG.camera.shake()
. You could then have a new GlitchLayer(glitchChance, ...)
that uses RenderLayer
.
For my purposes, I went the shader way (possible with the new postprocessing support in HaxeFlixel). The following fragment shader make a nice glitchy effect:
float rand(vec2 co) {
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
void main() {
// (...)
if (rand(vec2(1.0 - uTime, sin(uTime))) > 0.98) {
shift = 0.1 * rand(vec2(uTime, uTime));
}
col.r = texture2D(uImage0, vec2(uv.x + shift, uv.y)).x;
col.g = texture2D(uImage0, vec2(uv.x, uv.y)).y;
col.b = texture2D(uImage0, vec2(uv.x - shift, uv.y)).z;
// (...)
}
Right now, the glitch effect is tied into some logic that handles the chance of glitches. In my use case, I need to be able to trigger the glitches myself. So I propose to separate the glitch effect and the "glitch chance"-logic into separate classes.