Initial Compute Shader for Plate Generation.
This commit is contained in:
parent
9d2dd0ca82
commit
47ca1265e6
8 changed files with 214 additions and 29 deletions
40
shaders/compute/PlateExpansion.glsl
Normal file
40
shaders/compute/PlateExpansion.glsl
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
// Invocations in the (x, y, z) dimension
|
||||
layout(local_size_x = 1000, local_size_y = 1, local_size_z = 1) in;
|
||||
|
||||
// A binding to the buffer we create in our script
|
||||
layout(set = 0, binding = 0, std430) restrict buffer PointBuffer {
|
||||
int points[];
|
||||
}
|
||||
pointbuffer;
|
||||
layout(set = 0, binding = 1, std430) restrict buffer NeighborBuffer {
|
||||
int neighbors[];
|
||||
}
|
||||
neighborbuffer;
|
||||
layout(set = 0, binding = 2, std430) restrict buffer PlateBuffer {
|
||||
int plateid[];
|
||||
}
|
||||
platebuffer;
|
||||
|
||||
// The code we want to execute in each invocation
|
||||
void main() {
|
||||
// Iteration is gl_GlobalInvocationID.x
|
||||
// Neighbors for Point gl_GlobalInvocationID.y
|
||||
for (int point = 0; point < int(gl_WorkGroupSize.x); point++)
|
||||
{
|
||||
int localpoint = int(gl_WorkGroupID.x)*int(gl_WorkGroupSize.x) + point;
|
||||
for (int neighbor = 0; neighbor < 6; neighbor++) {
|
||||
if (neighborbuffer.neighbors[localpoint*6+neighbor] == -1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (platebuffer.plateid[localpoint] != -1 && platebuffer.plateid[neighborbuffer.neighbors[localpoint*6+neighbor]] == -1)
|
||||
{
|
||||
// Neighbor unclaimed, and we can claim it.
|
||||
platebuffer.plateid[neighborbuffer.neighbors[localpoint*6+neighbor]] = platebuffer.plateid[localpoint];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
14
shaders/compute/PlateExpansion.glsl.import
Normal file
14
shaders/compute/PlateExpansion.glsl.import
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://cypd2lshixd17"
|
||||
path="res://.godot/imported/PlateExpansion.glsl-9047ef54068b6d1a50f93c2cd303b382.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://shaders/compute/PlateExpansion.glsl"
|
||||
dest_files=["res://.godot/imported/PlateExpansion.glsl-9047ef54068b6d1a50f93c2cd303b382.res"]
|
||||
|
||||
[params]
|
||||
|
||||
17
shaders/compute/compute_example.glsl
Normal file
17
shaders/compute/compute_example.glsl
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#[compute]
|
||||
#version 450
|
||||
|
||||
// Invocations in the (x, y, z) dimension
|
||||
layout(local_size_x = 2, local_size_y = 1, local_size_z = 1) in;
|
||||
|
||||
// A binding to the buffer we create in our script
|
||||
layout(set = 0, binding = 0, std430) restrict buffer MyDataBuffer {
|
||||
float data[];
|
||||
}
|
||||
my_data_buffer;
|
||||
|
||||
// The code we want to execute in each invocation
|
||||
void main() {
|
||||
// gl_GlobalInvocationID.x uniquely identifies this invocation across all work groups
|
||||
my_data_buffer.data[gl_GlobalInvocationID.x] *= 2.0;
|
||||
}
|
||||
14
shaders/compute/compute_example.glsl.import
Normal file
14
shaders/compute/compute_example.glsl.import
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[remap]
|
||||
|
||||
importer="glsl"
|
||||
type="RDShaderFile"
|
||||
uid="uid://du2kf2vmf800w"
|
||||
path="res://.godot/imported/compute_example.glsl-3f04b63d0b43774004ed10776fd05117.res"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://shaders/compute/compute_example.glsl"
|
||||
dest_files=["res://.godot/imported/compute_example.glsl-3f04b63d0b43774004ed10776fd05117.res"]
|
||||
|
||||
[params]
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue