reve/src/renderer/shaders/blinn/vertex.glsl 1.7 KiB raw
1
#version 330 core
2
3
const uint InteractionModeObjects  = 0u;
4
const uint InteractionModeEdges    = 1u;
5
const uint InteractionModePoints   = 2u;
6
const uint InteractionModePolygons = 3u;
7
8
layout(location = 0) in vec3  position;
9
layout(location = 1) in vec4  color;
10
layout(location = 2) in vec3  normal;
11
layout(location = 3) in vec2  uv;
12
layout(location = 4) in float opacity;
13
layout(location = 5) in uint  polygon;
14
layout(location = 6) in float selected; // `0` or `1`.
15
16
smooth out vec3  vertViewDirWorld;
17
smooth out vec3  vertPosWorld;
18
smooth out vec4  vertColor;
19
smooth out float vertOpacity;
20
smooth out float vertExcludeEdge;
21
smooth out vec3  vertNormalSmooth;
22
flat   out vec3  vertNormalFlat;
23
flat   out int   vertID;
24
flat   out float vertSelected;
25
flat   out float vertHovered;
26
smooth out vec2  vertTextureCoord;
27
28
uniform vec3 light;
29
uniform mat4 model;
30
uniform mat4 view;
31
uniform mat4 proj;
32
uniform uint interactionMode;
33
uniform int  vertexHovered;
34
35
int getVertexID() {
36
	if (interactionMode == InteractionModePoints) {
37
		return gl_VertexID;
38
	}
39
	if (interactionMode == InteractionModePolygons) {
40
		return int(polygon);
41
	}
42
	return -1;
43
}
44
45
float isVertexHovered() {
46
	return vertexHovered == getVertexID() ? 1.0 : 0.0;
47
}
48
49
void main() {
50
	vec3 cameraPosWorld = vec3(inverse(view) * vec4(0.0, 0.0, 0.0, 1.0));
51
	vec3 normalWorld = normalize(mat3(model) * normal);
52
53
	vertPosWorld = vec3(model * vec4(position, 1));
54
	vertViewDirWorld = normalize(cameraPosWorld - vertPosWorld);
55
	vertNormalFlat = normalWorld;
56
	vertNormalSmooth = normalWorld;
57
	vertColor = color;
58
	vertOpacity = opacity;
59
	vertTextureCoord = uv;
60
	vertExcludeEdge = 0.0;
61
	vertID = getVertexID();
62
	vertSelected = selected;
63
	vertHovered = isVertexHovered();
64
65
	gl_Position = proj * view * model * vec4(position, 1);
66
}