ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
halluc_smoke_curl.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file halluc_smoke_curl.frag
5 * @brief Vulkan fragment shader: halluc smoke curl.
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 = 0.7;
43const float iBrightness = 0.95;
44const float iContrast = 1.10;
45const float iSaturation = 0.85;
46const float iHueShift = 0.30;
47const float iZoom = 1.0;
48const float iRotation = 0.0;
49const float iSmokeDensity = 1.10;
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.45, 0.45, 0.50);
58 vec3 b = vec3(0.30, 0.30, 0.35);
59 vec3 c = vec3(1.0, 1.0, 1.0);
60 vec3 d = vec3(0.55, 0.60, 0.70);
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 hash21 for this shader effect.
93 * @param p Input value for the calculation.
94 * @return Computed float value.
95 */
96float hash21(vec2 p) {
97 p = fract(p * vec2(73.71, 19.13));
98 p += dot(p, p + 51.7);
99 return fract(p.x * p.y);
100}
101/**
102 * @brief Evaluates vnoise for this shader effect.
103 * @param p Input value for the calculation.
104 * @return Computed float value.
105 */
106float vnoise(vec2 p) {
107 vec2 i = floor(p), f = fract(p);
108 float a = hash21(i);
109 float b = hash21(i + vec2(1.0, 0.0));
110 float c = hash21(i + vec2(0.0, 1.0));
111 float d = hash21(i + vec2(1.0, 1.0));
112 vec2 u = f * f * (3.0 - 2.0 * f);
113 return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
114}
115/**
116 * @brief Evaluates fbm for this shader effect.
117 * @param p Input value for the calculation.
118 * @return Computed float value.
119 */
120float fbm(vec2 p) {
121 float v = 0.0, a = 0.5;
122 for (int i = 0; i < 6; ++i) { v += a * vnoise(p); p = rot(0.5) * p * 2.07; a *= 0.5; }
123 return v;
124}
125
126// curl-like 2D field via finite differences of fbm
127/**
128 * @brief Evaluates curl for this shader effect.
129 * @param p Input value for the calculation.
130 * @param t Input value for the calculation.
131 * @return Computed vec2 value.
132 */
133vec2 curl(vec2 p, float t) {
134 float e = 0.05;
135 float a = fbm(p + vec2(0.0, e) + t);
136 float b = fbm(p - vec2(0.0, e) + t);
137 float c = fbm(p + vec2(e, 0.0) - t);
138 float d = fbm(p - vec2(e, 0.0) - t);
139 return vec2(a - b, d - c) / (2.0 * e);
140}
141
142/**
143 * @brief Evaluates smokeStack for this shader effect.
144 * @param uv Input value for the calculation.
145 * @param center Input value for the calculation.
146 * @param t Input value for the calculation.
147 * @return Computed vec3 value.
148 */
149vec3 smokeStack(vec2 uv, vec2 center, float t) {
150 vec2 p = uv - center;
151 p.x *= iResolution.x / iResolution.y;
152 p /= 0.5 + iZoom * 2.0;
153
154 // advect: smoke rises and curls
155 vec2 c = curl(p * 1.2, t * 0.4);
156 p += c * 0.25 * iAmplitude;
157 p.y -= t * 0.20;
158
159 float density = 0.0;
160 vec3 accTex = vec3(0.0);
161 float iter = 4.0;
162 float scale = 1.40 + iAmplitude * 0.3;
163
164 for (float i = 0.0; i < iter; i++) {
165 p = abs(p);
166 p -= 0.18;
167 p *= rot(t * 0.10 + iRotation + i * 0.7);
168 p *= scale;
169
170 float n = fbm(p * 1.3 + vec2(0.0, -t * 0.5) + i);
171 density += n / (i + 1.0);
172
173 vec2 texUV = p * 0.5 + 0.5;
174 texUV += c * 0.04;
175 accTex += mxTexture(samp, texUV).rgb * (0.55 / (i + 1.0));
176 }
177 density = clamp(density * iSmokeDensity, 0.0, 1.5);
178
179 vec3 pal = palette(density * 0.5 + t * 0.07);
180 // smoke is mostly desaturated
181 vec3 smoke = mix(vec3(dot(pal, vec3(0.33))), pal, 0.35);
182
183 // rising soot mask
184 float mask = smoothstep(0.10, 0.95, density);
185 vec3 col = mix(accTex, smoke * (0.4 + 0.6 * density), mask);
186 col += vec3(0.04, 0.05, 0.08) * pow(density, 3.0); // dark soot
187 return col;
188}
189
190/**
191 * @brief Executes the fragment shader entry point.
192 */
193void main() {
194 vec2 uv = tc;
195 vec2 center = vec2(0.5);
196 if (iMouse.z > 0.0) center = iMouse.xy / iResolution;
197 float bass = texture(spectrum, 0.03).r + amp_low * 0.5;
198 float midF = texture(spectrum, 0.22).r + amp_mid * 0.5;
199 float treble = texture(spectrum, 0.58).r + amp_high * 0.5;
200 float beat = max(amp_peak, bass);
201 float t = time_f * (0.08 + iFrequency * 0.18) * (1.0 + 0.6 * beat);
202
203 vec3 col = smokeStack(uv, center, t);
204
205 float gray = dot(col, vec3(0.299, 0.587, 0.114));
206 col = mix(vec3(gray), col, iSaturation);
207 col = (col - 0.5) * iContrast + 0.5;
208 col += vec3(0.6, 0.4, 1.0) * treble * 0.18;
209 col *= iBrightness * (1.0 + 0.5 * bass);
210
211 vec2 vUV = uv * (1.0 - uv.yx);
212 float vig = pow(vUV.x * vUV.y * 15.0, 0.22);
213 col *= vig;
214
215 color = vec4(col, 1.0);
216}
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
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
float vnoise(vec2 p)
Evaluates vnoise for this shader effect.
float hash21(vec2 p)
Evaluates hash21 for this shader effect.
vec3 pal(float t)
Evaluates pal for this shader effect.
float n(vec2 p)
Evaluates n for this shader effect.
float beat(float t)
Evaluates beat for this shader effect.
vec3 spectrum(float t)
Evaluates spectrum for this shader effect.
vec2 curl(vec2 p, float t)
Evaluates curl for this shader effect.
vec3 smokeStack(vec2 uv, vec2 center, float t)
Evaluates smokeStack for this shader effect.
const float iSmokeDensity