generated from Persson-dev/OpenGLComputeShader
matrix values cpu side
This commit is contained in:
@@ -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);
|
||||
}
|
||||
25
src/Main.cpp
25
src/Main.cpp
@@ -140,6 +140,31 @@ int main() {
|
||||
|
||||
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)) {
|
||||
// ScopedTimer timer("Main Loop");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user