ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
vhs-code-kung-fury.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file vhs-code-kung-fury.frag
5 * @brief Vulkan fragment shader: vhs-code-kung-fury.
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 hash21 for this shader effect.
28 * @param p Input value for the calculation.
29 * @return Computed float value.
30 */
31float hash21(vec2 p) {
32 p = fract(p * vec2(123.34, 456.21));
33 p += dot(p, p + 45.32);
34 return fract(p.x * p.y);
35}
36
37/**
38 * @brief Evaluates sampleSharp for this shader effect.
39 * @param uv Input value for the calculation.
40 * @return Computed vec3 value.
41 */
42vec3 sampleSharp(vec2 uv) {
43 vec2 pixel = 1.0 / max(iResolution, vec2(1.0));
44 vec3 center = texture(samp, uv).rgb;
45 vec3 blur = texture(samp, clamp(uv + vec2(pixel.x, 0.0), 0.0, 1.0)).rgb;
46 blur += texture(samp, clamp(uv - vec2(pixel.x, 0.0), 0.0, 1.0)).rgb;
47 blur += texture(samp, clamp(uv + vec2(0.0, pixel.y), 0.0, 1.0)).rgb;
48 blur += texture(samp, clamp(uv - vec2(0.0, pixel.y), 0.0, 1.0)).rgb;
49 blur *= 0.25;
50 return clamp(center + (center - blur) * 0.65, 0.0, 1.0);
51}
52
53/**
54 * @brief Evaluates neonPalette for this shader effect.
55 * @param source Input value for the calculation.
56 * @return Computed vec3 value.
57 */
58vec3 neonPalette(vec3 source) {
59 float luma = dot(source, vec3(0.299, 0.587, 0.114));
60 float warmth = source.r - source.b;
61 float coolness = source.b - source.r;
62
63 vec3 graded = source;
64 graded.r += warmth * 0.18 + source.b * 0.08;
65 graded.g += coolness * 0.14;
66 graded.b += coolness * 0.24 + source.r * 0.04;
67
68 vec3 cyanShadow = vec3(0.015, 0.10, 0.14);
69 vec3 magentaLight = vec3(1.0, 0.16, 0.52);
70 float shadowMask = 1.0 - smoothstep(0.08, 0.48, luma);
71 float highlightMask = smoothstep(0.48, 0.98, luma);
72 graded = mix(graded, cyanShadow + graded * 0.58, shadowMask * 0.72);
73 graded = mix(graded, magentaLight + graded * 0.42, highlightMask * 0.34);
74
75 luma = dot(graded, vec3(0.299, 0.587, 0.114));
76 graded = mix(vec3(luma), graded, 1.30);
77 graded = (graded - 0.5) * 1.20 + 0.5;
78 return clamp(graded, 0.0, 1.0);
79}
80
81/**
82 * @brief Executes the fragment shader entry point.
83 */
84void main(void) {
85 vec2 uv = tc;
86 vec2 pixel = 1.0 / max(iResolution, vec2(1.0));
87 float frame = floor(time_f * 29.97);
88 float line = floor(uv.y * max(iResolution.y, 1.0));
89
90 float lineWobble = sin(uv.y * 170.0 + time_f * 2.4) * pixel.x * 1.4;
91 float trackingNoise = hash21(vec2(line, frame)) - 0.5;
92 float trackingBand = 1.0 - smoothstep(0.0, 0.035, abs(uv.y - fract(time_f * 0.075)));
93 uv.x += lineWobble + trackingNoise * pixel.x * 0.7;
94 uv.x += trackingBand * trackingNoise * 0.055;
95 uv = clamp(uv, pixel, vec2(1.0) - pixel);
96
97 float chromaShift = pixel.x * 2.2 + trackingBand * 0.003;
98 vec3 source = sampleSharp(uv);
99 source.r = sampleSharp(clamp(uv + vec2(chromaShift, 0.0), 0.0, 1.0)).r;
100 source.b = sampleSharp(clamp(uv - vec2(chromaShift * 1.35, 0.0), 0.0, 1.0)).b;
101 vec3 image = neonPalette(source);
102
103 vec3 glow = texture(samp, clamp(uv + pixel * vec2(4.0, 2.0), 0.0, 1.0)).rgb;
104 glow += texture(samp, clamp(uv - pixel * vec2(4.0, 2.0), 0.0, 1.0)).rgb;
105 glow += texture(samp, clamp(uv + pixel * vec2(-4.0, 2.0), 0.0, 1.0)).rgb;
106 glow += texture(samp, clamp(uv + pixel * vec2(4.0, -2.0), 0.0, 1.0)).rgb;
107 glow *= 0.25;
108 glow = neonPalette(glow);
109 image += max(glow - 0.64, 0.0) * vec3(0.85, 0.42, 1.10) * 0.48;
110
111 float scanline = 0.965 + 0.035 * sin(line * 3.14159265);
112 float grain = hash21(gl_FragCoord.xy + frame * 17.0) - 0.5;
113 float flicker = 0.985 + hash21(vec2(frame, 4.0)) * 0.015;
114 float vignette = 1.0 - smoothstep(0.22, 0.78, length((tc - 0.5) * vec2(1.08, 1.0)));
115 image *= scanline * flicker;
116 image += grain * (0.022 + trackingBand * 0.12);
117 image *= mix(0.80, 1.0, vignette);
118
119 color = vec4(clamp(image, 0.0, 1.0), 1.0);
120}
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
vec4 blur(sampler2D image, vec2 uv, vec2 resolution)
Evaluates blur for this shader effect.
Definition af_scale.frag:44
vec3 neonPalette(float t)
Evaluates neonPalette for this shader effect.
Definition aura2.frag:112
float luma(vec3 c)
Evaluates luma for this shader effect.
Definition auraXi1.frag:58
float hash21(vec2 p)
Evaluates hash21 for this shader effect.
float scanline(vec2 uv)
Evaluates scanline for this shader effect.
vec3 sampleSharp(vec2 uv)
Evaluates sampleSharp for this shader effect.