ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
halluc_plasma_flame.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file halluc_plasma_flame.frag
5 * @brief Vulkan fragment shader: halluc plasma flame.
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.15;
45const float iSaturation = 1.30;
46const float iHueShift = 0.10;
47const float iZoom = 1.0;
48const float iRotation = 0.0;
49
50// "Plasma flame" — looks like fire but in shifting acid hues
51/**
52 * @brief Evaluates acidFlamePalette for this shader effect.
53 * @param t Input value for the calculation.
54 * @return Computed vec3 value.
55 */
56vec3 acidFlamePalette(float t) {
57 t = clamp(t, 0.0, 1.0);
58 vec3 c1 = vec3(0.05, 0.0, 0.20);
59 vec3 c2 = vec3(0.85, 0.10, 0.55);
60 vec3 c3 = vec3(1.00, 0.55, 0.05);
61 vec3 c4 = vec3(0.40, 1.10, 0.30);
62 vec3 c5 = vec3(0.85, 1.20, 1.00);
63 if (t < 0.30) return mix(c1, c2, t / 0.30);
64 if (t < 0.60) return mix(c2, c3, (t - 0.30) / 0.30);
65 if (t < 0.85) return mix(c3, c4, (t - 0.60) / 0.25);
66 return mix(c4, c5, (t - 0.85) / 0.15);
67}
68
69/**
70 * @brief Evaluates wrapUV for this shader effect.
71 * @param v Input value for the calculation.
72 * @return Computed vec2 value.
73 */
74vec2 wrapUV(vec2 v) { return 1.0 - abs(1.0 - 2.0 * fract(v * 0.5)); }
75/**
76 * @brief Evaluates mxTexture for this shader effect.
77 * @param tex Input value for the calculation.
78 * @param uv Input value for the calculation.
79 * @return Computed vec4 value.
80 */
81vec4 mxTexture(sampler2D tex, vec2 uv) {
82 vec2 ts = vec2(textureSize(tex, 0));
83 vec2 eps = 0.5 / ts;
84 vec2 u = wrapUV(uv);
85 return textureLod(tex, clamp(u, eps, 1.0 - eps), 0.0);
86}
87/**
88 * @brief Evaluates rot for this shader effect.
89 * @param a Input value for the calculation.
90 * @return Computed mat2 value.
91 */
92mat2 rot(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }
93
94/**
95 * @brief Evaluates hash21 for this shader effect.
96 * @param p Input value for the calculation.
97 * @return Computed float value.
98 */
99float hash21(vec2 p) {
100 p = fract(p * vec2(83.41, 27.93));
101 p += dot(p, p + 21.7);
102 return fract(p.x * p.y);
103}
104/**
105 * @brief Evaluates vnoise for this shader effect.
106 * @param p Input value for the calculation.
107 * @return Computed float value.
108 */
109float vnoise(vec2 p) {
110 vec2 i = floor(p), f = fract(p);
111 float a = hash21(i);
112 float b = hash21(i + vec2(1.0, 0.0));
113 float c = hash21(i + vec2(0.0, 1.0));
114 float d = hash21(i + vec2(1.0, 1.0));
115 vec2 u = f * f * (3.0 - 2.0 * f);
116 return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
117}
118/**
119 * @brief Evaluates fbm for this shader effect.
120 * @param p Input value for the calculation.
121 * @return Computed float value.
122 */
123float fbm(vec2 p) {
124 float v = 0.0, a = 0.5;
125 for (int i = 0; i < 6; ++i) { v += a * vnoise(p); p *= 2.05; a *= 0.5; }
126 return v;
127}
128
129/**
130 * @brief Evaluates plasmaFlame for this shader effect.
131 * @param uv Input value for the calculation.
132 * @param center Input value for the calculation.
133 * @param t Input value for the calculation.
134 * @return Computed vec3 value.
135 */
136vec3 plasmaFlame(vec2 uv, vec2 center, float t) {
137 vec2 p = uv - center;
138 p.x *= iResolution.x / iResolution.y;
139 p /= 0.5 + iZoom * 2.0;
140
141 // domain warp
142 vec2 q = vec2(fbm(p + t * 0.2), fbm(p + 5.2 - t * 0.17));
143 vec2 r = vec2(fbm(p + 4.0 * q + 1.7 + t * 0.15),
144 fbm(p + 4.0 * q + 9.2 - t * 0.13));
145 float h = fbm(p + 4.0 * r);
146
147 // fractal accumulation drives the structure
148 float ring = 100.0;
149 vec3 accTex = vec3(0.0);
150 vec2 pf = p;
151 float scale = 1.55 + iAmplitude * 0.4;
152 for (float i = 0.0; i < 4.0; i++) {
153 pf = abs(pf) - 0.22;
154 pf *= rot(t * 0.18 + iRotation + i);
155 pf *= scale;
156 ring = min(ring, abs(length(pf) - 0.55));
157 vec2 texUV = pf * 0.5 + 0.5 + (r - 0.5) * 0.08;
158 accTex += mxTexture(samp, texUV).rgb / (i + 1.0);
159 }
160
161 float heat = clamp(h * 1.4 + 0.25 * iAmplitude, 0.0, 1.5);
162 vec3 flame = acidFlamePalette(heat / 1.5);
163 vec3 col = mix(accTex * 0.7, flame, smoothstep(0.10, 0.95, heat));
164 col += flame * exp(-25.0 * ring) * iContrast;
165 return col;
166}
167
168/**
169 * @brief Executes the fragment shader entry point.
170 */
171void main() {
172 vec2 uv = tc;
173 vec2 center = vec2(0.5);
174 if (iMouse.z > 0.0) center = iMouse.xy / iResolution;
175 float bass = texture(spectrum, 0.03).r + amp_low * 0.5;
176 float midF = texture(spectrum, 0.22).r + amp_mid * 0.5;
177 float treble = texture(spectrum, 0.58).r + amp_high * 0.5;
178 float beat = max(amp_peak, bass);
179 float t = time_f * (0.08 + iFrequency * 0.22) * (1.0 + 0.6 * beat);
180
181 vec3 col = plasmaFlame(uv, center, t);
182
183 float gray = dot(col, vec3(0.299, 0.587, 0.114));
184 col = mix(vec3(gray), col, iSaturation);
185 col = (col - 0.5) * iContrast + 0.5;
186 col += vec3(0.6, 0.4, 1.0) * treble * 0.18;
187 col *= iBrightness * (1.0 + 0.5 * bass);
188
189 vec2 vUV = uv * (1.0 - uv.yx);
190 float vig = pow(vUV.x * vUV.y * 15.0, 0.20);
191 col *= vig;
192
193 color = vec4(col, 1.0);
194}
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
float fbm(vec2 point)
Evaluates fbm for this shader effect.
#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
float vnoise(vec2 p)
Evaluates vnoise for this shader effect.
float hash21(vec2 p)
Evaluates hash21 for this shader effect.
float h(vec2 p)
Evaluates h 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 plasmaFlame(vec2 uv, vec2 center, float t)
Evaluates plasmaFlame for this shader effect.
vec3 acidFlamePalette(float t)
Evaluates acidFlamePalette for this shader effect.