ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
new_fractal.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file new_fractal.frag
5 * @brief Vulkan fragment shader: new fractal.
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 iResolution ext.u0.zw
18#define time_f ext.u2.y
19
20layout(location = 0) in vec2 tc;
21layout(location = 0) out vec4 color;
22layout(set = 0, binding = 0) uniform sampler2D samp;
23
24
25
26/**
27 * @brief Evaluates hash for this shader effect.
28 * @param n Input value for the calculation.
29 * @return Computed float value.
30 */
31float hash(float n) {
32 return fract(sin(n) * 43758.5453123);
33}
34
35/**
36 * @brief Evaluates random2 for this shader effect.
37 * @param st Input value for the calculation.
38 * @return Computed vec2 value.
39 */
40vec2 random2(vec2 st) {
41 st = vec2(dot(st, vec2(127.1, 311.7)),
42 dot(st, vec2(269.5, 183.3)));
43 return -1.0 + 2.0 * fract(sin(st) * 43758.5453123);
44}
45
46/**
47 * @brief Evaluates smoothRandom2 for this shader effect.
48 * @param t Input value for the calculation.
49 * @return Computed vec2 value.
50 */
51vec2 smoothRandom2(float t) {
52 float t0 = floor(t);
53 float t1 = t0 + 1.0;
54 vec2 rand0 = random2(vec2(t0));
55 vec2 rand1 = random2(vec2(t1));
56 float mix_factor = fract(t);
57 return mix(rand0, rand1, smoothstep(0.0, 1.0, mix_factor));
58}
59
60/**
61 * @brief Evaluates rainbow for this shader effect.
62 * @param t Input value for the calculation.
63 * @return Computed vec3 value.
64 */
65vec3 rainbow(float t) {
66 t = fract(t);
67 float r = abs(t * 6.0 - 3.0) - 1.0;
68 float g = 2.0 - abs(t * 6.0 - 2.0);
69 float b = 2.0 - abs(t * 6.0 - 4.0);
70 return clamp(vec3(r, g, b), 0.0, 1.0);
71}
72
73/**
74 * @brief Evaluates pingPong for this shader effect.
75 * @param x Input value for the calculation.
76 * @param length Input value for the calculation.
77 * @return Computed float value.
78 */
79float pingPong(float x, float length) {
80 float modVal = mod(x, length * 2.0);
81 return modVal <= length ? modVal : length * 2.0 - modVal;
82}
83
84/**
85 * @brief Evaluates blur for this shader effect.
86 * @param image Input value for the calculation.
87 * @param uv Input value for the calculation.
88 * @param resolution Input value for the calculation.
89 * @return Computed vec4 value.
90 */
91vec4 blur(sampler2D image, vec2 uv, vec2 resolution) {
92 vec2 texelSize = 1.0 / resolution;
93 vec4 result = vec4(0.0);
94 float kernel[100];
95 float kernelVals[100] = float[](0.5, 1.0, 1.5, 2.0, 2.5, 2.5, 2.0, 1.5, 1.0, 0.5,
96 1.0, 2.0, 2.5, 3.0, 3.5, 3.5, 3.0, 2.5, 2.0, 1.0,
97 1.5, 2.5, 3.0, 3.5, 4.0, 4.0, 3.5, 3.0, 2.5, 1.5,
98 2.0, 3.0, 3.5, 4.0, 4.5, 4.5, 4.0, 3.5, 3.0, 2.0,
99 2.5, 3.5, 4.0, 4.5, 5.0, 5.0, 4.5, 4.0, 3.5, 2.5,
100 2.5, 3.5, 4.0, 4.5, 5.0, 5.0, 4.5, 4.0, 3.5, 2.5,
101 2.0, 3.0, 3.5, 4.0, 4.5, 4.5, 4.0, 3.5, 3.0, 2.0,
102 1.5, 2.5, 3.0, 3.5, 4.0, 4.0, 3.5, 3.0, 2.5, 1.5,
103 1.0, 2.0, 2.5, 3.0, 3.5, 3.5, 3.0, 2.5, 2.0, 1.0,
104 0.5, 1.0, 1.5, 2.0, 2.5, 2.5, 2.0, 1.5, 1.0, 0.5);
105
106 for (int i = 0; i < 100; i++) {
107 kernel[i] = kernelVals[i];
108 }
109
110 float kernelSum = 0.0;
111 for (int i = 0; i < 100; i++) {
112 kernelSum += kernel[i];
113 }
114
115 for (int x = -5; x <= 4; ++x) {
116 for (int y = -5; y <= 4; ++y) {
117 vec2 offset = vec2(float(x), float(y)) * texelSize;
118 result += texture(image, uv + offset) * kernel[(y + 5) * 10 + (x + 5)];
119 }
120 }
121
122 return result / kernelSum;
123}
124
125/**
126 * @brief Evaluates fractal for this shader effect.
127 * @param uv Input value for the calculation.
128 * @param time Input value for the calculation.
129 * @return Computed float value.
130 */
131float fractal(vec2 uv, float time) {
132 vec2 z = uv;
133 float iterations = 0.0;
134 const float maxIterations = 50.0;
135 for (float i = 0.0; i < maxIterations; i++) {
136 z = vec2(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y) + vec2(sin(time), cos(time));
137 if (length(z) > 2.0) break;
138 iterations += 1.0;
139 }
140 return iterations / maxIterations;
141}
142
143/**
144 * @brief Executes the fragment shader entry point.
145 */
146void main(void) {
147 vec2 uv = tc * 2.0 - 1.0;
148 uv.y *= iResolution.y / iResolution.x;
149
150 float fractalValue = fractal(cos(uv*pingPong(time_f, 30.0)+1.0), time_f);
151 vec3 fractalColor = rainbow(fractalValue);
152
153 float time_t = pingPong(time_f, 15.0) + 1.0;
154 float r = length(uv);
155 float theta = atan(uv.y, uv.x);
156 theta += time_f * 5.0 + r * 15.0;
157 uv = vec2(cos(theta), sin(theta)) * sin(r * time_f);
158
159 vec4 blurred_color = blur(samp, tc, iResolution);
160 vec3 blended_color = mix(blurred_color.rgb, fractalColor, 0.5);
161 color = vec4(sin(blended_color * time_t), blurred_color.a);
162}
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 pingPong(float x, float length)
Evaluates pingPong for this shader effect.
Definition af_scale.frag:32
vec4 blur(sampler2D image, vec2 uv, vec2 resolution)
Evaluates blur for this shader effect.
Definition af_scale.frag:44
float hash(vec2 p)
Evaluates hash for this shader effect.
vec3 rainbow(float t)
Evaluates rainbow for this shader effect.
float n(vec2 p)
Evaluates n for this shader effect.
float rand1(float x)
Evaluates rand1 for this shader effect.
vec4 fractalColor(vec2 uv)
Evaluates fractalColor for this shader effect.
Definition deeps1.frag:66
const int maxIterations
Definition fractal.frag:60
vec2 random2(vec2 st)
Evaluates random2 for this shader effect.
float fractal(vec2 uv, float time)
Evaluates fractal for this shader effect.
vec2 smoothRandom2(float t)
Evaluates smoothRandom2 for this shader effect.