ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
metal-code-plasma-alloy.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file metal-code-plasma-alloy.frag
5 * @brief Vulkan fragment shader: metal-code-plasma-alloy.
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 s = 0.0, a = 0.5;
62 for (int i = 0; i < 6; ++i) {
63 s += a * noise21(p);
64 p = mat2(0.8, -0.6, 0.6, 0.8) * p * 2.06 + 2.1;
65 a *= 0.5;
66 }
67 return s;
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 plasma for this shader effect.
79 * @param t Input value for the calculation.
80 * @return Computed vec3 value.
81 */
82vec3 plasma(float t) {
83 return 0.52 + 0.48 * cos(6.2831853 * (t + vec3(0.08, 0.38, 0.7)));
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 alloy for this shader effect.
95 * @param p Input value for the calculation.
96 * @return Computed float value.
97 */
98float alloy(vec2 p) {
99 float t = time_f;
100 vec2 q = p + vec2(fbm(p * 2.5 + t * 0.1), fbm(p * 2.5 + 7.3 - t * 0.08)) * 0.38;
101 float liquid = fbm(q * 4.0 + vec2(0, -t * 0.2));
102 float arc = sin(q.x * 18.0 + sin(q.y * 7.0 - t * 2.0) * 4.0 + t * 4.0);
103 return liquid * 0.62 + arc * 0.16 + sin(length(q) * 37.0 - t * 7.0 + liquid * 6.0) * 0.11;
104}
105/**
106 * @brief Evaluates normalAt for this shader effect.
107 * @param p Input value for the calculation.
108 * @param e Input value for the calculation.
109 * @return Computed vec3 value.
110 */
111vec3 normalAt(vec2 p, float e) {
112 float h = alloy(p);
113 vec2 g = vec2(alloy(p + vec2(e, 0)) - h, alloy(p + vec2(0, e)) - h) / e;
114 return normalize(vec3(-g * 0.18, 1));
115}
116/**
117 * @brief Executes the fragment shader entry point.
118 */
119void main(void) {
120 float aspect = max(iResolution.x, 1.0) / max(iResolution.y, 1.0);
121 vec2 p = (tc - 0.5) * vec2(aspect, 1.0);
122 float e = 2.0 / max(max(iResolution.x, iResolution.y), 320.0);
123 float h = alloy(p);
124 vec3 n = normalAt(p, e);
125 vec2 uv = mirrorUV(tc + n.xy * (0.028 + amp_mid * 0.02));
126 float split = 0.003 + amp_high * 0.009;
127 vec3 tex = vec3(texture(samp, mirrorUV(uv + n.xy * split)).r, texture(samp, uv).g,
128 texture(samp, mirrorUV(uv - n.xy * split)).b);
129 float y = dot(tex, vec3(0.299, 0.587, 0.114));
130 vec3 base = mix(vec3(y) * vec3(0.68, 0.78, 0.95), tex, 0.28);
131 vec3 v = normalize(vec3(-p * 0.1, 1.55)), l0 = normalize(vec3(-0.55, 0.7, 0.58)),
132 l1 = normalize(vec3(0.78, -0.2, 0.6));
133 float nv = max(dot(n, v), 0.0);
134 vec3 f0 = mix(vec3(0.6), base, 0.6);
135 vec3 F = f0 + (1.0 - f0) * pow(1.0 - nv, 5.0);
136 float s0 = pow(max(dot(n, normalize(v + l0)), 0.0), 140.0),
137 s1 = pow(max(dot(n, normalize(v + l1)), 0.0), 32.0);
138 vec3 env = plasma(dot(reflect(-v, n), vec3(0.45, 0.3, 0.25)) * 0.3 + time_f * 0.025);
139 vec3 col = base * (0.045 + 0.14 * max(dot(n, l0), 0.0)) +
140 F * (env * 0.8 + s0 * vec3(1.0, 0.85, 0.75) * 2.3 + s1 * vec3(0.25, 0.55, 1.2));
141 float arc = pow(abs(sin(h * 19.0 + time_f * 4.0)), 22.0);
142 float corona = pow(0.5 + 0.5 * sin(length(p) * 55.0 - time_f * 9.0 + h * 5.0), 12.0);
143 col += plasma(h * 0.4 + time_f * 0.04) * (arc * 0.8 + corona * 0.35) * (1.0 + amp_peak * 1.3);
144 color = vec4(aces(col * (1.0 + amp_smooth * 0.28)), 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.
float corona(vec2 p)
Evaluates corona 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.
float alloy(vec2 p)
Evaluates alloy for this shader effect.
vec3 plasma(float t)
Evaluates plasma for this shader effect.