-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshader.vert
64 lines (44 loc) · 2.11 KB
/
shader.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
64
#version 330 core
// NOTE: Do NOT use any version older than 330! Bad things will happen!
// This is an example vertex shader. GLSL is very similar to C.
// You can define extra functions if needed, and the main() function is
// called when the vertex shader gets run.
// The vertex shader gets called once per vertex.
//#define MAPSIZEHF 16.0 //map is from -16 to 16 on relative scale, we'll be using half of it
#define SCREENSIZE 20.0 //# of tiles on screen by default, modified by zoom
#define GUISPACE 0.4 //Space we give the Gui
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 aTexCoord;
// Uniform variables can be updated by fetching their location and passing values to that location
//uniform mat4 projection;
//uniform mat4 modelview;
uniform vec2 location;
uniform vec2 BL;
uniform float zoom;
uniform float renderRout;
// Outputs of the vertex shader are the inputs of the same name of the fragment shader.
// The default output, gl_Position, should be assigned something. You can define as many
// extra outputs as you need.
out float alpha;
out vec2 texCoord;
out vec4 FragPos;
float screenhf;
void main()
{
screenhf = (SCREENSIZE ) / 2.0; // - zoom
if(renderRout == 1){ //Tile
//we need to normalize the coordinates in terms of the size of the size of the map but also keep track of where the 'camera' is
//this moves the top left to TL and subtracts the screen half. But we need to account for the shape of the tile! use position.
float xpos = position.x + (location.x - BL.x - screenhf) / screenhf;
float ypos = position.y + (location.y - BL.y - screenhf) / screenhf + GUISPACE;
gl_Position = vec4( xpos, ypos, position.z , 1.0);
FragPos = vec4(xpos, ypos, position.z , 1.0);
texCoord = aTexCoord;
} else { //Map
gl_Position = vec4(position.x, position.y + GUISPACE , position.z, 1.0); //- 0.02 not lining up right at bottom
FragPos = vec4(position.x, position.y, position.z, 1.0); //position of a point same as position but accessible
texCoord = aTexCoord;
}
//normal = mat3(transpose(inverse(modelview))) * norms;
alpha = 1.0f;
}