ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
4rand.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file 4rand.frag
5 * @brief Vulkan fragment shader: 4rand.
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// Function to quantize colors to an 8-bit palette
27/**
28 * @brief Evaluates NESPalette for this shader effect.
29 * @param col Input value for the calculation.
30 * @return Computed vec3 value.
31 */
32vec3 NESPalette(vec3 col) {
33 float[16] rVals = float[16](0.0, 0.26, 0.5, 0.74, 1.0, 0.88, 0.62, 0.38, 0.14, 0.08, 0.22, 0.54, 0.78, 0.92, 0.96, 0.1);
34 float[16] gVals = float[16](0.0, 0.13, 0.25, 0.37, 0.5, 0.44, 0.31, 0.19, 0.08, 0.13, 0.37, 0.44, 0.56, 0.69, 0.82, 0.96);
35 float[16] bVals = float[16](0.0, 0.06, 0.13, 0.25, 0.38, 0.44, 0.56, 0.69, 0.82, 0.96, 0.74, 0.5, 0.25, 0.13, 0.06, 0.0);
36 int idxR = int(floor(col.r * 15.0 + 0.5));
37 int idxG = int(floor(col.g * 15.0 + 0.5));
38 int idxB = int(floor(col.b * 15.0 + 0.5));
39 return vec3(rVals[idxR], gVals[idxG], bVals[idxB]);
40}
41
42// Function to apply a feedback loop
43/**
44 * @brief Evaluates echo loop for this shader effect.
45 * @param baseColor Input value for the calculation.
46 * @param count Input value for the calculation.
47 * @return Computed vec4 value.
48 */
49vec4 echo_loop(vec4 baseColor, int count) {
50 vec4 col = baseColor;
51 for (int i = 2; i < count; i += 2) {
52 vec4 pos = texture(samp, tc / (i * fract(time_f)));
53 col = (0.6 * col) + (0.3 * pos);
54 }
55 return col;
56}
57
58// Main function
59/**
60 * @brief Executes the fragment shader entry point.
61 */
62void main(void) {
63 vec2 normCoord = tc;
64
65 // Apply deformation effect
66 float warpAmount = tan(time_f);
67 vec2 warp = vec2(
68 sin(normCoord.y * 10.0 + time_f) * warpAmount,
69 cos(normCoord.x * 10.0 + time_f) * warpAmount
70 );
71 vec2 warpedCoord = normCoord + warp;
72
73 // Sample texture with deformation
74 vec4 texColor = texture(samp, warpedCoord);
75
76 // Apply 8-bit palette quantization
77 vec3 quantizedColor = NESPalette(texColor.rgb);
78 vec4 quantizedTexColor = vec4(quantizedColor, texColor.a);
79
80 // Apply echo loop effect
81 vec4 echoedColor = echo_loop(quantizedTexColor, 14);
82
83 // Apply negative effect
84 color = vec4(1.0 - echoedColor.rgb, echoedColor.a);
85}
86
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 time_f
Definition 3high.frag:19
vec4 echo_loop(vec4 baseColor, int count)
Evaluates echo loop for this shader effect.
Definition 4rand.frag:49
vec3 NESPalette(vec3 col)
Evaluates NESPalette for this shader effect.
Definition 4rand.frag:32
vec2 warp(vec2 p, vec2 o, float k)
Evaluates warp for this shader effect.