generated from Persson-dev/OpenGLComputeShader
now in 3D
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#version 460 core
|
||||
|
||||
layout(std430, binding = 3) buffer layoutName {
|
||||
vec2 o_Points[];
|
||||
float o_Points[];
|
||||
};
|
||||
|
||||
layout(local_size_x = 64) in;
|
||||
@@ -16,23 +16,35 @@ highp float rand(vec2 co)
|
||||
return fract(sin(sn) * c);
|
||||
}
|
||||
|
||||
vec3 unpack(uint index) {
|
||||
return vec3(o_Points[index * 3], o_Points[index * 3 + 1], o_Points[index * 3 + 2]);
|
||||
}
|
||||
|
||||
void store(vec3 vect, uint index) {
|
||||
o_Points[index * 3] = vect.x;
|
||||
o_Points[index * 3 + 1] = vect.y;
|
||||
o_Points[index * 3 + 2] = vect.z;
|
||||
}
|
||||
|
||||
void main() {
|
||||
const uint total = gl_NumWorkGroups.x * gl_WorkGroupSize.x;
|
||||
uint currentPoint = gl_GlobalInvocationID.x;
|
||||
uint index = uint(rand(o_Points[currentPoint] + currentPoint) * 69);
|
||||
mat3 transformation;
|
||||
uint currentIndex = gl_GlobalInvocationID.x;
|
||||
vec3 currentPoint = unpack(currentIndex);
|
||||
uint index = uint(rand(currentPoint.xy + currentPoint.z + currentIndex) * 69);
|
||||
mat4 transformation;
|
||||
switch (index % 3) {
|
||||
case 0:
|
||||
transformation = mat3(0.5, 0, 0, 0, 0.5, 0, 0, 0.36, 1);
|
||||
transformation = mat4(0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0.36, 0, 1);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
transformation = mat3(0.5, 0, 0, 0, 0.5, 0, -0.5, -0.5, 1);
|
||||
transformation = mat4(0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, -0.5, -0.5, 0, 1);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
transformation = mat3(0.5, 0, 0, 0, 0.5, 0, 0.5, -0.5, 1);
|
||||
transformation = mat4(0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0.5, -0.5, 0, 1);
|
||||
break;
|
||||
}
|
||||
o_Points[currentPoint] = (transformation * vec3(o_Points[currentPoint], 1.0)).xy;
|
||||
vec3 result = (transformation * vec4(currentPoint, 1.0)).xyz;
|
||||
store(result, currentIndex);
|
||||
}
|
||||
@@ -2,10 +2,14 @@
|
||||
|
||||
layout(std430, binding = 3) buffer layoutName
|
||||
{
|
||||
vec2 data_SSBO[];
|
||||
float data_SSBO[];
|
||||
};
|
||||
|
||||
vec3 unpack(uint index) {
|
||||
return vec3(data_SSBO[index * 3], data_SSBO[index * 3 + 1], data_SSBO[index * 3 + 2]);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(data_SSBO[gl_InstanceID], 0.0, 1.0);
|
||||
gl_Position = vec4(unpack(gl_InstanceID), 1.0);
|
||||
}
|
||||
Reference in New Issue
Block a user