generated from Persson-dev/OpenGLComputeShader
50 lines
1.3 KiB
GLSL
50 lines
1.3 KiB
GLSL
#version 460 core
|
|
|
|
layout(std430, binding = 3) buffer layoutName {
|
|
float o_Points[];
|
|
};
|
|
|
|
layout(local_size_x = 64) in;
|
|
|
|
highp float rand(vec2 co)
|
|
{
|
|
highp float a = 12.9898;
|
|
highp float b = 78.233;
|
|
highp float c = 43758.5453;
|
|
highp float dt= dot(co.xy ,vec2(a,b));
|
|
highp float sn= mod(dt,3.14);
|
|
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 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 = mat4(0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0.36, 0, 1);
|
|
break;
|
|
|
|
case 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 = mat4(0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0.5, -0.5, 0, 1);
|
|
break;
|
|
}
|
|
vec3 result = (transformation * vec4(currentPoint, 1.0)).xyz;
|
|
store(result, currentIndex);
|
|
} |