25 layout (location = 0) in vec2 in_position; |
25 layout (location = 0) in vec2 in_position; |
26 uniform mat4 view; |
26 uniform mat4 view; |
27 uniform mat4 projection; |
27 uniform mat4 projection; |
28 uniform mat4 model; |
28 uniform mat4 model; |
29 smooth out vec2 ex_uv; |
29 smooth out vec2 ex_uv; |
30 const mat4 stretch = mat4(vec4(10000, 0, 0, 0), vec4(0, 10000, 0, 0), vec4(0, 0, 10000, 0), vec4(0, 0, 0, 1)); |
30 const mat4 stretch = mat4(vec4(1000, 0, 0, 0), vec4(0, 1000, 0, 0), vec4(0, 0, 1000, 0), vec4(0, 0, 0, 1)); |
31 uniform mat4 grid; |
31 uniform mat4 grid; |
32 |
32 |
33 void main() |
33 void main() |
34 { |
34 { |
35 gl_Position = projection * view * model * grid * stretch * vec4(in_position, 0.0, 1.0); |
35 gl_Position = projection * view * model * grid * stretch * vec4(in_position, 0.0, 1.0); |
45 uniform vec4 gridColor; |
45 uniform vec4 gridColor; |
46 const float pi = 3.14159265f; |
46 const float pi = 3.14159265f; |
47 |
47 |
48 void main(void) |
48 void main(void) |
49 { |
49 { |
50 float dx = fract(ex_uv.y / 0.0001f); |
50 float dx = fract(ex_uv.y / 0.001f); |
51 float dy = fract(ex_uv.x / 0.0001f); |
51 float dy = fract(ex_uv.x / 0.001f); |
52 /* compute distance to nearest unit line */ |
52 /* compute distance to nearest unit line */ |
53 float d = min(min(min(dy, dx), 1 - dy), 1 - dx); |
53 float d = min(min(min(dy, dx), 1 - dy), 1 - dx); |
54 /* use an extreme sigmoid to bring out the grid shape */ |
54 /* use an extreme sigmoid to bring out the grid shape */ |
55 d = pow(1 - d, 50); |
55 d = pow(1 - d, 50); |
56 /* fade the grid towards extreme co-ordinates */ |
56 /* fade the grid towards extreme co-ordinates */ |
57 d = (1.0f - 20 * max(abs(ex_uv.x), abs(ex_uv.y))) * d; |
57 d = (1.0f - 20 * max(abs(ex_uv.x), abs(ex_uv.y))) * d; |
58 /* add dashes */ |
58 /* add dashes */ |
59 d *= (1 + cos(ex_uv.y / 0.00001f * pi)) * 0.5f; |
59 d *= (1 + cos(ex_uv.y / 0.0001f * pi)) * 0.5f; |
60 d *= (1 + cos(ex_uv.x / 0.00001f * pi)) * 0.5f; |
60 d *= (1 + cos(ex_uv.x / 0.0001f * pi)) * 0.5f; |
61 color = vec4(gridColor.xyz, gridColor.w * d); |
61 color = vec4(gridColor.xyz, gridColor.w * d); |
62 } |
62 } |
63 )"; |
63 )"; |
64 |
64 |
65 static const glm::vec2 data[] = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}}; |
65 static const glm::vec2 data[] = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}}; |