-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshaders.cpp
81 lines (70 loc) · 1.88 KB
/
shaders.cpp
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
const char* vsSource = R"(
#version 460 core
layout (location = 0) in vec3 quadVec;
layout (location = 1) in vec2 uv;
layout (location = 2) in vec3 position;
layout (location = 3) in vec3 axis;
layout (location = 4) in float sine;
layout (location = 5) in float cosine;
layout (location = 6) in vec3 location;
layout (location = 7) in float color;
out vec3 colour;
out vec2 texCoords;
out vec3 locFragment;
out vec4 pos;
uniform mat4 rotation;
uniform mat4 projection;
uniform vec3 sideToBeRotated = vec3(0, 0, 0);
uniform vec3 translation;
uniform mat4 sideRotation = mat4(1.0);
uniform vec3 colors[12] = {
vec3(0, 1, 0),
vec3(1, 1, 0),
vec3(1, 0, 0),
vec3(0, 0, 1),
vec3(1, 1, 1),
vec3(1, 0.5, 0),
vec3(0, 0.5, 0),
vec3(0.5, 0.5, 0),
vec3(0.5, 0, 0),
vec3(0, 0, 0.5),
vec3(0.5, 0.5, 0.5),
vec3(0.5, 0.25, 0),
};
mat4 sideRotations[3] = {
mat4(1),
mat4(1),
sideRotation
};
void main() {
vec3 p = axis * dot(quadVec, axis) / dot(axis, axis);
vec3 m = quadVec - p;
vec3 n = cross(axis, m) / length(axis);
vec3 r = (cosine * m) + (sine * n) + p;
int index = int(sign(dot(normalize(sideToBeRotated), normalize(position /*+ r*/)))) + 1;
vec4 v = (rotation * sideRotations[index] * vec4(position + r, 1)) + vec4(translation, 0);
gl_Position = projection * v;
colour = colors[int(color)];
texCoords = uv;
locFragment = location;
//pos = rotation * sideRotations[index] * vec4(position, 1);
pos = rotation * sideRotations[index] * vec4(position /*+ r*/, 1);
}
)"
;
const char* fsSource = R"(
#version 460 core
in vec3 colour;
in vec2 texCoords;
in vec3 locFragment;
in vec4 pos;
/*layout (location = 0)*/ out vec3 fragColor;
//layout (location = 1) out vec3 loc;
uniform sampler2D sampler;
void main() {
fragColor = texture(sampler, texCoords).xyz * /*dot(pos.xyz, vec3(0, 0, 1))**/colour;
//if (dot(pos.xyz, vec3(0, 0, 1)) < cos(60)) fragColor = vec3(0);
//loc = locFragment;
}
)"
;