simplify shader grid drawing and add option to use a texture for the grid

This commit is contained in:
2023-09-08 16:38:14 +02:00
parent 978f60d762
commit 27d6853e3e
11 changed files with 8109 additions and 62 deletions
+5 -1
View File
@@ -1,6 +1,10 @@
#version 330 core
out vec4 FragColor;
in vec2 texCoords;
uniform sampler2D aTexture;
void main() {
FragColor = vec4(240.f/255.f, 235.f/255.f, 227.f/255.f, 1.0);
FragColor = texture(aTexture, texCoords);
}
+3
View File
@@ -1,8 +1,11 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTexCoords;
out vec2 texCoords;
uniform mat4 transform;
void main() {
gl_Position = transform * vec4(aPos, 1.0f);
texCoords = aTexCoords;
}
+6 -4
View File
@@ -15,12 +15,14 @@ void main()
// Calculate the UV coordinates of the current fragment
vec2 uv = (gl_FragCoord * transform).xy / vec2(resolution, resolution); // Adjust the resolution as needed
float scale_x = transform[0][0];
float scale_y = transform[1][1];
// Calculate the coordinates of the current fragment in the [-1, 1] range
float fragCoordX = (uv.x - 0.5) * (2.0 / transform[0][0]) - 1.0;
float fragCoordY = (uv.y - 0.5) * (2.0 / transform[1][1]) - 1.0;
float fragCoordX = (uv.x - 0.5) * (2.0 / scale_x) - 1.0;
float fragCoordY = (uv.y - 0.5) * (2.0 / scale_y) - 1.0;
// Initialize colors for grid lines and background
// Colors for grid lines
vec3 gridColor = vec3(0.4, 0.4, 0.4);
vec3 gridColorThick = vec3(0.2, 0.2, 0.2);
@@ -42,6 +44,6 @@ void main()
} else if (isGridX || isGridY) {
FragColor = vec4(gridColor, 1.0);
} else {
discard;
FragColor = vec4(240.f/255.f, 235.f/255.f, 227.f/255.f, 1.0);
}
}
-12
View File
@@ -1,12 +0,0 @@
#version 330 core
uniform mat4 transform;
vec3 gridPlane[6] = vec3[](
vec3(1, 1, 0), vec3(-1, -1, 0), vec3(-1, 1, 0),
vec3(-1, -1, 0), vec3(1, 1, 0), vec3(1, -1, 0)
);
void main() {
vec3 p = gridPlane[gl_VertexID].xyz;
gl_Position = vec4(p, 1.0f);
}