generated from Persson-dev/OpenGLComputeShader
working project
This commit is contained in:
@@ -2,31 +2,40 @@
|
||||
|
||||
layout(rgba32f, binding = 0) uniform writeonly image2D outputImage;
|
||||
|
||||
layout(local_size_x = 16, local_size_y = 16) in;
|
||||
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()
|
||||
{
|
||||
ivec2 pixelCoord = ivec2(gl_GlobalInvocationID.xy);
|
||||
uint triangleCount = gl_NumWorkGroups.x;
|
||||
uint currentPoint = gl_WorkGroupID.x;
|
||||
|
||||
if (pixelCoord.x >= imageSize(outputImage).x || pixelCoord.y >= imageSize(outputImage).y)
|
||||
return;
|
||||
uint offset = (triangleCount - 1) / 2;
|
||||
|
||||
ivec2 texSize = imageSize(outputImage);
|
||||
vec2 fTexSize = vec2(texSize);
|
||||
vec2 normalizedCoord = vec2(pixelCoord) / vec2(texSize);
|
||||
|
||||
vec4 O = vec4(0, 0, 0, 1);
|
||||
vec2 I = vec2(pixelCoord);
|
||||
|
||||
float iTime = 2.2;
|
||||
float i = 0.0, t=iTime;
|
||||
O *= i;
|
||||
for(vec2 a=fTexSize.xy, p=(I+I-a)/a.y; i++<20.;
|
||||
O += (cos(sin(i*.2+t)*vec4(0,4,3,1))+2.)
|
||||
/(i/1e3+abs(length(a-.5*min(a+a.yx,.1))-.05)))
|
||||
a.x = abs(a = (fract(.2*t+.3*p*i*mat2(cos(cos(.2*t+.2*i)+vec4(0,11,33,0))))-.5)).x;
|
||||
|
||||
O = tanh(O*O/2e5);
|
||||
|
||||
vec4 color = vec4(normalizedCoord, 0.0, 1.0);
|
||||
imageStore(outputImage, pixelCoord, O);
|
||||
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);
|
||||
}
|
||||
8
Shaders/Fragment.glsl
Normal file
8
Shaders/Fragment.glsl
Normal file
@@ -0,0 +1,8 @@
|
||||
#version 460 core
|
||||
|
||||
layout (location = 0) out vec4 o_Color;
|
||||
|
||||
void main()
|
||||
{
|
||||
o_Color = vec4(1, 1, 1, 1);
|
||||
}
|
||||
15
Shaders/Vertex.glsl
Normal file
15
Shaders/Vertex.glsl
Normal file
@@ -0,0 +1,15 @@
|
||||
#version 460 core
|
||||
|
||||
layout(location = 0) in vec2 a_Position;
|
||||
|
||||
layout(std430, binding = 3) buffer layoutName
|
||||
{
|
||||
vec2 data_SSBO[];
|
||||
};
|
||||
|
||||
out vec2 v_TexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(data_SSBO[gl_InstanceID], 0.0, 1.0);
|
||||
}
|
||||
Reference in New Issue
Block a user