ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
glitch1.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file glitch1.frag
5 * @brief Vulkan fragment shader: glitch1.
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 iMouse ext.mouse
18#define iResolution ext.u0.zw
19#define time_f ext.u2.y
20
21layout(location = 0) in vec2 tc;
22layout(location = 0) out vec4 color;
23
24layout(set = 0, binding = 0) uniform sampler2D samp;
25
26
27
28// Helper Functions
29/**
30 * @brief Evaluates random for this shader effect.
31 * @param st Input value for the calculation.
32 * @return Computed float value.
33 */
34float random(vec2 st) {
35 return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);
36}
37
38/**
39 * @brief Evaluates glitchOffset for this shader effect.
40 * @param uv Input value for the calculation.
41 * @param seed Input value for the calculation.
42 * @return Computed vec2 value.
43 */
44vec2 glitchOffset(vec2 uv, vec2 seed) {
45 float strength = random(seed) * 0.1 - 0.05; // Random strength
46 if (random(seed * 2.0 + time_f) > 0.5) {
47 uv.y += strength; // Horizontal distortion
48 } else {
49 uv.x += strength; // Vertical distortion
50 }
51 return uv;
52}
53
54/**
55 * @brief Executes the fragment shader entry point.
56 */
57void main(void) {
58 vec2 uv = tc;
59
60 // Random seed based on uv and time
61 vec2 seed = floor(uv * 10.0) + vec2(time_f);
62
63 // Apply glitch offset
64 vec2 glitch_uv = glitchOffset(uv, seed);
65
66 // Sample the texture with the distorted coordinates
67 vec4 texColor = texture(samp, glitch_uv);
68
69 // Additional glitch color distortions
70 float glitch_strength = random(seed) * 0.3;
71 if (random(seed + 1.0) > 0.7) {
72 texColor.r += glitch_strength;
73 texColor.g -= glitch_strength;
74 }
75
76 color = texColor;
77}
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
#define seed
Definition air-bowl.frag:20
float random(vec2 st)
Evaluates random for this shader effect.
vec2 glitchOffset(vec2 uv, vec2 seed)
Evaluates glitchOffset for this shader effect.
Definition glitch1.frag:44
#define strength
Definition ol.frag:16