ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
halluc_mercury_pop.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file halluc_mercury_pop.frag
5 * @brief Vulkan fragment shader: halluc mercury pop.
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.40;
46const float iHueShift = 0.0;
47const float iZoom = 1.0;
48const float iRotation = 0.0;
49const float iMercuryGloss = 1.0;
50
51/**
52 * @brief Evaluates palette for this shader effect.
53 * @param t Input value for the calculation.
54 * @return Computed vec3 value.
55 */
56vec3 palette(float t) {
57 vec3 a = vec3(0.5, 0.5, 0.5);
58 vec3 b = vec3(0.5, 0.5, 0.5);
59 vec3 c = vec3(1.0, 1.0, 1.0);
60 vec3 d = vec3(0.0, 0.33, 0.67);
61 return a + b * cos(6.28318 * (c * t + d + iHueShift));
62}
63
64/**
65 * @brief Evaluates wrapUV for this shader effect.
66 * @param v Input value for the calculation.
67 * @return Computed vec2 value.
68 */
69vec2 wrapUV(vec2 v) { return 1.0 - abs(1.0 - 2.0 * fract(v * 0.5)); }
70
71/**
72 * @brief Evaluates mxTexture for this shader effect.
73 * @param tex Input value for the calculation.
74 * @param uv Input value for the calculation.
75 * @return Computed vec4 value.
76 */
77vec4 mxTexture(sampler2D tex, vec2 uv) {
78 vec2 ts = vec2(textureSize(tex, 0));
79 vec2 eps = 0.5 / ts;
80 vec2 u = wrapUV(uv);
81 return textureLod(tex, clamp(u, eps, 1.0 - eps), 0.0);
82}
83
84/**
85 * @brief Evaluates rot for this shader effect.
86 * @param a Input value for the calculation.
87 * @return Computed mat2 value.
88 */
89mat2 rot(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }
90
91/**
92 * @brief Evaluates mercuryFractal for this shader effect.
93 * @param uv Input value for the calculation.
94 * @param center Input value for the calculation.
95 * @param t Input value for the calculation.
96 * @return Computed vec3 value.
97 */
98vec3 mercuryFractal(vec2 uv, vec2 center, float t) {
99 vec2 p = uv - center;
100 p.x *= iResolution.x / iResolution.y;
101 p /= 0.5 + iZoom * 2.0;
102
103 vec3 accTex = vec3(0.0);
104 float accGlare = 0.0;
105 float ringD = 100.0;
106
107 float iter = 5.0;
108 float scale = 1.55 + iAmplitude * 0.45;
109
110 for (float i = 0.0; i < iter; i++) {
111 // sphere inversion: makes everything bulge / blob
112 float r2 = dot(p, p);
113 if (r2 > 0.0001) p /= max(r2, 0.35);
114
115 // box fold
116 p = clamp(p, -1.0, 1.0) * 2.0 - p;
117
118 p *= rot(t * 0.15 + iRotation + i * 0.6);
119 p *= scale;
120 p -= vec2(sin(t * 0.5 + i), cos(t * 0.4 + i)) * 0.08;
121
122 vec2 texUV = p * 0.5 + 0.5;
123 accTex += mxTexture(samp, texUV).rgb / (i + 1.0);
124
125 float dist = length(p);
126 ringD = min(ringD, abs(dist - 0.6));
127 accGlare += exp(-12.0 * abs(dist - 0.4));
128 }
129 accTex /= 1.6;
130
131 // chrome-like reflective tint based on direction
132 vec2 dir = normalize(p + 1e-6);
133 float fres = pow(1.0 - abs(dir.y), 2.0);
134 vec3 chrome = mix(vec3(0.3, 0.4, 0.55), vec3(1.0, 0.95, 0.9), fres);
135 chrome *= 0.7 + 0.6 * iMercuryGloss;
136
137 vec3 pal = palette(ringD * 1.2 + t * 0.15);
138 vec3 col = mix(accTex, chrome, 0.55);
139 col = mix(col, pal, 0.30 * iSaturation);
140 col += pal * accGlare * 0.5 * iContrast;
141 // hard specular glints on tight ring
142 col += vec3(1.0, 0.95, 0.85) * exp(-50.0 * ringD) * 0.6;
143 return col;
144}
145
146/**
147 * @brief Executes the fragment shader entry point.
148 */
149void main() {
150 vec2 uv = tc;
151 vec2 center = vec2(0.5);
152 if (iMouse.z > 0.0) center = iMouse.xy / iResolution;
153 float bass = texture(spectrum, 0.03).r + amp_low * 0.5;
154 float midF = texture(spectrum, 0.22).r + amp_mid * 0.5;
155 float treble = texture(spectrum, 0.58).r + amp_high * 0.5;
156 float beat = max(amp_peak, bass);
157 float t = time_f * (0.08 + iFrequency * 0.20) * (1.0 + 0.6 * beat);
158
159 vec3 col = mercuryFractal(uv, center, t);
160
161 float gray = dot(col, vec3(0.299, 0.587, 0.114));
162 col = mix(vec3(gray), col, iSaturation);
163 col = (col - 0.5) * iContrast + 0.5;
164 col += vec3(0.6, 0.4, 1.0) * treble * 0.18;
165 col *= iBrightness * (1.0 + 0.5 * bass);
166
167 vec2 vUV = uv * (1.0 - uv.yx);
168 float vig = pow(vUV.x * vUV.y * 15.0, 0.18);
169 col *= vig;
170
171 color = vec4(col, 1.0);
172}
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
vec3 palette(float phase)
Evaluates palette for this shader effect.
#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 chrome(float t)
Evaluates chrome for this shader effect.
vec3 pal(float t)
Evaluates pal for this shader effect.
float beat(float t)
Evaluates beat for this shader effect.
vec3 spectrum(float t)
Evaluates spectrum for this shader effect.
vec3 mercuryFractal(vec2 uv, vec2 center, float t)
Evaluates mercuryFractal for this shader effect.
const float iMercuryGloss