src/gl/gridprogram.cpp

changeset 54
a4055f67b9c7
parent 53
3af627f7a40f
child 55
cb81ecb5fb23
--- a/src/gl/gridprogram.cpp	Thu Feb 13 12:51:27 2020 +0200
+++ b/src/gl/gridprogram.cpp	Thu Feb 13 15:25:01 2020 +0200
@@ -28,10 +28,11 @@
 uniform mat4 model;
 smooth out vec2 ex_uv;
 const mat4 stretch = mat4(vec4(10000, 0, 0, 0), vec4(0, 10000, 0, 0), vec4(0, 0, 10000, 0), vec4(0, 0, 0, 1));
+const mat4 gridmatrix = mat4(vec4(1, 0, 0, 0), vec4(0, 1, 0, 0), vec4(0, 0, 1, 0), vec4(0, 0, 0, 1));
 
 void main()
 {
-	gl_Position = projection * view * model * stretch * vec4(in_position, 0.0, 1.0);
+	gl_Position = projection * view * model * gridmatrix * stretch * vec4(in_position, 0.0, 1.0);
 	ex_uv = in_position;
 }
 )";
@@ -42,13 +43,22 @@
 out vec4 color;
 smooth in vec2 ex_uv;
 const vec4 lineColor = vec4(1.0, 1.0, 1.0, 0.75);
+const float pi = 3.14159265f;
 
 void main(void)
 {
-	if(fract(ex_uv.x / 0.001f) < 0.01f || fract(ex_uv.y / 0.001f) < 0.01f)
-		color = lineColor;
-	else
-		color = vec4(0);
+	float dx = fract(ex_uv.y / 0.0001f);
+	float dy = fract(ex_uv.x / 0.0001f);
+	/* compute distance to nearest unit line */
+	float d = min(min(min(dy, dx), 1 - dy), 1 - dx);
+	/* use an extreme sigmoid to bring out the grid shape */
+	d = pow(1 - d, 50);
+	/* fade the grid towards extreme co-ordinates */
+	d = (1.0f - 20 * max(abs(ex_uv.x), abs(ex_uv.y))) * d;
+	/* add dashes */
+	d *= (1 + cos(ex_uv.y / 0.00001f * pi)) * 0.5f;
+	d *= (1 + cos(ex_uv.x / 0.00001f * pi)) * 0.5f;
+	color = vec4(lineColor.xyz, d);
 }
 )";
 

mercurial