aboutsummaryrefslogtreecommitdiff
path: root/raylib/examples/others/resources/shaders/glsl430/gol_transfert.glsl
diff options
context:
space:
mode:
authorUneven Prankster <unevenprankster@protonmail.com>2023-10-15 21:28:29 -0300
committerUneven Prankster <unevenprankster@protonmail.com>2023-10-15 21:28:29 -0300
commit1c0cc775732201f4c4d3ee0d6772be786b3b4aa1 (patch)
treef5d692d046868261275c7430a624c3ea9ed75d3d /raylib/examples/others/resources/shaders/glsl430/gol_transfert.glsl
parenta89f892640cf12f75c7ce18e6e88c70a8d3965ed (diff)
A lot has certainly happened!
Diffstat (limited to 'raylib/examples/others/resources/shaders/glsl430/gol_transfert.glsl')
-rw-r--r--raylib/examples/others/resources/shaders/glsl430/gol_transfert.glsl51
1 files changed, 51 insertions, 0 deletions
diff --git a/raylib/examples/others/resources/shaders/glsl430/gol_transfert.glsl b/raylib/examples/others/resources/shaders/glsl430/gol_transfert.glsl
new file mode 100644
index 0000000..a202338
--- /dev/null
+++ b/raylib/examples/others/resources/shaders/glsl430/gol_transfert.glsl
@@ -0,0 +1,51 @@
+#version 430
+
+// Game of life transfert shader
+
+#define GOL_WIDTH 768
+
+// Game Of Life Update Command
+// NOTE: matches the structure defined on main program
+struct GolUpdateCmd {
+ uint x; // x coordinate of the gol command
+ uint y; // y coordinate of the gol command
+ uint w; // width of the filled zone
+ uint enabled; // whether to enable or disable zone
+};
+
+// Local compute unit size
+layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+
+// Output game of life grid buffer
+layout(std430, binding = 1) buffer golBufferLayout
+{
+ uint golBuffer[]; // golBuffer[x, y] = golBuffer[x + GOL_WIDTH * y]
+};
+
+// Command buffer
+layout(std430, binding = 3) readonly restrict buffer golUpdateLayout
+{
+ uint count;
+ GolUpdateCmd commands[];
+};
+
+#define isInside(x, y) (((x) >= 0) && ((y) >= 0) && ((x) < GOL_WIDTH) && ((y) < GOL_WIDTH))
+#define getBufferIndex(x, y) ((x) + GOL_WIDTH * (y))
+
+void main()
+{
+ uint cmdIndex = gl_GlobalInvocationID.x;
+ GolUpdateCmd cmd = commands[cmdIndex];
+
+ for (uint x = cmd.x; x < (cmd.x + cmd.w); x++)
+ {
+ for (uint y = cmd.y; y < (cmd.y + cmd.w); y++)
+ {
+ if (isInside(x, y))
+ {
+ if (cmd.enabled != 0) atomicOr(golBuffer[getBufferIndex(x, y)], 1);
+ else atomicAnd(golBuffer[getBufferIndex(x, y)], 0);
+ }
+ }
+ }
+}