File: light-basic.vert

package info (click to toggle)
vkmark 2025.01-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,500 kB
  • sloc: cpp: 28,949; ansic: 39; python: 20; makefile: 3
file content (31 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download
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
#version 420 core

layout(std140, binding = 0) uniform block {
    uniform mat4 ModelViewProjectionMatrix;
    uniform mat4 NormalMatrix;
    uniform vec4 MaterialDiffuse;
};

layout(location = 0) in vec3 in_position;
layout(location = 1) in vec3 in_normal;

layout(location = 0) out vec4 out_color;

vec4 LightSourcePosition = vec4(20.0, -20.0, 10.0, 1.0);

void main(void)
{
    // Transform the normal to eye coordinates
    vec3 N = normalize(vec3(NormalMatrix * vec4(in_normal, 1.0)));

    // The LightSourcePosition is actually its direction for directional light
    vec3 L = normalize(LightSourcePosition.xyz);

    // Multiply the diffuse value by the vertex color (which is fixed in this case)
    // to get the actual color that we will use to draw this vertex with
    float diffuse = max(dot(N, L), 0.0);
    out_color = vec4(diffuse * MaterialDiffuse.rgb, MaterialDiffuse.a);

    // Transform the position to clip coordinates
    gl_Position = ModelViewProjectionMatrix * vec4(in_position, 1.0);
}