matrix values cpu side

This commit is contained in:
2025-11-09 12:13:08 +01:00
parent 6a874a01bb
commit 1be8e337a3
2 changed files with 31 additions and 14 deletions

View File

@@ -4,6 +4,10 @@ layout(std430, binding = 3) buffer layoutName {
float o_Points[]; float o_Points[];
}; };
const uint transformationCount = 3;
layout(location = 1) uniform mat4 transformations[transformationCount];
layout(local_size_x = 64) in; layout(local_size_x = 64) in;
highp float rand(vec2 co) highp float rand(vec2 co)
@@ -27,24 +31,12 @@ void store(vec3 vect, uint index) {
} }
void main() { void main() {
const uint total = gl_NumWorkGroups.x * gl_WorkGroupSize.x;
uint currentIndex = gl_GlobalInvocationID.x; uint currentIndex = gl_GlobalInvocationID.x;
vec3 currentPoint = unpack(currentIndex); vec3 currentPoint = unpack(currentIndex);
uint index = uint(rand(currentPoint.xy + currentPoint.z + currentIndex) * 69); uint index = uint(rand(currentPoint.xy + currentPoint.z + currentIndex) * 69);
mat4 transformation; mat4 transformation = transformations[index % transformationCount];
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; vec3 result = (transformation * vec4(currentPoint, 1.0)).xyz;
store(result, currentIndex); store(result, currentIndex);
} }

View File

@@ -140,6 +140,31 @@ int main() {
glBindVertexArray(vertexArray); glBindVertexArray(vertexArray);
std::vector<glm::mat4> transformations = {
{
0.5f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f, 0.36f,
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f,
},
{
0.5f, 0.0f, 0.0f, -0.5f,
0.0f, 0.5f, 0.0f, -0.5f,
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f,
},
{
0.5f, 0.0f, 0.0f, 0.5f,
0.0f, 0.5f, 0.0f, -0.5f,
0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f,
},
};
glUseProgram(s_ComputeShader);
glUniformMatrix4fv(1, transformations.size(), true, glm::value_ptr(transformations[0]));
while (!glfwWindowShouldClose(window)) { while (!glfwWindowShouldClose(window)) {
// ScopedTimer timer("Main Loop"); // ScopedTimer timer("Main Loop");