ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
rainbow-code-prismatic-caustics.frag
Go to the documentation of this file.
1#version 450
2
3layout(set = 0, binding = 1, std140) uniform SpriteExtended {
4 vec4 mouse;
5 vec4 u0;
6 vec4 u1;
7 vec4 u2;
8 vec4 u3;
9 vec4 custom_uniforms[16];
10 vec4 audio_bands;
11 vec4 audio_history;
13#define amp_high ext.audio_bands.z
14#define amp_low ext.audio_bands.x
15#define amp_mid ext.audio_bands.y
16#define amp_peak ext.u2.w
17#define amp_rms ext.u3.z
18#define amp_smooth ext.u3.w
19#define iResolution ext.u0.zw
20#define iamp ext.u1.z
21#define time_f ext.u2.y
22
23/**
24 * @file rainbow-code-prismatic-caustics.frag
25 * @brief Vulkan fragment shader: rainbow-code-prismatic-caustics.
26 */
27// rainbow-code-prismatic-caustics
28// Clean refractive caustics with spectral focusing and sub-pixel texture dispersion.
29layout(location = 0) in vec2 tc;
30layout(location = 0) out vec4 color;
31layout(set = 0, binding = 0) uniform sampler2D samp;
32
33
34
35
36
37
38
39
40
41
42const float TAU = 6.28318530718;
43/**
44 * @brief Evaluates mirrorUV for this shader effect.
45 * @param p Input value for the calculation.
46 * @return Computed vec2 value.
47 */
48vec2 mirrorUV(vec2 p) {
49 return 1.0 - abs(mod(p, 2.0) - 1.0);
50}
51/**
52 * @brief Evaluates spectrum for this shader effect.
53 * @param x Input value for the calculation.
54 * @return Computed vec3 value.
55 */
56vec3 spectrum(float x) {
57 return .5 + .5 * cos(TAU * (x + vec3(0.02, .35, .68)));
58}
59/**
60 * @brief Evaluates aces for this shader effect.
61 * @param x Input value for the calculation.
62 * @return Computed vec3 value.
63 */
64vec3 aces(vec3 x) {
65 x = max(x, 0.0);
66 return clamp((x * (2.51 * x + .03)) / (x * (2.43 * x + .59) + .14), 0.0, 1.0);
67}
68/**
69 * @brief Evaluates waves for this shader effect.
70 * @param p Input value for the calculation.
71 * @return Computed float value.
72 */
73float waves(vec2 p) {
74 float t = time_f * (.65 + amp_smooth * .18);
75 float a = sin(dot(p, vec2(18.0, 11.0)) + t * 2.1);
76 float b = sin(dot(p, vec2(-13.0, 24.0)) - t * 1.7);
77 float c = sin(length(p - vec2(sin(t * .23), cos(t * .19)) * .25) * 31.0 - t * 3.4);
78 float d = sin(p.x * 47.0 + sin(p.y * 9.0 - t) * 2.0 + t);
79 return a * .38 + b * .29 + c * .22 + d * .11;
80}
81/**
82 * @brief Executes the fragment shader entry point.
83 */
84void main() {
85 float aspect = max(iResolution.x, 1.0) / max(iResolution.y, 1.0);
86 vec2 p = (tc - .5) * vec2(aspect, 1.0);
87 float e = 1.5 / max(iResolution.y, 360.0);
88 float h = waves(p), hx = waves(p + vec2(e, 0)), hy = waves(p + vec2(0, e));
89 vec2 grad = vec2(hx - h, hy - h) / e;
90 vec3 n = normalize(vec3(-grad * .055, 1.0));
91 vec2 refractOffset = n.xy * (.025 + amp_low * .018);
92 vec2 uv = mirrorUV(tc + refractOffset);
93 float dispersion = .002 + .008 * amp_high + .0025 * length(grad);
94 vec2 axis = normalize(n.xy + vec2(.0001));
95 vec3 src = vec3(texture(samp, mirrorUV(uv + axis * dispersion)).r, texture(samp, uv).g,
96 texture(samp, mirrorUV(uv - axis * dispersion)).b);
97 vec3 l = normalize(vec3(-.35, .55, .76));
98 float focus = pow(max(dot(n, l), 0.0), 18.0);
99 float ridge = pow(clamp(length(grad) * .075, 0.0, 1.0), 1.7);
100 vec3 prism = spectrum(h * .16 + dot(p, vec2(.09, .13)) - time_f * .035);
101 vec3 result = src * (.70 + .28 * max(n.z, 0.0));
102 result += prism * focus * (.35 + amp_peak * .8) + prism * ridge * (.10 + amp_mid * .28);
103 result += pow(max(dot(n, normalize(vec3(.6, -.3, .74))), 0.0), 80.0) * .55;
104 color = vec4(aces(result * (1.0 + amp_rms * .22)), texture(samp, uv).a);
105}
layout(set=0, binding=1, std140) uniform SpriteExtended
Definition 3high.frag:7
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
#define amp_smooth
#define amp_mid
#define amp_low
#define amp_high
#define amp_peak
vec3 prism(float t)
Evaluates prism for this shader effect.
vec2 mirrorUV(vec2 uv)
Evaluates mirrorUV for this shader effect.
#define amp_rms
Definition breathe.frag:21
float h(vec2 p)
Evaluates h for this shader effect.
float n(vec2 p)
Evaluates n for this shader effect.
vec3 aces(vec3 x)
Evaluates aces for this shader effect.
#define TAU
vec3 spectrum(float t)
Evaluates spectrum for this shader effect.
float waves(vec2 p)
Evaluates waves for this shader effect.