offset_color_carry_vertex.glsl 1.56 KB
Newer Older
Karol Actun's avatar
Karol Actun committed
1
2
// vertex shader for the OffsetColorCarryProgram

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

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


// 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
38
varying vec4 v_color;
Karol Actun's avatar
Karol Actun committed
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


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));

    mat4 use_world = world;
    use_world[3] += vec4(offset * world_scaling, 0);
    float alpha = color[3];
    if(carried > 0.5){
        use_world[0][0] = 0.5;
        use_world[1][1] = 0.5;
        use_world[2][2] = 0.5;
        use_world[3][0] += 0.2;
        use_world[3][1] += 0.2;
        use_world[3][2] += 0.2;
        alpha = 0.8;
    }

    v_color = vec4(diffuseReflection, alpha);

    gl_Position = projection  * view * use_world * vec4(position * model_scaling, 1.0);
}