diff options
author | 3gg <3gg@shellblade.net> | 2025-06-27 10:18:39 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2025-06-27 10:18:39 -0700 |
commit | bd57f345ed9dbed1d81683e48199626de2ea9044 (patch) | |
tree | 4221f2f2a7ad2244d2e93052bd68187ec91b8ea9 /shaders/cook_torrance.vert | |
parent | 9a82ce0083437a4f9f58108b2c23b957d2249ad8 (diff) |
Diffstat (limited to 'shaders/cook_torrance.vert')
-rw-r--r-- | shaders/cook_torrance.vert | 75 |
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 @@ | |||
1 | precision highp float; | ||
2 | |||
3 | uniform mat4 ModelMatrix; | ||
4 | // uniform mat4 Modelview; | ||
5 | uniform mat4 View; | ||
6 | uniform 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]; | ||
20 | uniform mat4 JointMatrices[MAX_JOINTS]; // Use 4x4 for now to keep it simple. | ||
21 | #endif | ||
22 | |||
23 | layout (location = 0) in vec3 vPosition; | ||
24 | #ifdef HAS_NORMALS | ||
25 | layout (location = 1) in vec3 vNormal; | ||
26 | #endif | ||
27 | #ifdef HAS_TANGENTS | ||
28 | layout (location = 2) in vec4 vTangent; | ||
29 | #endif | ||
30 | #ifdef HAS_TEXCOORDS | ||
31 | layout (location = 3) in vec2 vTexcoord; | ||
32 | #endif | ||
33 | #ifdef HAS_JOINTS | ||
34 | layout (location = 4) in uvec4 vJoint; | ||
35 | layout (location = 5) in vec4 vWeight; | ||
36 | #endif | ||
37 | |||
38 | // World-space position, normal and tangent. | ||
39 | out vec3 Position; | ||
40 | #ifdef HAS_NORMALS | ||
41 | out vec3 Normal; | ||
42 | #endif | ||
43 | #ifdef HAS_TANGENTS | ||
44 | out vec4 Tangent; | ||
45 | #endif | ||
46 | #ifdef HAS_TEXCOORDS | ||
47 | out vec2 Texcoord; | ||
48 | #endif | ||
49 | |||
50 | void 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 | } | ||