Files
RealTimeFractal/Shaders/Compute.glsl
Persson-dev 926bf694c0 fractal (#1)
Reviewed-on: #1
Co-authored-by: Persson-dev <sim16.prib@gmail.com>
Co-committed-by: Persson-dev <sim16.prib@gmail.com>
2025-11-09 15:41:00 +00:00

42 lines
1.0 KiB
GLSL

#version 460 core
layout(std430, binding = 3) buffer layoutName {
float o_Points[];
};
const uint transformationCount = 3;
layout(location = 1) uniform mat4 transformations[transformationCount];
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() {
uint currentIndex = gl_GlobalInvocationID.x;
vec3 currentPoint = unpack(currentIndex);
uint index = uint(rand(currentPoint.xy + currentPoint.z + currentIndex) * 69);
mat4 transformation = transformations[index % transformationCount];
vec3 result = (transformation * vec4(currentPoint, 1.0)).xyz;
store(result, currentIndex);
}