-
Notifications
You must be signed in to change notification settings - Fork 4
/
4.main.vs
84 lines (66 loc) · 2.17 KB
/
4.main.vs
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
38
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#version 440 core
// 4.main.vs
//---------------------------------------------------------------
// uniform from the code
//---------------------------------------------------------------
uniform mat4 uObject;
uniform mat4 uModel;
uniform mat4 uView;
uniform mat4 uProjection;
// camera pos [world]
uniform vec3 uCameraPos;
uniform bool uFigureHighlight;
uniform bool uFigureScreenCoord;
uniform mat4 uScreenProjection;
uniform mat4 uScreenModel;
//---------------------------------------------------------------
// vertex buffer components
//---------------------------------------------------------------
// vertex position [object]
layout(location = 0) in vec3 vPos;
// vertex normal [object]
layout(location = 1) in vec3 vNormal;
// vertex color [rgba]
layout(location = 2) in vec4 vMatColor;
// vertex material [ads]
layout(location = 3) in vec3 vMatProp;
// vertex texcoord
layout(location = 4) in vec2 vTexCoord;
//---------------------------------------------------------------
// variables to next stage
//---------------------------------------------------------------
out VertexData
{
// vertex pos [object]
vec3 oPos;
// vertex normal [object]
vec3 oNormal;
// fragment pos [world]
vec3 pos;
vec3 normal;
vec4 matColor;
vec3 matProp;
vec2 texCoord;
// camera pos [world]
vec3 cameraPos;
}
vs_out;
//---------------------------------------------------------------
// BODY
//---------------------------------------------------------------
void main()
{
// set gl_Position ( clip space pos )
if (uFigureScreenCoord)
gl_Position = uScreenProjection * uScreenModel * uObject * vec4(vPos, 1.0);
else
gl_Position = uProjection * uView * uModel * uObject * vec4(vPos, 1.0);
vs_out.oPos = vPos;
vs_out.oNormal = vNormal;
vs_out.pos = vec3(uModel * uObject * vec4(vPos, 1.0));
vs_out.normal = vec3(uModel * uObject * vec4(vNormal, 1.0)) - vec3(uModel * uObject * vec4(0, 0, 0, 1));
vs_out.matColor = vMatColor;
vs_out.matProp = vMatProp;
vs_out.texCoord = vTexCoord;
vs_out.cameraPos = uCameraPos;
}