ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
halluc_ink_bloom.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file halluc_ink_bloom.frag
5 * @brief Vulkan fragment shader: halluc ink bloom.
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.50;
47const float iZoom = 1.0;
48const float iRotation = 0.0;
49const float iInkWeight = 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.5, 0.5, 0.5);
58 vec3 b = vec3(0.5, 0.5, 0.5);
59 vec3 c = vec3(1.0, 0.7, 1.3);
60 vec3 d = vec3(0.10, 0.30, 0.55);
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 * @brief Evaluates mxTexture for this shader effect.
72 * @param tex Input value for the calculation.
73 * @param uv Input value for the calculation.
74 * @return Computed vec4 value.
75 */
76vec4 mxTexture(sampler2D tex, vec2 uv) {
77 vec2 ts = vec2(textureSize(tex, 0));
78 vec2 eps = 0.5 / ts;
79 vec2 u = wrapUV(uv);
80 return textureLod(tex, clamp(u, eps, 1.0 - eps), 0.0);
81}
82/**
83 * @brief Evaluates rot for this shader effect.
84 * @param a Input value for the calculation.
85 * @return Computed mat2 value.
86 */
87mat2 rot(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }
88
89/**
90 * @brief Evaluates hash21 for this shader effect.
91 * @param p Input value for the calculation.
92 * @return Computed float value.
93 */
94float hash21(vec2 p) {
95 p = fract(p * vec2(43.13, 27.91));
96 p += dot(p, p + 22.7);
97 return fract(p.x * p.y);
98}
99/**
100 * @brief Evaluates vnoise for this shader effect.
101 * @param p Input value for the calculation.
102 * @return Computed float value.
103 */
104float vnoise(vec2 p) {
105 vec2 i = floor(p), f = fract(p);
106 float a = hash21(i);
107 float b = hash21(i + vec2(1.0, 0.0));
108 float c = hash21(i + vec2(0.0, 1.0));
109 float d = hash21(i + vec2(1.0, 1.0));
110 vec2 u = f * f * (3.0 - 2.0 * f);
111 return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
112}
113/**
114 * @brief Evaluates fbm for this shader effect.
115 * @param p Input value for the calculation.
116 * @return Computed float value.
117 */
118float fbm(vec2 p) {
119 float v = 0.0, a = 0.5;
120 for (int i = 0; i < 6; ++i) { v += a * vnoise(p); p *= 2.05; a *= 0.5; }
121 return v;
122}
123
124// 4-channel ink that diffuses through a fractal field
125/**
126 * @brief Evaluates inkBloom for this shader effect.
127 * @param uv Input value for the calculation.
128 * @param center Input value for the calculation.
129 * @param t Input value for the calculation.
130 * @return Computed vec3 value.
131 */
132vec3 inkBloom(vec2 uv, vec2 center, float t) {
133 vec2 p = uv - center;
134 p.x *= iResolution.x / iResolution.y;
135 p /= 0.5 + iZoom * 2.0;
136
137 // domain warp drives the ink-spread
138 vec2 q = vec2(fbm(p * 1.7 + t * 0.20), fbm(p * 1.7 + 3.5 - t * 0.18));
139 vec2 r = vec2(fbm(p * 1.7 + 4.0 * q + t * 0.12),
140 fbm(p * 1.7 + 4.0 * q + 9.1 - t * 0.10));
141 vec2 pp = p + (r - 0.5) * 0.55 * iAmplitude;
142
143 // fractal accumulation
144 vec3 accTex = vec3(0.0);
145 float ring = 100.0;
146 float scale = 1.55 + iAmplitude * 0.4;
147 for (float i = 0.0; i < 5.0; i++) {
148 pp = abs(pp) - 0.20;
149 pp *= rot(t * 0.18 + iRotation + i * 0.55);
150 pp *= scale;
151 ring = min(ring, abs(length(pp) - 0.55));
152 vec2 texUV = pp * 0.5 + 0.5;
153 accTex += mxTexture(samp, texUV).rgb * (0.55 / (i + 1.0));
154 }
155 accTex /= 1.6;
156
157 // four ink "drops" at offset positions, each its own hue
158 float d0 = fbm(p * 2.0 - t * 0.13);
159 float d1 = fbm(p * 2.0 + 7.0 + t * 0.11);
160 float d2 = fbm(p * 2.0 + 13.0 + t * 0.09);
161 float d3 = fbm(p * 2.0 + 19.0 - t * 0.10);
162 vec3 ink = vec3(0.0);
163 ink += palette(0.05) * d0;
164 ink += palette(0.30) * d1;
165 ink += palette(0.55) * d2;
166 ink += palette(0.80) * d3;
167 ink *= 0.5 * iInkWeight;
168
169 vec3 col = mix(accTex, ink, 0.55 * iSaturation);
170 col += palette(d0 * 0.5 + t * 0.07) * exp(-15.0 * ring) * 0.5 * iContrast;
171 return col;
172}
173
174/**
175 * @brief Executes the fragment shader entry point.
176 */
177void main() {
178 vec2 uv = tc;
179 vec2 center = vec2(0.5);
180 if (iMouse.z > 0.0) center = iMouse.xy / iResolution;
181 float bass = texture(spectrum, 0.03).r + amp_low * 0.5;
182 float midF = texture(spectrum, 0.22).r + amp_mid * 0.5;
183 float treble = texture(spectrum, 0.58).r + amp_high * 0.5;
184 float beat = max(amp_peak, bass);
185 float t = time_f * (0.07 + iFrequency * 0.20) * (1.0 + 0.6 * beat);
186
187 vec3 col = inkBloom(uv, center, t);
188
189 float gray = dot(col, vec3(0.299, 0.587, 0.114));
190 col = mix(vec3(gray), col, iSaturation);
191 col = (col - 0.5) * iContrast + 0.5;
192 col += vec3(0.6, 0.4, 1.0) * treble * 0.18;
193 col *= iBrightness * (1.0 + 0.5 * bass);
194
195 vec2 vUV = uv * (1.0 - uv.yx);
196 float vig = pow(vUV.x * vUV.y * 15.0, 0.18);
197 col *= vig;
198
199 color = vec4(col, 1.0);
200}
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.
float beat(float t)
Evaluates beat for this shader effect.
vec3 spectrum(float t)
Evaluates spectrum for this shader effect.
vec3 inkBloom(vec2 uv, vec2 center, float t)
Evaluates inkBloom for this shader effect.
const float iInkWeight
float pp(float x, float len)
Evaluates pp for this shader effect.
Definition inthesky.frag:36