ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
ant_gem_metal_fracture.frag
Go to the documentation of this file.
1#version 450
2
3layout(set = 0, binding = 1, std140) uniform SpriteExtended {
4 vec4 mouse;
5 vec4 u0;
6 vec4 u1;
7 vec4 u2;
8 vec4 u3;
9 vec4 custom_uniforms[16];
10 vec4 audio_bands;
11 vec4 audio_history;
13#define amp_peak ext.u2.w
14#define amp_smooth ext.u3.w
15#define iResolution ext.u0.zw
16#define time_f ext.u2.y
17
18/**
19 * @file ant_gem_metal_fracture.frag
20 * @brief Vulkan fragment shader: ant gem metal fracture.
21 */
22// ant_gem_metal_fracture
23// Fractured metal surface with Voronoi cracks and spectrum-colored stress lines
24layout(location = 0) in vec2 tc;
25layout(location = 0) out vec4 color;
26layout(set = 0, binding = 0) uniform sampler2D samp;
27
28
29
30
31layout(set = 0, binding = 3) uniform sampler1D spectrum;
32
33/**
34 * @brief Evaluates metalSpectrum for this shader effect.
35 * @param t Input value for the calculation.
36 * @return Computed vec3 value.
37 */
38vec3 metalSpectrum(float t) {
39 return vec3(0.5 + 0.5 * cos(6.28318 * (t + vec3(0.0, 0.33, 0.67))));
40}
41
42/**
43 * @brief Evaluates hash2 for this shader effect.
44 * @param p Input value for the calculation.
45 * @return Computed vec2 value.
46 */
47vec2 hash2(vec2 p) {
48 p = vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)));
49 return fract(sin(p) * 43758.5453);
50}
51
52/**
53 * @brief Executes the fragment shader entry point.
54 */
55void main(void) {
56 float bass = texture(spectrum, 0.04).r;
57 float mid = texture(spectrum, 0.22).r;
58 float hiMid = texture(spectrum, 0.40).r;
59 float treble = texture(spectrum, 0.58).r;
60 float air = texture(spectrum, 0.80).r;
61
62 vec2 uv = tc * 2.0 - 1.0;
63 uv.x *= iResolution.x / iResolution.y;
64
65 float r = length(uv);
66 float angle = atan(uv.y, uv.x);
67
68 // Voronoi fracture pattern
69 float cellScale = 6.0 + bass * 4.0;
70 vec2 cellUV = uv * cellScale;
71 vec2 cellID = floor(cellUV);
72 vec2 cellF = fract(cellUV);
73
74 float minDist = 10.0;
75 float secondDist = 10.0;
76 vec2 nearestID = vec2(0.0);
77
78 for (int y = -1; y <= 1; y++) {
79 for (int x = -1; x <= 1; x++) {
80 vec2 neighbor = vec2(float(x), float(y));
81 vec2 point = hash2(cellID + neighbor);
82 point = 0.5 + 0.5 * sin(time_f * 0.5 + 6.28318 * point);
83 float d = length(cellF - neighbor - point);
84 if (d < minDist) {
85 secondDist = minDist;
86 minDist = d;
87 nearestID = cellID + neighbor;
88 } else if (d < secondDist) {
89 secondDist = d;
90 }
91 }
92 }
93
94 // Crack lines at cell boundaries
95 float crack = secondDist - minDist;
96 float crackMask = smoothstep(0.0, 0.05 + treble * 0.03, crack);
97 float crackGlow = 1.0 - crackMask;
98
99 // Texture per cell with offset
100 float cellHash = fract(sin(dot(nearestID, vec2(12.9898, 78.233))) * 43758.5453);
101 vec2 cellOffset = vec2(cellHash * 0.02, fract(cellHash * 7.0) * 0.02);
102 vec2 sampUV = tc + cellOffset * (1.0 + mid * 2.0);
103
104 // Chromatic split
105 float chroma = 0.008 + air * 0.02;
106 vec3 baseTex;
107 baseTex.r = texture(samp, sampUV + vec2(chroma, 0.0)).r;
108 baseTex.g = texture(samp, sampUV).g;
109 baseTex.b = texture(samp, sampUV - vec2(chroma, 0.0)).b;
110
111 // Stress coloring in cracks
112 vec3 stressColor = metalSpectrum(cellHash + time_f * 0.2 + bass);
113 vec3 crackColor = stressColor * crackGlow * (2.0 + hiMid * 3.0);
114
115 // Metallic sheen on cells
116 float sheen = sin(r * 10.0 + angle * 3.0 + time_f) * 0.5 + 0.5;
117 vec3 metalSheen = metalSpectrum(sheen + time_f * 0.1) * 0.15;
118
119 vec3 finalColor = baseTex * crackMask + crackColor;
120 finalColor += metalSheen * crackMask;
121
122 // Central glow
123 float center = exp(-r * (5.0 - amp_smooth * 3.0));
124 finalColor += vec3(1.0, 0.95, 0.9) * center * (1.5 + amp_peak * 2.0);
125
126 color = vec4(finalColor, 1.0);
127}
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
#define amp_smooth
#define amp_peak
vec3 metalSpectrum(float t)
Evaluates metalSpectrum for this shader effect.
vec2 hash2(vec2 p)
Evaluates hash2 for this shader effect.
vec3 spectrum(float t)
Evaluates spectrum for this shader effect.