32 lines
850 B
Plaintext
32 lines
850 B
Plaintext
|
// based on:
|
||
|
// - https://www.youtube.com/watch?v=5CKvGYqagyI
|
||
|
// - https://pastebin.com/pbGGjrE8
|
||
|
|
||
|
#[compute]
|
||
|
#version 450
|
||
|
|
||
|
// Invocations in the (x, y, z) dimension
|
||
|
layout(local_size_x = 4, local_size_y = 4, local_size_z = 1) in;
|
||
|
|
||
|
// A binding to the buffer we create in our script
|
||
|
layout(set = 0, binding = 0, std430) buffer MyDataBuffer {
|
||
|
int data[];
|
||
|
}
|
||
|
my_data_buffer;
|
||
|
|
||
|
layout(set = 0, binding = 1) uniform sampler2D tex;
|
||
|
|
||
|
void main() {
|
||
|
if (texture(tex, vec2(gl_GlobalInvocationID.x, gl_GlobalInvocationID.y)).r > 0.0) {
|
||
|
atomicAdd(my_data_buffer.data[0], 1);
|
||
|
}
|
||
|
|
||
|
if (texture(tex, vec2(gl_GlobalInvocationID.x, gl_GlobalInvocationID.y)).b > 0.0) {
|
||
|
atomicAdd(my_data_buffer.data[1], 1);
|
||
|
}
|
||
|
|
||
|
if (texture(tex, vec2(gl_GlobalInvocationID.x, gl_GlobalInvocationID.y)).rgb == vec3(1.0, 0, 1.0)) {
|
||
|
atomicAdd(my_data_buffer.data[2], 1);
|
||
|
}
|
||
|
}
|