ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
halluc_ember_storm.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file halluc_ember_storm.frag
5 * @brief Vulkan fragment shader: halluc ember storm.
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.05;
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 iEmberDensity = 1.10;
50
51/**
52 * @brief Evaluates firePalette for this shader effect.
53 * @param t Input value for the calculation.
54 * @return Computed vec3 value.
55 */
56vec3 firePalette(float t) {
57 t = clamp(t, 0.0, 1.0);
58 vec3 c1 = vec3(0.10, 0.0, 0.0);
59 vec3 c2 = vec3(0.70, 0.10, 0.05);
60 vec3 c3 = vec3(1.20, 0.50, 0.10);
61 vec3 c4 = vec3(1.30, 1.00, 0.40);
62 if (t < 0.40) return mix(c1, c2, t / 0.40);
63 if (t < 0.75) return mix(c2, c3, (t - 0.40) / 0.35);
64 return mix(c3, c4, (t - 0.75) / 0.25);
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(127.1, 311.7));
99 p += dot(p, p + 19.31);
100 return fract(p.x * p.y);
101}
102
103/**
104 * @brief Evaluates emberStorm for this shader effect.
105 * @param uv Input value for the calculation.
106 * @param center Input value for the calculation.
107 * @param t Input value for the calculation.
108 * @return Computed vec3 value.
109 */
110vec3 emberStorm(vec2 uv, vec2 center, float t) {
111 vec2 p = uv - center;
112 p.x *= iResolution.x / iResolution.y;
113 p /= 0.5 + iZoom * 2.0;
114
115 // Fractal background flicker
116 vec3 bg = vec3(0.0);
117 vec2 pf = p;
118 for (float i = 0.0; i < 4.0; i++) {
119 pf = abs(pf) - 0.20;
120 pf *= rot(t * 0.10 + iRotation + i * 0.5);
121 pf *= 1.5 + iAmplitude * 0.3;
122 vec2 texUV = pf * 0.5 + 0.5;
123 bg += mxTexture(samp, texUV).rgb * (0.5 / (i + 1.0));
124 }
125 bg *= 0.55;
126
127 // Particle field of embers (cellular)
128 float emberLight = 0.0;
129 vec3 emberCol = vec3(0.0);
130 vec2 grid = p * (4.0 + iAmplitude * 2.0);
131 vec2 gi = floor(grid);
132 vec2 gf = fract(grid) - 0.5;
133 for (int dy = -1; dy <= 1; ++dy) {
134 for (int dx = -1; dx <= 1; ++dx) {
135 vec2 nb = vec2(float(dx), float(dy));
136 vec2 cell = gi + nb;
137 float h = hash21(cell);
138 float life = fract(h * 13.7 + t * (0.30 + 0.40 * h));
139 // ember position drifts upward and jitters
140 vec2 jitter = vec2(
141 hash21(cell + 1.7) - 0.5,
142 hash21(cell + 5.3) - 0.5
143 );
144 vec2 pos = nb + jitter * 0.6 + vec2(0.0, -life * 1.0);
145 float d = length(gf - pos);
146 float spark = exp(-22.0 * d) * (1.0 - life) * iEmberDensity;
147 emberLight += spark;
148 float heat = mix(0.4, 1.0, h) * (1.0 - life * 0.7);
149 emberCol += firePalette(heat) * spark;
150 }
151 }
152
153 // Heat shimmer warp on bg
154 bg = mxTexture(samp, p * 0.4 + 0.5 + vec2(0.0, sin(p.x * 8.0 + t * 2.0) * 0.01)).rgb * 0.3 + bg;
155
156 vec3 col = bg * 0.5 + emberCol * iContrast;
157 col += firePalette(emberLight * 0.6) * 0.25;
158 return col;
159}
160
161/**
162 * @brief Executes the fragment shader entry point.
163 */
164void main() {
165 vec2 uv = tc;
166 vec2 center = vec2(0.5);
167 if (iMouse.z > 0.0) center = iMouse.xy / iResolution;
168 float bass = texture(spectrum, 0.03).r + amp_low * 0.5;
169 float midF = texture(spectrum, 0.22).r + amp_mid * 0.5;
170 float treble = texture(spectrum, 0.58).r + amp_high * 0.5;
171 float beat = max(amp_peak, bass);
172 float t = time_f * (0.10 + iFrequency * 0.25) * (1.0 + 0.6 * beat);
173
174 vec3 col = emberStorm(uv, center, t);
175
176 float gray = dot(col, vec3(0.299, 0.587, 0.114));
177 col = mix(vec3(gray), col, iSaturation);
178 col = (col - 0.5) * iContrast + 0.5;
179 col += vec3(0.6, 0.4, 1.0) * treble * 0.18;
180 col *= iBrightness * (1.0 + 0.5 * bass);
181
182 vec2 vUV = uv * (1.0 - uv.yx);
183 float vig = pow(vUV.x * vUV.y * 15.0, 0.20);
184 col *= vig;
185
186 color = vec4(col, 1.0);
187}
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
float hash21(vec2 p)
Evaluates hash21 for this shader effect.
float h(vec2 p)
Evaluates h for this shader effect.
vec2 cell(vec2 p)
Evaluates cell 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 firePalette(float t)
Evaluates firePalette for this shader effect.
const float iEmberDensity
vec3 emberStorm(vec2 uv, vec2 center, float t)
Evaluates emberStorm for this shader effect.