ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
brokenglass.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file brokenglass.frag
5 * @brief Vulkan fragment shader: brokenglass.
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) in vec2 tc;
21layout(location = 0) out vec4 color;
22
23layout(set = 0, binding = 0) uniform sampler2D samp;
24
25
26// Simple hash for pseudo-random crack generation
27/**
28 * @brief Evaluates hash for this shader effect.
29 * @param p Input value for the calculation.
30 * @return Computed float value.
31 */
32float hash(vec2 p) {
33 return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
34}
35
36// Voronoi for crack-like cells
37/**
38 * @brief Evaluates voronoi for this shader effect.
39 * @param uv Input value for the calculation.
40 * @return Computed float value.
41 */
42float voronoi(vec2 uv) {
43 vec2 g = floor(uv);
44 vec2 f = fract(uv);
45 float res = 8.0;
46 for (int y=-1; y<=1; y++) {
47 for (int x=-1; x<=1; x++) {
48 vec2 lattice = vec2(x,y);
49 vec2 p = hash(g+lattice) * vec2(0.5+0.5*sin(time_f*0.2));
50 vec2 diff = lattice + p - f;
51 float d = length(diff);
52 res = min(res, d);
53 }
54 }
55 return res;
56}
57
58/**
59 * @brief Executes the fragment shader entry point.
60 */
61void main(void) {
62 vec2 uv = tc * iResolution.xy / min(iResolution.x, iResolution.y);
63
64 // Crack mask that spreads with time
65 float cracks = smoothstep(0.05, 0.15, voronoi(uv * (2.0 + 0.5*sin(time_f*0.1))));
66
67 // Distortion based on crack intensity
68 vec2 offset = vec2(cos(uv.y*20.0 + time_f*0.5), sin(uv.x*20.0 - time_f*0.5))
69 * (1.0 - cracks) * 0.02;
70
71 // Sample texture with refracted coords
72 vec4 texCol = texture(samp, tc + offset);
73
74 // Blend cracks as dark fracture lines
75 vec3 crackColor = mix(vec3(0.0), texCol.rgb, cracks);
76
77 color = vec4(crackColor, 1.0);
78}
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 iResolution
Definition 3high.frag:18
#define time_f
Definition 3high.frag:19
float hash(vec2 p)
Evaluates hash for this shader effect.
vec2 voronoi(vec2 p)
Evaluates voronoi for this shader effect.
float lattice(vec2 point, float bass, float middle, float high)
Evaluates lattice for this shader effect.