ACMX Vulkan Shader Library
GLSL 4.50 shader effects for ACMX's Vulkan renderer
Loading...
Searching...
No Matches
square_grid.frag
Go to the documentation of this file.
1#version 450
2
3/**
4 * @file square_grid.frag
5 * @brief Vulkan fragment shader: square grid.
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 time_f ext.u2.y
18
19layout(location = 0) in vec2 tc;
20layout(location = 0) out vec4 color;
21layout(set = 0, binding = 0) uniform sampler2D samp;
22
23
24/**
25 * @brief Evaluates xor RGB for this shader effect.
26 * @param icolor Input value for the calculation.
27 * @param source Input value for the calculation.
28 * @return Computed vec4 value.
29 */
30vec4 xor_RGB(vec4 icolor, vec4 source) {
31 ivec3 int_color;
32 ivec4 isource = ivec4(source * 255);
33 for(int i = 0; i < 3; ++i) {
34 int_color[i] = int(255 * icolor[i]);
35 int_color[i] = int_color[i]^isource[i];
36 if(int_color[i] > 255)
37 int_color[i] = int_color[i]%255;
38 icolor[i] = float(int_color[i])/255;
39 }
40 icolor.a = 1.0;
41return icolor;
42}
43
44/**
45 * @brief Evaluates randomColor for this shader effect.
46 * @param cell_coord Input value for the calculation.
47 * @return Computed vec4 value.
48 */
49vec4 randomColor(ivec2 cell_coord) {
50 int n = cell_coord.x + cell_coord.y * 10 + int(time_f);
51 n = (n << 13) ^ n;
52 n = (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff;
53 return vec4(float((n & 0xFF0000) >> 16) / 255.0,
54 float((n & 0x00FF00) >> 8) / 255.0,
55 float(n & 0x0000FF) / 255.0,
56 1.0);
57}
58
59/**
60 * @brief Executes the fragment shader entry point.
61 */
62void main(void) {
63 int grid_size = 10;
64 float cell_size = 1.0 / float(grid_size);
65 ivec2 cell_coord = ivec2(floor(tc.x * float(grid_size)), floor(tc.y * float(grid_size)));
66 vec2 cell_center = (vec2(cell_coord) + 0.5) * cell_size;
67 vec2 offset = tc - cell_center;
68 float border = 0.05 * cell_size;
69 if (abs(offset.x) < border || abs(offset.y) < border) {
70 color = vec4(0, 0, 0, 1);
71 } else {
72 vec4 rand_color = randomColor(cell_coord);
73 color = xor_RGB(texture(samp, tc), rand_color);
74 }
75}
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 xor_RGB(vec4 a, vec4 b)
Evaluates xor RGB for this shader effect.
float n(vec2 p)
Evaluates n for this shader effect.
vec4 randomColor(ivec2 cell_coord)
Evaluates randomColor for this shader effect.