-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStandardShadingRTT.vertexshader
58 lines (44 loc) · 2.33 KB
/
StandardShadingRTT.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
#version 330 core
// Input vertex data, different for all executions of this shader.
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec2 vertexUV;
layout(location = 2) in vec3 vertexNormal_modelspace;
// Output data ; will be interpolated for each fragment.
out vec2 UV;
out vec3 Position_worldspace;
out vec3 Normal_cameraspace;
out vec3 EyeDirection_cameraspace;
out vec3 LightDirection1_cameraspace;
out vec3 LightDirection2_cameraspace;
out vec3 LightDirection3_cameraspace;
out vec3 LightDirection4_cameraspace;
// Values that stay constant for the whole mesh.
uniform mat4 MVP;
uniform mat4 V;
uniform mat4 M;
uniform vec3 LightPosition1_worldspace;
uniform vec3 LightPosition2_worldspace;
uniform vec3 LightPosition3_worldspace;
uniform vec3 LightPosition4_worldspace;
void main(){
// Output position of the vertex, in clip space : MVP * position
gl_Position = MVP * 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).
EyeDirection_cameraspace = vec3(0, 0, 0) - (V * M * vec4(vertexPosition_modelspace, 1)).xyz;
// Vector that goes from the vertex to the light, in camera space
vec3 LightPosition1_cameraspace = (V * vec4(LightPosition1_worldspace, 1)).xyz;
LightDirection1_cameraspace = LightPosition1_cameraspace + EyeDirection_cameraspace;
vec3 LightPosition2_cameraspace = (V * vec4(LightPosition2_worldspace,1)).xyz;
LightDirection2_cameraspace = LightPosition2_cameraspace + EyeDirection_cameraspace;
vec3 LightPosition3_cameraspace = (V * vec4(LightPosition3_worldspace,1)).xyz;
LightDirection3_cameraspace = LightPosition3_cameraspace + EyeDirection_cameraspace;
vec3 LightPosition4_cameraspace = (V * vec4(LightPosition4_worldspace,1)).xyz;
LightDirection4_cameraspace = LightPosition4_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;
}