1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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);
}
|