aboutsummaryrefslogtreecommitdiff
path: root/resources/pull.vert
diff options
context:
space:
mode:
Diffstat (limited to 'resources/pull.vert')
-rw-r--r--resources/pull.vert65
1 files changed, 65 insertions, 0 deletions
diff --git a/resources/pull.vert b/resources/pull.vert
new file mode 100644
index 0000000..fb6ab8b
--- /dev/null
+++ b/resources/pull.vert
@@ -0,0 +1,65 @@
+#version 460 core
+
+// Our SSBO added in step 4
+layout(std430, binding = 0) restrict readonly buffer vertexPullBuffer
+{
+ uint packedMeshData[]; // Contains packed data for our vertices
+};
+
+in uint _meshdat;
+out vec2 UV;
+out vec3 FragmentPos;
+out vec3 Normal;
+
+uniform mat4 MVP;
+uniform mat4 modelPosition;
+
+
+// Offsets for our vertices drawing this face
+const vec3 facePositions[4] = vec3[4]
+(
+ vec3(0.0f, 0.0f, 1.0f),
+ vec3(1.0f, 0.0f, 0.0f),
+ vec3(1.0f, 0.0f, 1.0f),
+ vec3(0.0f, 0.0f, 0.0f)
+
+ //vec3( 0.5f, 0.5f, 0.5f), // 10 up
+ //vec3( 0.5f, 0.5f, -0.5f),
+ //vec3(-0.5f, 0.5f, -0.5f),
+ //vec3(-0.5f, 0.5f, 0.5f)
+
+);
+
+// Winding order to access the face positions
+int indices[6] = {0, 1, 2, 1, 0, 3};
+
+vec3 unpack(int idx) {
+ const int i = idx / 6;
+ const uint packedData = packedMeshData[idx];
+ const int currVertexID = idx % 6;
+
+ // Unpack the data we retrieved
+ const uint x = (packedData) & uint(255);
+ const uint y = (packedData >> 8) & uint(255);
+ const uint z = (packedData >> 16) & uint(255);
+
+ // Apply the offsets for our face so we can form the 2 triangles
+ return vec3(x, y, z) + facePositions[indices[currVertexID]];
+}
+
+void main()
+{
+ // Create a custom index to access the mesh data in the right order
+ vec3 position = unpack(gl_VertexID);
+
+ // Output our position
+ gl_Position = vec4(position, 1.0);
+ FragmentPos = vec3(modelPosition * vec4(position,1));
+ UV = vec2(0,0.5);
+
+ //vec3 B = unpack(gl_VertexID + 1) - position;
+ //vec3 C = unpack(gl_VertexID + 2) - position;
+ //vec3 n = cross(C,B);
+ //Normal = normalize(n);
+ Normal = vec3(0,1,0);
+}