ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
halluc_lava_crack.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file halluc_lava_crack.frag
5 * @brief Vulkan fragment shader: halluc lava crack.
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 amp_high ext.audio_bands.z
18#define amp_low ext.audio_bands.x
19#define amp_mid ext.audio_bands.y
20#define amp_peak ext.u2.w
21#define amp_smooth ext.u3.w
22#define iMouse ext.mouse
23#define iResolution ext.u0.zw
24#define time_f ext.u2.y
25
26layout(set = 0, binding = 0) uniform sampler2D samp;
27
28
29
30
31// Audio
32layout(set = 0, binding = 3) uniform sampler1D spectrum;
33
34
35
36
37
38layout(location = 0) out vec4 color;
39layout(location = 0) in vec2 tc;
40
41const float iAmplitude = 1.0;
42const float iFrequency = 1.0;
43const float iBrightness = 1.0;
44const float iContrast = 1.20;
45const float iSaturation = 1.20;
46const float iHueShift = 0.0;
47const float iZoom = 1.0;
48const float iRotation = 0.0;
49const float iLavaHeat = 1.0;
50
51/**
52 * @brief Evaluates lavaPalette for this shader effect.
53 * @param t Input value for the calculation.
54 * @return Computed vec3 value.
55 */
56vec3 lavaPalette(float t) {
57 t = clamp(t, 0.0, 1.0);
58 vec3 c1 = vec3(0.04, 0.0, 0.0);
59 vec3 c2 = vec3(0.45, 0.05, 0.02);
60 vec3 c3 = vec3(0.95, 0.30, 0.05);
61 vec3 c4 = vec3(1.20, 0.85, 0.20);
62 if (t < 0.30) return mix(c1, c2, t / 0.30);
63 if (t < 0.65) return mix(c2, c3, (t - 0.30) / 0.35);
64 return mix(c3, c4, (t - 0.65) / 0.35);
65}
66
67/**
68 * @brief Evaluates wrapUV for this shader effect.
69 * @param v Input value for the calculation.
70 * @return Computed vec2 value.
71 */
72vec2 wrapUV(vec2 v) { return 1.0 - abs(1.0 - 2.0 * fract(v * 0.5)); }
73/**
74 * @brief Evaluates mxTexture for this shader effect.
75 * @param tex Input value for the calculation.
76 * @param uv Input value for the calculation.
77 * @return Computed vec4 value.
78 */
79vec4 mxTexture(sampler2D tex, vec2 uv) {
80 vec2 ts = vec2(textureSize(tex, 0));
81 vec2 eps = 0.5 / ts;
82 vec2 u = wrapUV(uv);
83 return textureLod(tex, clamp(u, eps, 1.0 - eps), 0.0);
84}
85/**
86 * @brief Evaluates rot for this shader effect.
87 * @param a Input value for the calculation.
88 * @return Computed mat2 value.
89 */
90mat2 rot(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }
91
92/**
93 * @brief Evaluates hash21 for this shader effect.
94 * @param p Input value for the calculation.
95 * @return Computed float value.
96 */
97float hash21(vec2 p) {
98 p = fract(p * vec2(31.71, 17.13));
99 p += dot(p, p + 18.5);
100 return fract(p.x * p.y);
101}
102
103// Voronoi-like F1/F2 → cracked-crust mask
104/**
105 * @brief Evaluates voronoi for this shader effect.
106 * @param p Input value for the calculation.
107 * @return Computed vec2 value.
108 */
109vec2 voronoi(vec2 p) {
110 vec2 ip = floor(p), fp = fract(p);
111 float f1 = 8.0, f2 = 8.0;
112 for (int dy = -1; dy <= 1; ++dy)
113 for (int dx = -1; dx <= 1; ++dx) {
114 vec2 nb = vec2(float(dx), float(dy));
115 vec2 jit = vec2(hash21(ip + nb), hash21(ip + nb + 19.7));
116 vec2 d = nb + jit - fp;
117 float r = dot(d, d);
118 if (r < f1) { f2 = f1; f1 = r; }
119 else if (r < f2) { f2 = r; }
120 }
121 return vec2(sqrt(f1), sqrt(f2));
122}
123
124/**
125 * @brief Evaluates lavaCrack for this shader effect.
126 * @param uv Input value for the calculation.
127 * @param center Input value for the calculation.
128 * @param t Input value for the calculation.
129 * @return Computed vec3 value.
130 */
131vec3 lavaCrack(vec2 uv, vec2 center, float t) {
132 vec2 p = uv - center;
133 p.x *= iResolution.x / iResolution.y;
134 p /= 0.5 + iZoom * 2.0;
135
136 // fractal warp
137 vec2 pf = p;
138 vec3 accTex = vec3(0.0);
139 float ring = 100.0;
140 float scale = 1.55 + iAmplitude * 0.4;
141 for (float i = 0.0; i < 4.0; i++) {
142 pf = abs(pf) - 0.20;
143 pf *= rot(t * 0.10 + iRotation + i * 0.5);
144 pf *= scale;
145 ring = min(ring, abs(length(pf) - 0.55));
146 vec2 texUV = pf * 0.5 + 0.5;
147 accTex += mxTexture(samp, texUV).rgb * (0.55 / (i + 1.0));
148 }
149
150 // Voronoi crust drifts slowly
151 vec2 vp = p * (3.5 + iAmplitude) + vec2(0.0, t * 0.15);
152 vec2 v = voronoi(vp);
153 float crack = smoothstep(0.0, 0.04, v.y - v.x); // thin crack lines
154 float crust = 1.0 - crack;
155
156 // hot lava fills the cracks; crust is blackish accTex
157 float heat = clamp(crack * iLavaHeat + 0.15, 0.0, 1.5);
158 vec3 lava = lavaPalette(heat / 1.5);
159 vec3 cool = accTex * vec3(0.35, 0.30, 0.30);
160
161 vec3 col = mix(cool, lava, crack);
162 col += lava * exp(-30.0 * ring) * 0.5 * iContrast;
163 // glowing edges between crust plates
164 col += lavaPalette(0.95) * smoothstep(0.0, 0.02, v.y - v.x) * 0.0; // (no-op base)
165 col += lavaPalette(0.80) * pow(1.0 - smoothstep(0.0, 0.06, v.y - v.x), 4.0) * 0.6;
166 return col;
167}
168
169/**
170 * @brief Executes the fragment shader entry point.
171 */
172void main() {
173 vec2 uv = tc;
174 vec2 center = vec2(0.5);
175 if (iMouse.z > 0.0) center = iMouse.xy / iResolution;
176 float bass = texture(spectrum, 0.03).r + amp_low * 0.5;
177 float midF = texture(spectrum, 0.22).r + amp_mid * 0.5;
178 float treble = texture(spectrum, 0.58).r + amp_high * 0.5;
179 float beat = max(amp_peak, bass);
180 float t = time_f * (0.07 + iFrequency * 0.20) * (1.0 + 0.6 * beat);
181
182 vec3 col = lavaCrack(uv, center, t);
183
184 float gray = dot(col, vec3(0.299, 0.587, 0.114));
185 col = mix(vec3(gray), col, iSaturation);
186 col = (col - 0.5) * iContrast + 0.5;
187 col += vec3(0.6, 0.4, 1.0) * treble * 0.18;
188 col *= iBrightness * (1.0 + 0.5 * bass);
189
190 vec2 vUV = uv * (1.0 - uv.yx);
191 float vig = pow(vUV.x * vUV.y * 15.0, 0.20);
192 col *= vig;
193
194 color = vec4(col, 1.0);
195}
layout(set=0, binding=1, std140) uniform SpriteExtended
Definition 3high.frag:7
#define iMouse
Definition 3high.frag:17
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
vec4 mxTexture(sampler2D tex, vec2 tc)
Evaluates mxTexture for this shader effect.
const float iFrequency
const float iRotation
const float iBrightness
vec2 wrapUV(vec2 tc)
Evaluates wrapUV for this shader effect.
const float iAmplitude
const float iSaturation
const float iContrast
const float iHueShift
const float iZoom
#define amp_mid
#define amp_low
#define amp_high
#define amp_peak
vec2 rot(vec2 v, float a)
Evaluates rot for this shader effect.
Definition air-bowl.frag:52
vec3 lava(float t)
Evaluates lava for this shader effect.
vec2 voronoi(vec2 p)
Evaluates voronoi for this shader effect.
float hash21(vec2 p)
Evaluates hash21 for this shader effect.
float beat(float t)
Evaluates beat for this shader effect.
vec3 spectrum(float t)
Evaluates spectrum for this shader effect.
const float iLavaHeat
vec3 lavaPalette(float t)
Evaluates lavaPalette for this shader effect.
vec3 lavaCrack(vec2 uv, vec2 center, float t)
Evaluates lavaCrack for this shader effect.