ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
rainbow-code-diamond-wave.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-diamond-wave.frag
25 * @brief Vulkan fragment shader: rainbow-code-diamond-wave.
26 */
27// rainbow-code-diamond-wave
28// Sculpted diamond waves with jewel-like dispersion and crisp microfacet highlights.
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 rot for this shader effect.
45 * @param a Input value for the calculation.
46 * @return Computed mat2 value.
47 */
48mat2 rot(float a) {
49 float s = sin(a), c = cos(a);
50 return mat2(c, -s, s, c);
51}
52/**
53 * @brief Evaluates mirrorUV for this shader effect.
54 * @param p Input value for the calculation.
55 * @return Computed vec2 value.
56 */
57vec2 mirrorUV(vec2 p) {
58 return 1.0 - abs(mod(p, 2.0) - 1.0);
59}
60/**
61 * @brief Evaluates spectral for this shader effect.
62 * @param x Input value for the calculation.
63 * @return Computed vec3 value.
64 */
65vec3 spectral(float x) {
66 return .5 + .5 * cos(TAU * (x + vec3(.0, .34, .67)));
67}
68/**
69 * @brief Evaluates aces for this shader effect.
70 * @param x Input value for the calculation.
71 * @return Computed vec3 value.
72 */
73vec3 aces(vec3 x) {
74 x = max(x, 0.0);
75 return clamp((x * (2.51 * x + .03)) / (x * (2.43 * x + .59) + .14), 0.0, 1.0);
76}
77/**
78 * @brief Evaluates diamonds for this shader effect.
79 * @param p Input value for the calculation.
80 * @return Computed float value.
81 */
82float diamonds(vec2 p) {
83 p = rot(.785398) * p;
84 float t = time_f * .38;
85 vec2 cell = abs(fract(p * vec2(7.0, 9.0) + vec2(t * .12, -t * .08)) - .5);
86 float facet = .5 - max(cell.x, cell.y);
87 float wave = sin((abs(p.x) + abs(p.y)) * 28.0 - t * 3.2);
88 return facet * 1.8 + wave * .085 + sin(p.x * 16.0 - p.y * 7.0 + t) * .045;
89}
90/**
91 * @brief Executes the fragment shader entry point.
92 */
93void main() {
94 float aspect = max(iResolution.x, 1.0) / max(iResolution.y, 1.0);
95 vec2 p = (tc - .5) * vec2(aspect, 1.0);
96 float e = 1.4 / max(iResolution.y, 360.0);
97 float h = diamonds(p), hx = diamonds(p + vec2(e, 0)), hy = diamonds(p + vec2(0, e));
98 vec3 n = normalize(vec3((h - hx) * 3.2, (h - hy) * 3.2, e));
99 vec2 uv = mirrorUV(tc + n.xy * (.017 + amp_low * .018));
100 float split = .003 + amp_high * .013;
101 vec2 axis = normalize(n.xy + .0001);
102 vec3 src = vec3(texture(samp, mirrorUV(uv + axis * split)).r, texture(samp, uv).g,
103 texture(samp, mirrorUV(uv - axis * split)).b);
104 vec3 v = normalize(vec3(-p * .12, 1.2)), l1 = normalize(vec3(-.58, .67, .45)),
105 l2 = normalize(vec3(.65, -.2, .73));
106 float s1 = pow(max(dot(n, normalize(v + l1)), 0.0), 95.0),
107 s2 = pow(max(dot(n, normalize(v + l2)), 0.0), 55.0);
108 float fres = pow(1.0 - max(dot(n, v), 0.0), 4.0);
109 vec3 gem = spectral(h * .42 + length(p) * .15 - time_f * .024);
110 vec3 result = src * (.28 + .65 * max(dot(n, l1), 0.0)) + gem * (.10 + .58 * fres);
111 result += s1 * vec3(1.0, .82, .62) * (1.0 + amp_peak * .7) + s2 * gem * .65;
112 float edge = pow(1.0 - clamp(h * 2.2, 0.0, 1.0), 12.0);
113 result += gem * edge * (.08 + amp_mid * .24);
114 color = vec4(aces(result * (1.0 + amp_smooth * .14)), texture(samp, uv).a);
115}
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 wave(ivec2 p, ivec2 size)
Evaluates wave for this shader effect.
vec2 rot(vec2 v, float a)
Evaluates rot for this shader effect.
Definition air-bowl.frag:52
vec3 gem(float t)
Evaluates gem for this shader effect.
vec2 mirrorUV(vec2 uv)
Evaluates mirrorUV for this shader effect.
vec3 spectral(float t)
Evaluates spectral for this shader effect.
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.
vec2 cell(vec2 p)
Evaluates cell for this shader effect.
#define TAU
float s2(float x)
Evaluates s2 for this shader effect.
float diamonds(vec2 p)
Evaluates diamonds for this shader effect.