ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
metal-code-opal-steel.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file metal-code-opal-steel.frag
5 * @brief Vulkan fragment shader: metal-code-opal-steel.
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 iResolution ext.u0.zw
23#define time_f ext.u2.y
24
25layout(location = 0) in vec2 tc;
26layout(location = 0) out vec4 color;
27layout(set = 0, binding = 0) uniform sampler2D samp;
28
29
30
31
32
33
34
35
36/**
37 * @brief Evaluates hash21 for this shader effect.
38 * @param p Input value for the calculation.
39 * @return Computed float value.
40 */
41float hash21(vec2 p) {
42 return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
43}
44/**
45 * @brief Evaluates noise21 for this shader effect.
46 * @param p Input value for the calculation.
47 * @return Computed float value.
48 */
49float noise21(vec2 p) {
50 vec2 i = floor(p), f = fract(p);
51 f = f * f * (3.0 - 2.0 * f);
52 return mix(mix(hash21(i), hash21(i + vec2(1, 0)), f.x),
53 mix(hash21(i + vec2(0, 1)), hash21(i + 1.0), f.x), f.y);
54}
55/**
56 * @brief Evaluates fbm for this shader effect.
57 * @param p Input value for the calculation.
58 * @return Computed float value.
59 */
60float fbm(vec2 p) {
61 float f = 0.0, a = 0.5;
62 for (int i = 0; i < 6; ++i) {
63 f += a * noise21(p);
64 p = mat2(0.8, -0.6, 0.6, 0.8) * p * 2.03 + 2.5;
65 a *= 0.5;
66 }
67 return f;
68}
69/**
70 * @brief Evaluates mirrorUV for this shader effect.
71 * @param p Input value for the calculation.
72 * @return Computed vec2 value.
73 */
74vec2 mirrorUV(vec2 p) {
75 return 1.0 - abs(mod(p, 2.0) - 1.0);
76}
77/**
78 * @brief Evaluates film for this shader effect.
79 * @param t Input value for the calculation.
80 * @return Computed vec3 value.
81 */
82vec3 film(float t) {
83 return 0.5 + 0.5 * cos(6.2831853 * (t + vec3(0.00, 0.29, 0.63)));
84}
85/**
86 * @brief Evaluates aces for this shader effect.
87 * @param x Input value for the calculation.
88 * @return Computed vec3 value.
89 */
90vec3 aces(vec3 x) {
91 return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0);
92}
93/**
94 * @brief Evaluates opal for this shader effect.
95 * @param p Input value for the calculation.
96 * @return Computed float value.
97 */
98float opal(vec2 p) {
99 float t = time_f;
100 vec2 q = p + vec2(fbm(p * 2.0 + t * 0.06), fbm(p * 2.0 + 6.1 - t * 0.05)) * 0.28;
101 float cloud = fbm(q * 4.0 + vec2(t * 0.08, -t * 0.07)), grain = fbm(q * 10.0 - t * 0.04);
102 return cloud * 0.65 + grain * 0.22 + sin(q.x * 12.0 + q.y * 9.0 - t * 2.0 + cloud * 7.0) * 0.12;
103}
104/**
105 * @brief Evaluates normalAt for this shader effect.
106 * @param p Input value for the calculation.
107 * @param e Input value for the calculation.
108 * @return Computed vec3 value.
109 */
110vec3 normalAt(vec2 p, float e) {
111 float h = opal(p);
112 vec2 g = vec2(opal(p + vec2(e, 0)) - h, opal(p + vec2(0, e)) - h) / e;
113 return normalize(vec3(-g * 0.19, 1));
114}
115/**
116 * @brief Executes the fragment shader entry point.
117 */
118void main(void) {
119 float aspect = max(iResolution.x, 1.0) / max(iResolution.y, 1.0);
120 vec2 p = (tc - 0.5) * vec2(aspect, 1.0);
121 float e = 2.0 / max(max(iResolution.x, iResolution.y), 320.0);
122 float h = opal(p);
123 vec3 n = normalAt(p, e);
124 vec2 uv = mirrorUV(tc + n.xy * (0.025 + amp_mid * 0.018));
125 float split = 0.002 + amp_high * 0.008;
126 vec3 tex = vec3(texture(samp, mirrorUV(uv + n.xy * split)).r, texture(samp, uv).g,
127 texture(samp, mirrorUV(uv - n.xy * split)).b);
128 float y = dot(tex, vec3(0.299, 0.587, 0.114));
129 vec3 base = mix(vec3(y) * vec3(0.82, 0.88, 0.94), tex, 0.3);
130 vec3 v = normalize(vec3(-p * 0.08, 1.6)), l0 = normalize(vec3(-0.6, 0.65, 0.55)),
131 l1 = normalize(vec3(0.72, -0.28, 0.63));
132 float nv = max(dot(n, v), 0.0);
133 vec3 f0 = mix(vec3(0.52), base, 0.68);
134 vec3 F = f0 + (1.0 - f0) * pow(1.0 - nv, 5.0);
135 float s0 = pow(max(dot(n, normalize(v + l0)), 0.0), 135.0),
136 s1 = pow(max(dot(n, normalize(v + l1)), 0.0), 30.0);
137 vec3 irid = film(h * 1.6 + (1.0 - nv) * 1.8 + time_f * 0.018);
138 vec3 col =
139 base * (0.055 + 0.16 * max(dot(n, l0), 0.0)) +
140 F * (irid * 1.05 + s0 * vec3(1.0, 0.9, 0.78) * 2.1 + s1 * vec3(0.35, 0.58, 1.0) * 0.85);
141 float fleck = pow(fbm(p * 22.0 + time_f * 0.08), 14.0);
142 col += film(h * 2.3 + time_f * 0.035) * fleck * (1.2 + amp_peak * 1.5);
143 col = mix(col, col * irid, 0.18 + amp_smooth * 0.12);
144 color = vec4(aces(col), texture(samp, uv).a);
145}
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
float fbm(vec2 point)
Evaluates fbm for this shader effect.
#define amp_smooth
#define amp_mid
#define amp_high
#define amp_peak
vec2 mirrorUV(vec2 uv)
Evaluates mirrorUV for this shader effect.
float hash21(vec2 p)
Evaluates hash21 for this shader effect.
float h(vec2 p)
Evaluates h for this shader effect.
float n(vec2 p)
Evaluates n for this shader effect.
float F(vec2 p)
Evaluates F for this shader effect.
vec3 aces(vec3 x)
Evaluates aces for this shader effect.
float noise21(vec2 p)
Evaluates noise21 for this shader effect.
vec3 film(float x, float v)
Evaluates film for this shader effect.
vec3 normalAt(vec2 p, float e, vec2 origin, float bass, float mid)
Evaluates normalAt for this shader effect.
float opal(vec2 p)
Evaluates opal for this shader effect.