ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
metal-code-iridescent-foundry.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file metal-code-iridescent-foundry.frag
5 * @brief Vulkan fragment shader: metal-code-iridescent-foundry.
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.07 + 1.9;
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 thinFilm for this shader effect.
79 * @param t Input value for the calculation.
80 * @return Computed vec3 value.
81 */
82vec3 thinFilm(float t) {
83 return 0.5 + 0.5 * cos(6.2831853 * (t + vec3(0.00, 0.34, 0.68)));
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/**
95 * @brief Evaluates foundry for this shader effect.
96 * @param p Input value for the calculation.
97 * @return Computed float value.
98 */
99float foundry(vec2 p) {
100 float t = time_f;
101 float flow = fbm(p * 2.2 + vec2(t * 0.12, -t * 0.2));
102 vec2 q = p + vec2(fbm(p * 3.0 + t * 0.08), fbm(p * 3.0 + 8.7 - t * 0.09)) * 0.45;
103 float hammer = fbm(q * 6.0);
104 float channels = abs(sin(q.x * 8.0 + sin(q.y * 5.0 + t) * 2.0));
105 return flow * 0.65 + hammer * 0.28 - channels * 0.20 + sin(length(p) * 24.0 - t * 4.0) * 0.08;
106}
107/**
108 * @brief Evaluates normalAt for this shader effect.
109 * @param p Input value for the calculation.
110 * @param e Input value for the calculation.
111 * @return Computed vec3 value.
112 */
113vec3 normalAt(vec2 p, float e) {
114 float h = foundry(p);
115 vec2 g = vec2(foundry(p + vec2(e, 0)) - h, foundry(p + vec2(0, e)) - h) / e;
116 return normalize(vec3(-g * 0.2, 1));
117}
118/**
119 * @brief Evaluates lighting for this shader effect.
120 * @param base Input value for the calculation.
121 * @param n Input value for the calculation.
122 * @param p Input value for the calculation.
123 * @param heat Input value for the calculation.
124 * @return Computed vec3 value.
125 */
126vec3 lighting(vec3 base, vec3 n, vec2 p, float heat) {
127 vec3 v = normalize(vec3(-p * 0.1, 1.6));
128 vec3 l0 = normalize(vec3(-0.55, 0.72, 0.62)), l1 = normalize(vec3(0.8, -0.25, 0.55));
129 float nv = max(dot(n, v), 0.0);
130 vec3 f0 = mix(vec3(0.48), base, 0.78);
131 vec3 F = f0 + (1.0 - f0) * pow(1.0 - nv, 5.0);
132 float sp0 = pow(max(dot(n, normalize(v + l0)), 0.0), 110.0);
133 float sp1 = pow(max(dot(n, normalize(v + l1)), 0.0), 32.0);
134 vec3 refl =
135 thinFilm(dot(reflect(-v, n), vec3(0.43, 0.37, 0.2)) * 0.35 + time_f * 0.018 + heat * 0.1);
136 return base * (0.06 + 0.18 * max(dot(n, l0), 0.0)) +
137 F * (refl * 0.9 + sp0 * vec3(1, 0.7, 0.35) * 2.8 + sp1 * vec3(0.25, 0.5, 1.2));
138}
139/**
140 * @brief Executes the fragment shader entry point.
141 */
142void main(void) {
143 float aspect = max(iResolution.x, 1.0) / max(iResolution.y, 1.0);
144 vec2 p = (tc - 0.5) * vec2(aspect, 1.0);
145 float e = 2.0 / max(max(iResolution.x, iResolution.y), 320.0);
146 float h = foundry(p);
147 vec3 n = normalAt(p, e);
148 vec2 uv = mirrorUV(tc + n.xy * (0.028 + amp_low * 0.02));
149 float ca = 0.003 + amp_high * 0.006;
150 vec3 src = vec3(texture(samp, mirrorUV(uv + n.xy * ca)).r, texture(samp, uv).g,
151 texture(samp, mirrorUV(uv - n.xy * ca)).b);
152 float y = dot(src, vec3(0.299, 0.587, 0.114));
153 vec3 alloy = mix(vec3(y) * vec3(0.9, 0.72, 0.5), src, 0.32);
154 float heat = smoothstep(0.42, 0.72, fbm(p * 2.4 + vec2(0, -time_f * 0.16)));
155 vec3 col = lighting(alloy, n, p, heat);
156 vec3 hot = mix(vec3(0.5, 0.015, 0.002), vec3(1.8, 0.65, 0.08), smoothstep(0.35, 0.8, heat));
157 float crack = pow(1.0 - abs(sin(h * 10.0 + time_f)), 14.0);
158 col += hot * heat * (0.25 + 0.65 * amp_low) +
159 thinFilm(h * 0.35 + time_f * 0.025) * crack * (0.2 + amp_peak);
160 color = vec4(aces(col * (1.0 + amp_smooth * 0.25)), texture(samp, uv).a);
161}
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_low
#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 normalAt(vec2 p, float e, vec2 origin, float bass, float mid)
Evaluates normalAt for this shader effect.
vec3 thinFilm(float phase)
Evaluates thinFilm for this shader effect.
vec3 lighting(vec3 base, vec3 n, vec2 p, float heat)
Evaluates lighting for this shader effect.
float foundry(vec2 p)
Evaluates foundry for this shader effect.
float alloy(vec2 p)
Evaluates alloy for this shader effect.