-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModel.vertexshader
executable file
·82 lines (68 loc) · 2.98 KB
/
Model.vertexshader
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
76
77
78
79
80
81
82
#version 330 core
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec2 vertexUV;
layout(location = 2) in vec3 vertexNormal_modelspace;
layout(location = 4) in float weight_00;
layout(location = 5) in float weight_01;
layout(location = 6) in float weight_02;
layout(location = 7) in float weight_03;
layout(location = 8) in float weight_04;
layout(location = 9) in float weight_05;
layout(location = 10) in float weight_06;
layout(location = 11) in float weight_07;
layout(location = 12) in float weight_08;
layout(location = 13) in float weight_09;
layout(location = 14) in float weight_10;
layout(location = 15) in float weight_11;
out vec2 UV;
out vec3 Position_worldspace;
out vec3 Normal_cameraspace;
out vec3 EyeDirection_cameraspace;
out vec3 LightDirection_cameraspace;
uniform mat4 MVP;
uniform mat4 V;
uniform mat4 M;
uniform vec3 LightPosition_worldspace;
uniform mat4 BoneMatrix[12];
mat4 Weighted_Matrix[12];
mat4 Synthetic_Matrix;
void main(){
Weighted_Matrix[0] = BoneMatrix[0] * weight_00;
Weighted_Matrix[1] = BoneMatrix[1] * weight_01;
Weighted_Matrix[2] = BoneMatrix[2] * weight_02;
Weighted_Matrix[3] = BoneMatrix[3] * weight_03;
Weighted_Matrix[4] = BoneMatrix[4] * weight_04;
Weighted_Matrix[5] = BoneMatrix[5] * weight_05;
Weighted_Matrix[6] = BoneMatrix[6] * weight_06;
Weighted_Matrix[7] = BoneMatrix[7] * weight_07;
Weighted_Matrix[8] = BoneMatrix[8] * weight_08;
Weighted_Matrix[9] = BoneMatrix[9] * weight_09;
Weighted_Matrix[10] = BoneMatrix[10] * weight_10;
Weighted_Matrix[11] = BoneMatrix[11] * weight_11;
Synthetic_Matrix = Weighted_Matrix[0]
+ Weighted_Matrix[1]
+ Weighted_Matrix[2]
+ Weighted_Matrix[3]
+ Weighted_Matrix[4]
+ Weighted_Matrix[5]
+ Weighted_Matrix[6]
+ Weighted_Matrix[7]
+ Weighted_Matrix[8]
+ Weighted_Matrix[9]
+ Weighted_Matrix[10]
+ Weighted_Matrix[11];
gl_Position = MVP * Synthetic_Matrix * vec4(vertexPosition_modelspace,1);
// Position of the vertex, in worldspace : M * position
Position_worldspace = (M * vec4(vertexPosition_modelspace,1)).xyz;
// Vector that goes from the vertex to the camera, in camera space.
// In camera space, the camera is at the origin (0,0,0).
vec3 vertexPosition_cameraspace = ( V * M * vec4(vertexPosition_modelspace,1)).xyz;
EyeDirection_cameraspace = vec3(0,0,0) - vertexPosition_cameraspace;
// Vector that goes from the vertex to the light, in camera space. M is ommited because it's identity.
vec3 LightPosition_cameraspace = ( V * vec4(LightPosition_worldspace,1)).xyz;
LightDirection_cameraspace = LightPosition_cameraspace + EyeDirection_cameraspace;
// Normal of the the vertex, in camera space
Normal_cameraspace = ( V * M * vec4(vertexNormal_modelspace,0)).xyz; // Only correct if ModelMatrix does not scale the model ! Use its inverse transpose if not.
// UV of the vertex. No special space for this one.
UV = vertexUV;
}