ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
Light_Rainbow_Swirl.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file Light_Rainbow_Swirl.frag
5 * @brief Vulkan fragment shader: Light Rainbow Swirl.
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 iMouse ext.mouse
18#define iResolution ext.u0.zw
19#define time_f ext.u2.y
20
21layout(location = 0) out vec4 color;
22layout(location = 0) in vec2 tc;
23layout(set = 0, binding = 0) uniform sampler2D samp;
24
25
26
27
28// --- CONTROLS ---
29const float iAmplitude = 1.0;
30const float iFrequency = 1.0;
31const float iBrightness = 1.0;
32const float iContrast = 1.1;
33const float iSaturation = 1.3;
34const float iZoom = 1.0;
35const float iRotation = 0.0;
36const float PI = 3.14159;
37
38// --- SHADER 1: RAINBOW FUNCTION ---
39/**
40 * @brief Evaluates rainbow for this shader effect.
41 * @param t Input value for the calculation.
42 * @return Computed vec3 value.
43 */
44vec3 rainbow(float t) {
45 t = fract(t);
46 float r = abs(t * 6.0 - 3.0) - 1.0;
47 float g = 2.0 - abs(t * 6.0 - 2.0);
48 float b = 2.0 - abs(t * 6.0 - 4.0);
49 return clamp(vec3(r, g, b), 0.0, 1.0);
50}
51
52// --- SHADER 2: HELPER FUNCTIONS ---
53
54/**
55 * @brief Evaluates adjustBrightness for this shader effect.
56 * @param col Input value for the calculation.
57 * @param b Input value for the calculation.
58 * @return Computed vec3 value.
59 */
60vec3 adjustBrightness(vec3 col, float b) { return col * b; }
61/**
62 * @brief Evaluates adjustContrast for this shader effect.
63 * @param col Input value for the calculation.
64 * @param c Input value for the calculation.
65 * @return Computed vec3 value.
66 */
67vec3 adjustContrast(vec3 col, float c) { return (col - 0.5) * c + 0.5; }
68/**
69 * @brief Evaluates adjustSaturation for this shader effect.
70 * @param col Input value for the calculation.
71 * @param s Input value for the calculation.
72 * @return Computed vec3 value.
73 */
74vec3 adjustSaturation(vec3 col, float s) {
75 float gray = dot(col, vec3(0.299, 0.587, 0.114));
76 return mix(vec3(gray), col, s);
77}
78
79/**
80 * @brief Evaluates wrapUV for this shader effect.
81 * @param tc Input value for the calculation.
82 * @return Computed vec2 value.
83 */
84vec2 wrapUV(vec2 tc) {
85 return 1.0 - abs(1.0 - 2.0 * fract(tc * 0.5));
86}
87
88/**
89 * @brief Evaluates mxTexture for this shader effect.
90 * @param tex Input value for the calculation.
91 * @param tc Input value for the calculation.
92 * @return Computed vec4 value.
93 */
94vec4 mxTexture(sampler2D tex, vec2 tc) {
95 vec2 ts = vec2(textureSize(tex, 0));
96 vec2 eps = 0.5 / ts;
97 vec2 uv = wrapUV(tc);
98 vec2 sampleUV = clamp(uv, eps, 1.0 - eps);
99 return texture(tex, sampleUV);
100}
101
102/**
103 * @brief Evaluates rotate2D for this shader effect.
104 * @param p Input value for the calculation.
105 * @param a Input value for the calculation.
106 * @return Computed vec2 value.
107 */
108vec2 rotate2D(vec2 p, float a) {
109 float c = cos(a); float s = sin(a);
110 return mat2(c, -s, s, c) * p;
111}
112
113// --- FLUID NOISE GENERATORS ---
114/**
115 * @brief Evaluates hash for this shader effect.
116 * @param p Input value for the calculation.
117 * @return Computed float value.
118 */
119float hash(vec2 p) {
120 return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);
121}
122
123/**
124 * @brief Evaluates noise for this shader effect.
125 * @param p Input value for the calculation.
126 * @return Computed float value.
127 */
128float noise(vec2 p) {
129 vec2 i = floor(p);
130 vec2 f = fract(p);
131 vec2 u = f * f * (3.0 - 2.0 * f);
132 return mix(mix(hash(i), hash(i + vec2(1.0, 0.0)), u.x),
133 mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x), u.y);
134}
135
136/**
137 * @brief Evaluates fbm for this shader effect.
138 * @param p Input value for the calculation.
139 * @return Computed float value.
140 */
141float fbm(vec2 p) {
142 float v = 0.0;
143 float a = 0.5;
144 mat2 rot = mat2(cos(0.5), sin(0.5), -sin(0.5), cos(0.50));
145 for (int i = 0; i < 5; i++) {
146 v += a * noise(p);
147 p = rot * p * 2.0 + vec2(2.0);
148 a *= 0.5;
149 }
150 return v;
151}
152
153// --- THE COMBINED LOGIC ---
154
155/**
156 * @brief Evaluates sampleMergedLiquid for this shader effect.
157 * @param uv Input value for the calculation.
158 * @param t Input value for the calculation.
159 * @param strength Input value for the calculation.
160 * @param center Input value for the calculation.
161 * @param res Input value for the calculation.
162 * @return Computed vec3 value.
163 */
164vec3 sampleMergedLiquid(vec2 uv, float t, float strength, vec2 center, vec2 res) {
165 float aspect = res.x / res.y;
166
167 // Center the coordinate system for the Spiral calculation
168 vec2 p = (uv - center) * vec2(aspect, 1.0);
169 p = rotate2D(p, iRotation);
170 float zoom = max(iZoom, 0.1);
171 p /= zoom;
172
173 // --- FLUID SIMULATION (Domain Warping) ---
174 vec2 q = vec2(0.0);
175 q.x = fbm(p + vec2(0.0, 0.0) + 0.05*t);
176 q.y = fbm(p + vec2(5.2, 1.3) + 0.05*t);
177
178 vec2 r = vec2(0.0);
179 r.x = fbm(p + 4.0*q + vec2(t * 0.2));
180 r.y = fbm(p + 4.0*q + vec2(t * 0.1, 2.8));
181
182 // 'r' is the fluid vector field. We use it to distort everything.
183 vec2 distortion = r * 0.3 * strength * iAmplitude;
184
185 // --- INTEGRATING SHADER 1 (The Spiral) ---
186
187 // We apply the fluid distortion to the coordinates used for the spiral angle.
188 // This makes the spiral look like it is made of liquid.
189 vec2 spiralCoords = p + distortion;
190
191 // Calculate the polar angle (atan) like in Shader 1
192 // We add 't' to rotate it, and 'length' to twist it (spiral shape)
193 float angle = atan(spiralCoords.y, spiralCoords.x);
194 float spiralTwist = angle + length(spiralCoords) * 3.0 - t * 0.5;
195
196 // Generate the Rainbow Gradient from Shader 1
197 vec3 spiralColor = rainbow(spiralTwist / (2.0 * PI));
198
199 // --- TEXTURE MAPPING ---
200
201 // Warp the UVs for the texture lookup
202 vec2 fluidUV = uv + distortion;
203 vec3 texCol = mxTexture(samp, fluidUV).rgb;
204
205 // --- BLENDING ---
206
207 // Blend the texture with the rainbow spiral
208 // We use the fluid density (length(r)) to make the blend look organic
209 float blendFactor = 0.6 + 0.2 * sin(length(r) * 5.0 + t);
210
211 // Hard Light blending approximation for vibrant colors
212 vec3 finalCol = mix(texCol, spiralColor, 0.5); // Base mix
213
214 // Add a glow overlay based on the spiral color
215 finalCol += spiralColor * 0.2 * strength;
216
217 return finalCol;
218}
219
220/**
221 * @brief Executes the fragment shader entry point.
222 */
223void main() {
224 vec2 uv = tc;
225 uv = wrapUV(uv); // Safety wrap
226
227 float t = time_f * (0.2 + iFrequency * 0.1);
228 float ampControl = clamp(iAmplitude, 0.0, 2.0);
229 float strength = 1.0 + (ampControl * 0.5);
230
231 vec2 center = vec2(0.5);
232 if (iMouse.z > 0.0) {
233 center = iMouse.xy / iResolution;
234 }
235
236 // --- CHROMATIC ABERRATION (From Shader 2) ---
237 // We split the RGB channels and offset them based on fluid intensity
238 vec2 offset = vec2(0.005 * strength, 0.0);
239
240 vec3 col;
241 col.r = sampleMergedLiquid(uv + offset, t, strength, center, iResolution).r;
242 col.g = sampleMergedLiquid(uv, t, strength, center, iResolution).g;
243 col.b = sampleMergedLiquid(uv - offset, t, strength, center, iResolution).b;
244
245 // --- POST PROCESSING ---
246 col = adjustBrightness(col, iBrightness);
247 col = adjustContrast(col, iContrast);
248 col = adjustSaturation(col, iSaturation);
249
250 // Vignette
251 vec2 vUV = uv * (1.0 - uv.yx);
252 float vig = vUV.x * vUV.y * 15.0;
253 vig = pow(vig, 0.2);
254 col *= vig;
255
256 color.rgb = sin(col * time_f);
257 color.a = 1.0;
258}
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
vec3 adjustBrightness(vec3 col, float b)
Evaluates adjustBrightness for this shader effect.
const float iBrightness
vec2 wrapUV(vec2 tc)
Evaluates wrapUV for this shader effect.
vec3 adjustSaturation(vec3 col, float s)
Evaluates adjustSaturation for this shader effect.
vec3 adjustContrast(vec3 col, float c)
Evaluates adjustContrast for this shader effect.
const float iAmplitude
const float iSaturation
const float iContrast
const float iZoom
vec3 sampleMergedLiquid(vec2 uv, float t, float strength, vec2 center, vec2 res)
Evaluates sampleMergedLiquid for this shader effect.
float fbm(vec2 point)
Evaluates fbm for this shader effect.
vec2 rot(vec2 v, float a)
Evaluates rot for this shader effect.
Definition air-bowl.frag:52
float hash(vec2 p)
Evaluates hash for this shader effect.
float noise(vec2 p)
Evaluates noise for this shader effect.
vec3 rainbow(float t)
Evaluates rainbow for this shader effect.
vec2 spiralTwist(vec2 uv, vec2 center, float aspect, float t, float drive)
Evaluates spiralTwist for this shader effect.
Definition auraXi1.frag:119
mat2 rotate2D(float a)
Evaluates rotate2D for this shader effect.
#define PI
#define strength
Definition ol.frag:16