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
66
67
68
69
70
71
72
73
74
75
|
precision highp float;
uniform mat4 ModelMatrix;
// uniform mat4 Modelview;
uniform mat4 View;
uniform mat4 Projection;
//uniform mat4 MVP;
#ifdef HAS_JOINTS
// The client should pass in an appropriate value for MAX_JOINTS.
// #define MAX_JOINTS 96
//
// matnxm -- n columns and m rows, different convention from math.
// We don't need the last row of [0, 0, 0, 1], so drop it to pack the matrices
// as tightly as possible.
// 256 joints * 4x4 matrix * 4 bytes/float = 16.0KB
// 256 joints * 4x3 matrix * 4 bytes/float = 12.0KB
// 96 joints * 4x4 matrix * 4 bytes/float = 6.0KB
// 96 joints * 4x3 matrix * 4 bytes/float = 4.5KB
//uniform mat4x3 Joints[MAX_JOINTS];
uniform mat4 JointMatrices[MAX_JOINTS]; // Use 4x4 for now to keep it simple.
#endif
layout (location = 0) in vec3 vPosition;
#ifdef HAS_NORMALS
layout (location = 1) in vec3 vNormal;
#endif
#ifdef HAS_TANGENTS
layout (location = 2) in vec4 vTangent;
#endif
#ifdef HAS_TEXCOORDS
layout (location = 3) in vec2 vTexcoord;
#endif
#ifdef HAS_JOINTS
layout (location = 4) in uvec4 vJoint;
layout (location = 5) in vec4 vWeight;
#endif
// World-space position, normal and tangent.
out vec3 Position;
#ifdef HAS_NORMALS
out vec3 Normal;
#endif
#ifdef HAS_TANGENTS
out vec4 Tangent;
#endif
#ifdef HAS_TEXCOORDS
out vec2 Texcoord;
#endif
void main()
{
#ifdef HAS_JOINTS
mat4 skinMatrix =
vWeight.x * JointMatrices[vJoint.x] +
vWeight.y * JointMatrices[vJoint.y] +
vWeight.z * JointMatrices[vJoint.z] +
vWeight.w * JointMatrices[vJoint.w];
Position = vec3(ModelMatrix * skinMatrix * vec4(vPosition, 1.0));
#else
Position = vec3(ModelMatrix * vec4(vPosition, 1.0));
#endif
#ifdef HAS_NORMALS
Normal = mat3(ModelMatrix) * vNormal;
//Normal = normalize(ModelMatrix * vec4(vNormal, 0.0)).xyz;
#endif
#ifdef HAS_TANGENTS
Tangent = vec4(mat3(ModelMatrix) * vTangent.xyz, vTangent.w);
#endif
#ifdef HAS_TEXCOORDS
Texcoord = vTexcoord;
#endif
gl_Position = Projection * View * vec4(Position, 1.0);
//gl_Position = Projection * vec4(Position, 1.0);
//gl_Position = MVP * vec4(vPosition, 1.0);
}
|