ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
hallu_code_abyssal_opaline.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file hallu_code_abyssal_opaline.frag
5 * @brief Vulkan fragment shader: hallu code abyssal opaline.
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 TAU = 6.28318530718;
42const float iBrightness = 1.02;
43const float iContrast = 1.16;
44const float iSaturation = 1.36;
45
46/**
47 * @brief Evaluates rot for this shader effect.
48 * @param a Input value for the calculation.
49 * @return Computed mat2 value.
50 */
51mat2 rot(float a) {
52 float c = cos(a), s = sin(a);
53 return mat2(c, -s, s, c);
54}
55
56/**
57 * @brief Evaluates wrapUV for this shader effect.
58 * @param uv Input value for the calculation.
59 * @return Computed vec2 value.
60 */
61vec2 wrapUV(vec2 uv) {
62 return 1.0 - abs(1.0 - 2.0 * fract(uv * 0.5));
63}
64
65/**
66 * @brief Evaluates sampleMirror for this shader effect.
67 * @param uv Input value for the calculation.
68 * @return Computed vec3 value.
69 */
70vec3 sampleMirror(vec2 uv) {
71 vec2 size = vec2(textureSize(samp, 0));
72 vec2 edge = 0.5 / size;
73 return textureLod(samp, clamp(wrapUV(uv), edge, 1.0 - edge), 0.0).rgb;
74}
75
76/**
77 * @brief Evaluates hash21 for this shader effect.
78 * @param p Input value for the calculation.
79 * @return Computed float value.
80 */
81float hash21(vec2 p) {
82 p = fract(p * vec2(123.34, 456.21));
83 p += dot(p, p + 45.32);
84 return fract(p.x * p.y);
85}
86
87/**
88 * @brief Evaluates noise for this shader effect.
89 * @param p Input value for the calculation.
90 * @return Computed float value.
91 */
92float noise(vec2 p) {
93 vec2 i = floor(p);
94 vec2 f = fract(p);
95 vec2 u = f * f * (3.0 - 2.0 * f);
96 return mix(mix(hash21(i), hash21(i + vec2(1.0, 0.0)), u.x),
97 mix(hash21(i + vec2(0.0, 1.0)), hash21(i + 1.0), u.x), u.y);
98}
99
100/**
101 * @brief Evaluates fbm for this shader effect.
102 * @param p Input value for the calculation.
103 * @return Computed float value.
104 */
105float fbm(vec2 p) {
106 float sum = 0.0;
107 float amplitude = 0.52;
108 mat2 octave = mat2(1.74, 1.08, -1.08, 1.74);
109 for (int i = 0; i < 7; ++i) {
110 sum += amplitude * noise(p);
111 p = octave * p + vec2(0.13, -0.09);
112 amplitude *= 0.49;
113 }
114 return sum;
115}
116
117/**
118 * @brief Evaluates curlField for this shader effect.
119 * @param p Input value for the calculation.
120 * @param t Input value for the calculation.
121 * @return Computed vec2 value.
122 */
123vec2 curlField(vec2 p, float t) {
124 float e = 0.025;
125 float n1 = fbm(p + vec2(0.0, e) + t * 0.035);
126 float n2 = fbm(p - vec2(0.0, e) + t * 0.035);
127 float n3 = fbm(p + vec2(e, 0.0) - t * 0.029);
128 float n4 = fbm(p - vec2(e, 0.0) - t * 0.029);
129 return vec2(n1 - n2, n4 - n3) / (2.0 * e);
130}
131
132/**
133 * @brief Evaluates opalPalette for this shader effect.
134 * @param t Input value for the calculation.
135 * @return Computed vec3 value.
136 */
137vec3 opalPalette(float t) {
138 vec3 base = vec3(0.50);
139 vec3 range = vec3(0.50);
140 vec3 rate = vec3(1.0, 0.78, 1.24);
141 vec3 phase = vec3(0.01, 0.27, 0.58);
142 return base + range * cos(TAU * (rate * t + phase));
143}
144
145// Integer angular harmonics guarantee continuity across the atan branch cut.
146/**
147 * @brief Evaluates angularOpal for this shader effect.
148 * @param angle Input value for the calculation.
149 * @param phase Input value for the calculation.
150 * @return Computed vec3 value.
151 */
152vec3 angularOpal(float angle, float phase) {
153 vec3 harmonic = vec3(1.0, 2.0, 3.0);
154 vec3 offset = vec3(0.02, 0.31, 0.61);
155 return 0.5 + 0.5 * cos(harmonic * angle + TAU * (phase + offset));
156}
157
158/**
159 * @brief Evaluates gyroid for this shader effect.
160 * @param p Input value for the calculation.
161 * @return Computed float value.
162 */
163float gyroid(vec3 p) {
164 return dot(sin(p), cos(p.yzx));
165}
166
167/**
168 * @brief Evaluates abyssalOpal for this shader effect.
169 * @param uv Input value for the calculation.
170 * @param center Input value for the calculation.
171 * @param t Input value for the calculation.
172 * @param audio Input value for the calculation.
173 * @return Computed vec3 value.
174 */
175vec3 abyssalOpal(vec2 uv, vec2 center, float t, vec3 audio) {
176 float aspect = iResolution.x / max(iResolution.y, 1.0);
177 vec2 p = (uv - center) * vec2(aspect, 1.0);
178 float originalRadius = length(p);
179 float angle = atan(p.y, p.x);
180
181 // Spiral the image into a deep lens, then advect it through a curl field.
182 float lens = 1.0 / (0.24 + originalRadius);
183 float twist = 1.05 * exp(-1.7 * originalRadius) + audio.y * 0.20;
184 p *= rot(t * 0.08 + twist * sin(t * 0.31 + originalRadius * 7.0));
185 vec2 curl = curlField(p * 1.85 + vec2(cos(t * 0.13), sin(t * 0.11)), t);
186 p += curl * (0.075 + audio.x * 0.035);
187
188 vec2 q = vec2(fbm(p * 2.4 + curl + vec2(t * 0.12, 0.0)),
189 fbm(p.yx * 2.1 - curl + vec2(4.7, -t * 0.10)));
190 vec2 r = vec2(fbm(p * 3.0 + q * 3.8 + vec2(-t * 0.08, 8.1)),
191 fbm(p.yx * 3.2 - q * 3.4 + vec2(2.6, t * 0.09)));
192 vec2 flow = p + (r - 0.5) * (0.30 + audio.x * 0.12);
193
194 vec3 texAccum = vec3(0.0);
195 float weightSum = 0.0;
196 float filament = 0.0;
197 float caustic = 0.0;
198 float shell = 10.0;
199 vec2 z = flow;
200
201 for (int i = 0; i < 6; ++i) {
202 float fi = float(i);
203 float radial = length(z);
204 float localAngle = atan(z.y, z.x);
205 float wave = sin(radial * (15.0 + fi * 2.1) - localAngle * (3.0 + fi) - t * 0.9);
206 z += 0.045 * vec2(cos(localAngle + wave), sin(localAngle - wave));
207 z = abs(z * rot(0.47 + fi * 0.62 + t * 0.018)) - vec2(0.18, 0.135);
208 z *= 1.29 + 0.035 * fi;
209
210 float g = abs(gyroid(vec3(z * (4.0 + fi * 0.25), t * 0.42 + fi)));
211 filament += exp(-7.5 * g) / (1.0 + fi * 0.48);
212 caustic += pow(max(0.0, 1.0 - g), 6.0) / (1.0 + fi * 0.65);
213 shell = min(shell, abs(radial - 0.19 - fi * 0.065));
214
215 float weight = 1.0 / (1.0 + fi * 0.55);
216 vec2 texUV = z * (0.26 + fi * 0.018) + 0.5;
217 texUV += (q - 0.5) * 0.10;
218 texAccum += sampleMirror(texUV) * weight;
219 weightSum += weight;
220 }
221 texAccum /= weightSum;
222
223 float depthBands = 0.5 + 0.5 * sin(lens * 4.8 - t * 1.15 + q.x * 5.0);
224 float pearl = 0.5 + 0.5 * sin(filament * 2.8 + r.y * 8.0 - t * 0.25);
225 float portal = exp(-4.0 * originalRadius) *
226 (0.58 + 0.42 * cos(angle * (5.0 + floor(audio.y * 4.0)) + t));
227 float shellGlow = exp(-34.0 * shell);
228
229 vec3 opal = opalPalette(pearl * 0.46 + depthBands * 0.18 + t * 0.022);
230 vec3 abyss = vec3(0.015, 0.025, 0.07) +
231 opalPalette(q.x * 0.18 + 0.67) * 0.13;
232 vec3 col = mix(abyss, texAccum * (0.55 + opal * 0.55), 0.62 + 0.20 * r.x);
233 col = mix(col, opal, clamp(filament * 0.16, 0.0, 0.48));
234 col += opal * caustic * (0.12 + audio.z * 0.085);
235 col += angularOpal(angle, t * 0.045) * shellGlow * 0.32;
236 col += vec3(0.50, 0.72, 1.0) * portal * depthBands * 0.34;
237
238 // Fine diffraction strands shimmer on high frequencies without strobing.
239 float diffraction = pow(0.5 + 0.5 * cos(angle * 18.0 + lens * 2.0 - t), 12.0);
240 col += angularOpal(angle, pearl) * diffraction *
241 exp(-2.2 * originalRadius) * (0.04 + audio.z * 0.14);
242 return col;
243}
244
245/**
246 * @brief Executes the fragment shader entry point.
247 */
248void main() {
249 vec2 uv = tc;
250 vec2 center = vec2(0.5);
251 if (iMouse.z > 0.0) {
252 center = iMouse.xy / iResolution;
253 }
254
255 float bass = clamp(texture(spectrum, 0.025).r + amp_low * 0.65, 0.0, 2.0);
256 float mids = clamp(texture(spectrum, 0.24).r + amp_mid * 0.62, 0.0, 2.0);
257 float highs = clamp(texture(spectrum, 0.67).r + amp_high * 0.68, 0.0, 2.0);
258 float beat = max(amp_peak, bass);
259 float t = time_f * 0.18 * (1.0 + beat * 0.40);
260
261 vec3 col = abyssalOpal(uv, center, t, vec3(bass, mids, highs));
262
263 float luma = dot(col, vec3(0.299, 0.587, 0.114));
264 col = mix(vec3(luma), col, iSaturation);
265 col = (col - 0.5) * iContrast + 0.5;
266 col *= iBrightness * (1.0 + bass * 0.20 + amp_smooth * 0.14);
267 col = col / (0.88 + 0.30 * col); // filmic highlight rolloff
268
269 vec2 vignetteUV = uv * (1.0 - uv.yx);
270 float vignette = pow(max(vignetteUV.x * vignetteUV.y * 15.5, 0.0), 0.18);
271 color = vec4(max(col * vignette, 0.0), 1.0);
272}
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
const float iBrightness
vec2 wrapUV(vec2 tc)
Evaluates wrapUV for this shader effect.
const float iSaturation
const float iContrast
float fbm(vec2 point)
Evaluates fbm for this shader effect.
#define amp_smooth
#define amp_mid
#define amp_low
#define amp_high
#define amp_peak
vec3 wave(ivec2 p, ivec2 size)
Evaluates wave for this shader effect.
vec2 rot(vec2 v, float a)
Evaluates rot for this shader effect.
Definition air-bowl.frag:52
float noise(vec2 p)
Evaluates noise for this shader effect.
vec3 harmonic(float t)
Evaluates harmonic for this shader effect.
float luma(vec3 c)
Evaluates luma for this shader effect.
Definition auraXi1.frag:58
float hash21(vec2 p)
Evaluates hash21 for this shader effect.
vec2 lens(vec2 p, float z)
Evaluates lens for this shader effect.
#define TAU
float n2(vec2 p)
Evaluates n2 for this shader effect.
float beat(float t)
Evaluates beat for this shader effect.
vec3 spectrum(float t)
Evaluates spectrum for this shader effect.
float gyroid(vec3 p)
Evaluates gyroid for this shader effect.
vec2 curlField(vec2 p, float t)
Evaluates curlField for this shader effect.
vec3 sampleMirror(vec2 uv)
Evaluates sampleMirror for this shader effect.
vec3 opalPalette(float t)
Evaluates opalPalette for this shader effect.
vec3 angularOpal(float angle, float phase)
Evaluates angularOpal for this shader effect.
vec3 abyssalOpal(vec2 uv, vec2 center, float t, vec3 audio)
Evaluates abyssalOpal for this shader effect.
vec2 curl(vec2 p, float t)
Evaluates curl for this shader effect.
float opal(vec2 p)
Evaluates opal for this shader effect.
float pearl(vec2 p)
Evaluates pearl for this shader effect.
vec2 twist(vec2 coord, float twistAmount, float time, float direction)
Evaluates twist for this shader effect.
float caustic(vec2 p)
Evaluates caustic for this shader effect.