-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaogl.vert
63 lines (52 loc) · 1.48 KB
/
aogl.vert
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
#version 430 core
#define POSITION 0
#define NORMAL 1
#define TEXCOORD 2
#define FRAG_COLOR 0
precision highp float;
precision highp int;
uniform mat4 MVP;
uniform mat4 MV;
uniform float Time;
uniform int InstanceCount;
const float PI = 3.14159265359;
const float TWOPI = 6.28318530718;
const float PI_2 = 1.57079632679;
const float SQUARE_SIZE = 10.0;
//layout(std140, column_major) uniform;
layout(location = POSITION) in vec3 Position;
layout(location = NORMAL) in vec3 Normal;
layout(location = TEXCOORD) in vec2 Texcoord;
out block
{
flat int InstanceId;
vec2 Texcoord;
vec3 CameraSpacePosition;
vec3 CameraSpaceNormal;
} Out;
void main()
{
Out.Texcoord = Texcoord;
vec3 p = Position;
vec3 n = Normal;
float t = Time + gl_InstanceID;
t = 0;
float ct = cos(t);
float st = sin(t);
p.x = Position.x * ct + Position.z * st;
p.z = -Position.x * st + Position.z * ct;
n.x = Normal.x * ct + Normal.z * st;
n.z = -Normal.x * st + Normal.z * ct;
n.y = Normal.y;
float square = sqrt(InstanceCount);
float square_delta = 2.0;
if (gl_InstanceID > 0) {
p.x += square_delta * floor(gl_InstanceID / square) - square;
p.z += square_delta * (gl_InstanceID - (square * floor(gl_InstanceID/square))) - square;
p.y += 1; //sin(floor(gl_InstanceID / square)) + sin((gl_InstanceID - (square * floor(gl_InstanceID/square)))) ;
}
Out.CameraSpacePosition = vec3(vec4(p, 1.0));
Out.CameraSpaceNormal = vec3(vec4(n, 0.0));
Out.InstanceId = gl_InstanceID;
gl_Position = MVP * vec4(p, 1.0);
}