From 1be8e337a371068931633b26e327bc7a43271eed Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Sun, 9 Nov 2025 12:13:08 +0100 Subject: [PATCH] matrix values cpu side --- Shaders/Compute.glsl | 20 ++++++-------------- src/Main.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/Shaders/Compute.glsl b/Shaders/Compute.glsl index cfa3368..0052231 100644 --- a/Shaders/Compute.glsl +++ b/Shaders/Compute.glsl @@ -4,6 +4,10 @@ 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) @@ -27,24 +31,12 @@ void store(vec3 vect, uint index) { } 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; + mat4 transformation = transformations[index % transformationCount]; - 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); } \ No newline at end of file diff --git a/src/Main.cpp b/src/Main.cpp index 6488118..b317f02 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -140,6 +140,31 @@ int main() { glBindVertexArray(vertexArray); + std::vector 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)) { // ScopedTimer timer("Main Loop");