Files
RealTimeFractal/Shaders/Compute.glsl
2025-11-08 21:30:49 +01:00

41 lines
1.3 KiB
GLSL

#version 460 core
layout(rgba32f, binding = 0) uniform writeonly image2D outputImage;
layout(std430, binding = 3) buffer layoutName
{
vec2 o_Points[];
};
// 1 -> 1
// 2 -> 3
// 3 -> 9
// 4 -> 27
// 5 -> 81
// 6 -> 243
// ...
// 4 27
// 1 + 3 + 9 = 13
// Sn = ((3^n)-1)/2
// S3 = 3^3 - 1 / 2
// 3^4
// gl_NumWorkGroups : This variable contains the number of work groups passed to the dispatch function.
// gl_WorkGroupID : This is the current work group for this shader invocation. Each of the XYZ components will be on the half-open range [0, gl_NumWorkGroups.XYZ).
// gl_LocalInvocationID : This is the current invocation of the shader within the work group. Each of the XYZ components will be on the half-open range [0, gl_WorkGroupSize.XYZ).
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main()
{
uint triangleCount = gl_NumWorkGroups.x;
uint currentPoint = gl_WorkGroupID.x;
uint offset = (triangleCount - 1) / 2;
uint firstPointIndex = offset * 3 + 1;
o_Points[firstPointIndex + currentPoint * 3 ] = o_Points[offset + currentPoint] / 2 + vec2(0, 0.36);
o_Points[firstPointIndex + currentPoint * 3 + 1] = o_Points[offset + currentPoint] / 2 + vec2(-0.5, -0.5);
o_Points[firstPointIndex + currentPoint * 3 + 2] = o_Points[offset + currentPoint] / 2 + vec2(0.5, -0.5);
}