ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
gpt_trip.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file gpt_trip.frag
5 * @brief Vulkan fragment shader: gpt trip.
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 lum for this shader effect.
28 * @param c Input value for the calculation.
29 * @return Computed float value.
30 */
31float lum(vec3 c) {
32 return dot(c, vec3(0.2126, 0.7152, 0.0722));
33}
34
35/**
36 * @brief Evaluates hash for this shader effect.
37 * @param p Input value for the calculation.
38 * @return Computed float value.
39 */
40float hash(vec2 p) {
41 return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);
42}
43
44/**
45 * @brief Evaluates noise for this shader effect.
46 * @param p Input value for the calculation.
47 * @return Computed float value.
48 */
49float noise(vec2 p) {
50 vec2 i = floor(p);
51 vec2 f = fract(p);
52 float a = hash(i);
53 float b = hash(i + vec2(1.0, 0.0));
54 float c = hash(i + vec2(0.0, 1.0));
55 float d = hash(i + vec2(1.0, 1.0));
56 vec2 u = f * f * (3.0 - 2.0 * f);
57 return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
58}
59
60/**
61 * @brief Evaluates rgb2hsv for this shader effect.
62 * @param c Input value for the calculation.
63 * @return Computed vec3 value.
64 */
65vec3 rgb2hsv(vec3 c) {
66 vec4 K = vec4(0.0, -0.3333333, 0.6666667, -1.0);
67 vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
68 vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
69 float d = q.x - min(q.w, q.y);
70 float e = 0.00001;
71 return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
72}
73
74/**
75 * @brief Evaluates hsv2rgb for this shader effect.
76 * @param c Input value for the calculation.
77 * @return Computed vec3 value.
78 */
79vec3 hsv2rgb(vec3 c) {
80 vec3 p = abs(fract(c.xxx + vec3(0.0, 0.6666667, 0.3333333)) * 6.0 - 3.0);
81 vec3 rgb = clamp(p - 1.0, 0.0, 1.0);
82 return c.z * mix(vec3(1.0), rgb, c.y);
83}
84
85/**
86 * @brief Evaluates warp for this shader effect.
87 * @param uv Input value for the calculation.
88 * @return Computed vec2 value.
89 */
90vec2 warp(vec2 uv) {
91 vec2 p = uv * 2.0 - 1.0;
92 float r = length(p);
93 float a = atan(p.y, p.x);
94 float n1 = noise(uv * 5.0 + vec2(time_f * 0.08, -time_f * 0.06));
95 float n2 = noise(uv * 9.0 + vec2(-time_f * 0.05, time_f * 0.07));
96 a += 0.04 * sin(r * 8.0 - time_f * 0.5) + 0.03 * (n1 - 0.5);
97 r += 0.012 * sin(a * 6.0 + time_f * 0.4) + 0.01 * (n2 - 0.5);
98 p = vec2(cos(a), sin(a)) * r;
99 uv = p * 0.5 + 0.5;
100 uv += 0.004 * vec2(
101 sin(uv.y * 22.0 + time_f * 0.7),
102 cos(uv.x * 18.0 - time_f * 0.6)
103 );
104 return uv;
105}
106
107/**
108 * @brief Evaluates edgeSobel for this shader effect.
109 * @param uv Input value for the calculation.
110 * @param px Input value for the calculation.
111 * @return Computed float value.
112 */
113float edgeSobel(vec2 uv, vec2 px) {
114 float tl = lum(texture(samp, uv + px * vec2(-1.0, -1.0)).rgb);
115 float tc0 = lum(texture(samp, uv + px * vec2( 0.0, -1.0)).rgb);
116 float tr = lum(texture(samp, uv + px * vec2( 1.0, -1.0)).rgb);
117 float ml = lum(texture(samp, uv + px * vec2(-1.0, 0.0)).rgb);
118 float mr = lum(texture(samp, uv + px * vec2( 1.0, 0.0)).rgb);
119 float bl = lum(texture(samp, uv + px * vec2(-1.0, 1.0)).rgb);
120 float bc = lum(texture(samp, uv + px * vec2( 0.0, 1.0)).rgb);
121 float br = lum(texture(samp, uv + px * vec2( 1.0, 1.0)).rgb);
122
123 float gx = -tl - 2.0 * ml - bl + tr + 2.0 * mr + br;
124 float gy = -tl - 2.0 * tc0 - tr + bl + 2.0 * bc + br;
125
126 return sqrt(gx * gx + gy * gy);
127}
128
129/**
130 * @brief Executes the fragment shader entry point.
131 */
132void main() {
133 vec2 uv = tc;
134 vec2 px = 1.0 / iResolution;
135
136 vec2 wuv = warp(uv);
137
138 vec3 src = texture(samp, wuv).rgb;
139 vec3 s1 = texture(samp, wuv + px * vec2(1.0, 0.0)).rgb;
140 vec3 s2 = texture(samp, wuv + px * vec2(-1.0, 0.0)).rgb;
141 vec3 s3 = texture(samp, wuv + px * vec2(0.0, 1.0)).rgb;
142 vec3 s4 = texture(samp, wuv + px * vec2(0.0, -1.0)).rgb;
143
144 vec3 soft = (src + s1 + s2 + s3 + s4) / 5.0;
145
146 float edge = edgeSobel(wuv, px);
147 edge = clamp(edge * 1.6, 0.0, 1.0);
148
149 float detail = length(src - soft);
150 detail = clamp(detail * 3.0, 0.0, 1.0);
151
152 vec3 hsv = rgb2hsv(src);
153 hsv.x = fract(hsv.x + 0.08 * sin(lum(src) * 8.0 + time_f * 0.25) + 0.12 * edge);
154 hsv.y = clamp(hsv.y * 1.4 + 0.2 * detail + 0.2 * edge, 0.0, 1.0);
155 hsv.z = clamp(hsv.z * 1.05 + 0.12 * detail, 0.0, 1.0);
156
157 vec3 neonBase = hsv2rgb(hsv);
158
159 vec3 edgeTint1 = vec3(1.0, 0.1, 0.9);
160 vec3 edgeTint2 = vec3(0.1, 1.0, 0.5);
161 vec3 edgeTint3 = vec3(0.2, 0.6, 1.0);
162
163 vec3 contour = vec3(0.0);
164 contour += edgeTint1 * smoothstep(0.10, 0.35, edge);
165 contour += edgeTint2 * smoothstep(0.25, 0.60, edge);
166 contour += edgeTint3 * smoothstep(0.45, 0.90, edge);
167
168 float rings = 0.5 + 0.5 * sin((lum(src) + detail * 0.7) * 20.0 + time_f * 0.2);
169 vec3 ringTint = mix(vec3(0.8, 0.1, 1.0), vec3(0.1, 0.9, 1.0), rings);
170
171 vec3 finalColor = mix(src, neonBase, 0.45);
172 finalColor += contour * 0.35;
173 finalColor += ringTint * detail * 0.12;
174
175 finalColor = mix(finalColor, src, smoothstep(0.75, 1.0, lum(src)) * 0.45);
176
177 finalColor = clamp(finalColor, 0.0, 1.0);
178 finalColor = pow(finalColor, vec3(0.95));
179
180 color = vec4(finalColor, 1.0);
181}
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 hash(vec2 p)
Evaluates hash for this shader effect.
float noise(vec2 p)
Evaluates noise for this shader effect.
vec3 hsv2rgb(vec3 c)
Evaluates hsv2rgb for this shader effect.
Definition aura.frag:43
vec2 warp(vec2 p, vec2 o, float k)
Evaluates warp for this shader effect.
float s3
Definition eye2.frag:24
float n2(vec2 p)
Evaluates n2 for this shader effect.
float lum(vec3 c)
Evaluates lum for this shader effect.
vec3 rgb2hsv(vec3 c)
Evaluates rgb2hsv for this shader effect.
Definition gpt_trip.frag:65
float edgeSobel(vec2 uv, vec2 px)
Evaluates edgeSobel for this shader effect.
float s2(float x)
Evaluates s2 for this shader effect.