-
Notifications
You must be signed in to change notification settings - Fork 0
/
TransformVertexShader.vertexshader
37 lines (29 loc) · 1.15 KB
/
TransformVertexShader.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
#version 330 core
// Input vertex data - different for all executions of this shader.
layout(location = 0) in vec3 vertex_position_modelspace;
layout(location = 1) in vec4 vertex_colour;
layout(location = 2) in vec2 vertex_UV;
layout(location = 3) in vec3 vertex_normal;
layout(location = 4) in vec3 vertex_tangent;
layout(location = 5) in vec3 vertex_bitangent;
// Output data - will be interpolated for each fragment.
out vec4 fragment_colour;
out vec2 UV;
out vec3 light_direction_tangent_space;
out vec3 light_direction;
out vec3 surface_normal;
uniform mat4 WORLD_VIEW_PROJECTION;
uniform mat4 MODEL;
uniform vec3 LIGHT_POSITION;
void main()
{
// Output position of the vertex, in clip space : MODEL * WORLD_VIEW_PROJECTION * position
gl_Position = WORLD_VIEW_PROJECTION * MODEL * vec4(vertex_position_modelspace, 1);
// The colour of each vertex will be interpolated
// to produce the colour of each fragment
fragment_colour = vertex_colour;
UV = vertex_UV;
light_direction = normalize(vec4(LIGHT_POSITION, 1) - MODEL * vec4(vertex_position_modelspace, 1)).xyz;
surface_normal = vertex_normal;
light_direction_tangent_space = light_direction;
}