offset_color_vertex.glsl 1.21 KB
Newer Older
Karol Actun's avatar
Karol Actun committed
1
2
// vertex shader for the OffsetColorProgram

3
#version 150
Karol Actun's avatar
Karol Actun committed
4
5
6

// VBO 0 - per vertex
// vector of a face
7
attribute vec3 position;
Karol Actun's avatar
Karol Actun committed
8
// normal vector of the vector/face
9
attribute vec3 normal;
Karol Actun's avatar
Karol Actun committed
10
11
12

// VBO 1 - per instance
// position offset of the model
13
attribute vec3 offset;
Karol Actun's avatar
Karol Actun committed
14
// color of the model
15
attribute vec4 color;
Karol Actun's avatar
Karol Actun committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

// uniforms
// projection matrix
uniform mat4 projection;
// view matrix
uniform mat4 view;
// world matrix
uniform mat4 world;
// scaling of the position
uniform vec3 world_scaling;
// scaling of the size
uniform vec3 model_scaling;
// min value of brightness
uniform float ambient_light;
// direction of the parallel lightsource
uniform vec3 light_direction;
// color of the parallel lightsource
uniform vec4 light_color;

// varying color for fragment shader
36
varying vec4 v_color;
Karol Actun's avatar
Karol Actun committed
37
38
39
40
41
42
43
44
45
46
47
48
49


void main(void)
{
    vec3 nn = normalize(normal);
    vec3 diffuseReflection = vec3(light_color) * vec3(color)
                             * max(max(ambient_light, dot(nn, light_direction)), dot(-nn, light_direction));
    v_color = vec4(diffuseReflection, color[3]);

    mat4 use_world = world;
    use_world[3] += vec4(offset * world_scaling, 0);
    gl_Position = projection  * view * use_world * vec4(position * model_scaling, 1.0);
}