aboutsummaryrefslogtreecommitdiff
path: root/shaders/cook_torrance.vert
diff options
context:
space:
mode:
Diffstat (limited to 'shaders/cook_torrance.vert')
-rw-r--r--shaders/cook_torrance.vert75
1 files changed, 75 insertions, 0 deletions
diff --git a/shaders/cook_torrance.vert b/shaders/cook_torrance.vert
new file mode 100644
index 0000000..5f126c0
--- /dev/null
+++ b/shaders/cook_torrance.vert
@@ -0,0 +1,75 @@
1precision highp float;
2
3uniform mat4 ModelMatrix;
4// uniform mat4 Modelview;
5uniform mat4 View;
6uniform mat4 Projection;
7//uniform mat4 MVP;
8#ifdef HAS_JOINTS
9// The client should pass in an appropriate value for MAX_JOINTS.
10// #define MAX_JOINTS 96
11//
12// matnxm -- n columns and m rows, different convention from math.
13// We don't need the last row of [0, 0, 0, 1], so drop it to pack the matrices
14// as tightly as possible.
15// 256 joints * 4x4 matrix * 4 bytes/float = 16.0KB
16// 256 joints * 4x3 matrix * 4 bytes/float = 12.0KB
17// 96 joints * 4x4 matrix * 4 bytes/float = 6.0KB
18// 96 joints * 4x3 matrix * 4 bytes/float = 4.5KB
19//uniform mat4x3 Joints[MAX_JOINTS];
20uniform mat4 JointMatrices[MAX_JOINTS]; // Use 4x4 for now to keep it simple.
21#endif
22
23layout (location = 0) in vec3 vPosition;
24#ifdef HAS_NORMALS
25layout (location = 1) in vec3 vNormal;
26#endif
27#ifdef HAS_TANGENTS
28layout (location = 2) in vec4 vTangent;
29#endif
30#ifdef HAS_TEXCOORDS
31layout (location = 3) in vec2 vTexcoord;
32#endif
33#ifdef HAS_JOINTS
34layout (location = 4) in uvec4 vJoint;
35layout (location = 5) in vec4 vWeight;
36#endif
37
38// World-space position, normal and tangent.
39out vec3 Position;
40#ifdef HAS_NORMALS
41out vec3 Normal;
42#endif
43#ifdef HAS_TANGENTS
44out vec4 Tangent;
45#endif
46#ifdef HAS_TEXCOORDS
47out vec2 Texcoord;
48#endif
49
50void main()
51{
52#ifdef HAS_JOINTS
53 mat4 skinMatrix =
54 vWeight.x * JointMatrices[vJoint.x] +
55 vWeight.y * JointMatrices[vJoint.y] +
56 vWeight.z * JointMatrices[vJoint.z] +
57 vWeight.w * JointMatrices[vJoint.w];
58 Position = vec3(ModelMatrix * skinMatrix * vec4(vPosition, 1.0));
59#else
60 Position = vec3(ModelMatrix * vec4(vPosition, 1.0));
61#endif
62#ifdef HAS_NORMALS
63 Normal = mat3(ModelMatrix) * vNormal;
64 //Normal = normalize(ModelMatrix * vec4(vNormal, 0.0)).xyz;
65#endif
66#ifdef HAS_TANGENTS
67 Tangent = vec4(mat3(ModelMatrix) * vTangent.xyz, vTangent.w);
68#endif
69#ifdef HAS_TEXCOORDS
70 Texcoord = vTexcoord;
71#endif
72 gl_Position = Projection * View * vec4(Position, 1.0);
73 //gl_Position = Projection * vec4(Position, 1.0);
74 //gl_Position = MVP * vec4(vPosition, 1.0);
75}