-
Notifications
You must be signed in to change notification settings - Fork 2
/
StandardShading.vertexshader
72 lines (51 loc) · 2.34 KB
/
StandardShading.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
#version 120
// Input vertex data, different for all executions of this shader.
attribute vec3 vertexPosition_modelspace;
attribute vec2 vertexUV;
attribute vec3 vertexNormal_modelspace;
// Output data ; will be interpolated for each fragment.
varying vec2 UV;
varying vec3 Position_worldspace;
varying vec3 Normal_cameraspace;
varying vec3 EyeDirection_cameraspace;
varying vec3 LightDirection_cameraspace;
// Values that stay constant for the whole mesh.
uniform mat4 MVP;
uniform mat4 V;
uniform mat4 M;
uniform vec3 LightPosition_worldspace;
// Shadow mapping
uniform mat4 DepthVP;
uniform mat4 BiasMatrix;
varying vec4 ShadowCoord;
// World (Environment) light _ color bleeding
varying vec3 Normal;
varying vec3 Position;
uniform mat4 Minv;
void main(){
mat4 DepthMVP = DepthVP * M;
mat4 depthBiasMVP = BiasMatrix*DepthMVP;
// Output position of the vertex, in clip space : MVP * position
gl_Position = MVP * vec4(vertexPosition_modelspace,1);
//edits to render to PP_framebuffer
//gl_Position = vec4(gl_Position.x, gl_Position.y, 0, 1);
//gl_Position.x = - gl_Position.x; hahah :D
// environment light
Normal = mat3(transpose(Minv)) * vertexNormal_modelspace;
Position = vec3(M * vec4(vertexPosition_modelspace, 1.0f));
// Same, but with the light's view matrix
ShadowCoord = depthBiasMVP * 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;
}