ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
ant_gem_metal_nebula.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_peak ext.u2.w
14#define amp_smooth ext.u3.w
15#define iResolution ext.u0.zw
16#define time_f ext.u2.y
17
18/**
19 * @file ant_gem_metal_nebula.frag
20 * @brief Vulkan fragment shader: ant gem metal nebula.
21 */
22// ant_gem_metal_nebula
23// Space nebula with metallic dust clouds and spectrum-driven star formation
24layout(location = 0) in vec2 tc;
25layout(location = 0) out vec4 color;
26layout(set = 0, binding = 0) uniform sampler2D samp;
27
28
29
30
31layout(set = 0, binding = 3) uniform sampler1D spectrum;
32
33/**
34 * @brief Evaluates metalSpectrum for this shader effect.
35 * @param t Input value for the calculation.
36 * @return Computed vec3 value.
37 */
38vec3 metalSpectrum(float t) {
39 return vec3(0.5 + 0.5 * cos(6.28318 * (t + vec3(0.0, 0.33, 0.67))));
40}
41
42/**
43 * @brief Evaluates hash for this shader effect.
44 * @param p Input value for the calculation.
45 * @return Computed float value.
46 */
47float hash(vec2 p) {
48 return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
49}
50
51/**
52 * @brief Evaluates noise for this shader effect.
53 * @param p Input value for the calculation.
54 * @return Computed float value.
55 */
56float noise(vec2 p) {
57 vec2 i = floor(p);
58 vec2 f = fract(p);
59 vec2 u = f * f * (3.0 - 2.0 * f);
60 return mix(mix(hash(i), hash(i + vec2(1.0, 0.0)), u.x),
61 mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x), u.y);
62}
63
64/**
65 * @brief Evaluates fbm for this shader effect.
66 * @param p Input value for the calculation.
67 * @return Computed float value.
68 */
69float fbm(vec2 p) {
70 float f = 0.0;
71 float amp = 0.5;
72 for (int i = 0; i < 5; i++) {
73 f += noise(p) * amp;
74 p *= 2.1;
75 amp *= 0.5;
76 }
77 return f;
78}
79
80/**
81 * @brief Executes the fragment shader entry point.
82 */
83void main(void) {
84 float bass = texture(spectrum, 0.04).r;
85 float mid = texture(spectrum, 0.22).r;
86 float hiMid = texture(spectrum, 0.40).r;
87 float treble = texture(spectrum, 0.58).r;
88 float air = texture(spectrum, 0.80).r;
89
90 vec2 uv = tc * 2.0 - 1.0;
91 uv.x *= iResolution.x / iResolution.y;
92
93 float r = length(uv);
94 float angle = atan(uv.y, uv.x);
95
96 // Nebula gas clouds via fbm
97 float nebula1 = fbm(uv * 2.0 + time_f * 0.2);
98 float nebula2 = fbm(uv * 3.0 - time_f * 0.15 + 5.0);
99 float nebulaMix = nebula1 * 0.6 + nebula2 * 0.4;
100 nebulaMix *= 1.0 + bass * 0.8;
101
102 // Swirl driven by mid
103 float swirl = sin(angle * 3.0 + r * (6.0 + mid * 5.0) - time_f * 1.5);
104
105 // Texture warp through nebula
106 vec2 nebulaWarp = vec2(nebula1 - 0.5, nebula2 - 0.5) * (0.03 + mid * 0.04);
107 vec2 sampUV = tc + nebulaWarp;
108
109 // Chromatic split for gas refraction
110 float chroma = 0.01 + treble * 0.025;
111 vec3 baseTex;
112 baseTex.r = texture(samp, sampUV + vec2(chroma, chroma * 0.5)).r;
113 baseTex.g = texture(samp, sampUV).g;
114 baseTex.b = texture(samp, sampUV - vec2(chroma * 0.5, chroma)).b;
115
116 // Nebula coloring: purple/blue/pink metallic dust
117 vec3 nebulaColor1 = metalSpectrum(nebulaMix + time_f * 0.1) * vec3(0.8, 0.4, 1.0);
118 vec3 nebulaColor2 = metalSpectrum(nebulaMix + time_f * 0.1 + 0.3) * vec3(0.4, 0.6, 1.0);
119 vec3 nebulaColor = mix(nebulaColor1, nebulaColor2, swirl * 0.5 + 0.5);
120
121 float gasMask = smoothstep(0.3, 0.6, nebulaMix);
122 vec3 finalColor = mix(baseTex, baseTex * 0.5 + nebulaColor, gasMask * (0.4 + hiMid * 0.4));
123
124 // Star particles
125 float starField = pow(hash(floor(uv * 40.0)), 20.0);
126 float twinkle = sin(time_f * 3.0 + hash(floor(uv * 40.0)) * 100.0) * 0.5 + 0.5;
127 finalColor += vec3(1.0, 0.95, 0.9) * starField * twinkle * (2.0 + air * 3.0);
128
129 // Central core glow (newborn star)
130 float center = exp(-r * (4.0 - amp_smooth * 2.5));
131 finalColor += vec3(1.0, 0.9, 0.95) * center * (2.0 + amp_peak * 3.0);
132
133 // Ripple underlay
134 float ripple = sin(r * 12.0 - time_f * 2.0) * (0.03 + bass * 0.04);
135 finalColor += ripple * (0.5 + bass);
136
137 color = vec4(finalColor, 1.0);
138}
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
Definition abc.frag:17
float fbm(vec2 point)
Evaluates fbm for this shader effect.
#define amp_smooth
#define amp_peak
vec3 ripple(ivec2 p, ivec2 size)
Evaluates ripple for this shader effect.
float hash(vec2 p)
Evaluates hash for this shader effect.
float noise(vec2 p)
Evaluates noise for this shader effect.
vec3 metalSpectrum(float t)
Evaluates metalSpectrum for this shader effect.
vec2 swirl(vec2 uv, float centerRadius, float swirlAmount)
Evaluates swirl for this shader effect.
vec3 spectrum(float t)
Evaluates spectrum for this shader effect.