ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
glitch-noise.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file glitch-noise.frag
5 * @brief Vulkan fragment shader: glitch-noise.
6 */
7layout(set = 0, binding = 1, std140) uniform SpriteExtended {
8 vec4 mouse;
9 vec4 u0;
10 vec4 u1;
11 vec4 u2;
12 vec4 u3;
13 vec4 custom_uniforms[16];
14 vec4 audio_bands;
15 vec4 audio_history;
17#define iResolution ext.u0.zw
18#define time_f ext.u2.y
19
20layout(location = 0) out vec4 color;
21layout(location = 0) in vec2 tc;
22layout(set = 0, binding = 0) uniform sampler2D samp;
23
24
25
26/**
27 * @brief Evaluates rand for this shader effect.
28 * @param co Input value for the calculation.
29 * @return Computed float value.
30 */
31float rand(vec2 co) {
32 return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
33}
34
35/**
36 * @brief Evaluates noise for this shader effect.
37 * @param pos Input value for the calculation.
38 * @return Computed float value.
39 */
40float noise(vec2 pos) {
41 vec2 i = floor(pos);
42 vec2 f = fract(pos);
43 vec2 u = f * f * (3.0 - 2.0 * f);
44 return mix(mix(rand(i + vec2(0.0, 0.0)), rand(i + vec2(1.0, 0.0)), u.x),
45 mix(rand(i + vec2(0.0, 1.0)), rand(i + vec2(1.0, 1.0)), u.x), u.y);
46}
47
48/**
49 * @brief Executes the fragment shader entry point.
50 */
51void main(void) {
52 vec2 uv = tc;
53 float glitchStrength = 0.01;
54 float timeNoise = noise(uv * 10.0 + time_f * 0.5);
55 uv.x += (rand(uv + time_f) - 0.5) * glitchStrength;
56 uv.y += (rand(uv + time_f * 1.5) - 0.5) * glitchStrength;
57 vec4 texColor = texture(samp, uv);
58 vec4 colorShift = vec4(texColor.r, texColor.g * 0.5 + 0.5 * timeNoise, texColor.b * 0.5 + 0.5 * (1.0 - timeNoise), texColor.a);
59 float glitchNoise = rand(uv + time_f);
60 vec4 glitchColor = vec4(vec3(sin(glitchNoise * time_f)), 1.0) * glitchStrength ;
61 color = mix(colorShift, glitchColor, glitchStrength * glitchNoise);
62 color = sin(color * time_f);
63 color.a = 1.0;
64}
float rand(vec2 co)
Evaluates rand for this shader effect.
Definition 3high.frag:40
layout(set=0, binding=1, std140) uniform SpriteExtended
Definition 3high.frag:7
ext
Definition 3high.frag:16
void main(void)
Executes the fragment shader entry point.
Definition 3high.frag:47
#define time_f
Definition 3high.frag:19
vec4 colorShift(vec4 col)
Evaluates colorShift for this shader effect.
Definition af_scale.frag:84
float noise(vec2 p)
Evaluates noise for this shader effect.