-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStandardShading.vertexshader
More file actions
executable file
·47 lines (37 loc) · 1.88 KB
/
StandardShading.vertexshader
File metadata and controls
executable file
·47 lines (37 loc) · 1.88 KB
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
#version 330 core
// Input vertex data, different for all executions of this shader.
layout(location = 0) in vec4 vertexPosition_modelspace;
layout(location = 1) in vec4 vertexColor;
// Output data ; will be interpolated for each fragment.
out vec4 vs_vertexColor;
out vec3 Position_worldspace;
out vec3 Normal_cameraspace;
out vec3 EyeDirection_cameraspace;
out vec3 LightDirection_cameraspace;
out vec3 LightDirection_cameraspace2;
// Values that stay constant for the whole mesh.
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform vec3 LightPosition_worldspace;
uniform vec3 LightPosition_worldspace2;
void main(){
gl_PointSize = 5.0;
// Output position of the vertex, in clip space : MVP * position
gl_Position = P * V * M * vertexPosition_modelspace;
// Position of the vertex, in worldspace : M * position
Position_worldspace = (M * vertexPosition_modelspace).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 * vertexPosition_modelspace).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;
vec3 LightPosition_cameraspace2 = ( V * vec4(LightPosition_worldspace2,1)).xyz;
LightDirection_cameraspace = LightPosition_cameraspace + EyeDirection_cameraspace;
LightDirection_cameraspace2 = LightPosition_cameraspace2 + EyeDirection_cameraspace;
// Normal of the the vertex, in camera space
Normal_cameraspace = ( V * M * vec4(1.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.
vs_vertexColor = vertexColor;
}