board grid lines

This commit is contained in:
2023-09-08 01:11:35 +02:00
parent 4d03b0d3ee
commit fe99a4c9ff
7 changed files with 86 additions and 2 deletions
+47
View File
@@ -0,0 +1,47 @@
#version 330 core
out vec4 FragColor;
uniform mat4 transform;
uniform float resolution;
void main()
{
// Define the size of the grid
int gridSize = 9;
// Calculate the step size for the grid lines
float stepSize = 2.0 / float(gridSize);
// Calculate the UV coordinates of the current fragment
vec2 uv = (gl_FragCoord * transform).xy / vec2(resolution, resolution); // Adjust the resolution as needed
// 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;
// Initialize colors for grid lines and background
vec3 gridColor = vec3(0.4, 0.4, 0.4);
vec3 gridColorThick = vec3(0.2, 0.2, 0.2);
bool isInsideGridHorizontally = (fragCoordX >= -2.0 && fragCoordX <= 0.0);
bool isInsideGridVertically = (fragCoordY >= -2.0 && fragCoordY <= 0.0);
bool isInsideGrid = isInsideGridHorizontally && isInsideGridVertically;
// Determine if the current fragment is on a thicker grid line
bool isThickLineX = isInsideGrid && mod(fragCoordX, stepSize * 3) < 0.01;
bool isThickLineY = isInsideGrid && mod(fragCoordY, stepSize * 3) < 0.01;
// Check if the current fragment is on a grid line
bool isGridX = isInsideGrid && mod(fragCoordX, stepSize) < 0.005;
bool isGridY = isInsideGrid && mod(fragCoordY, stepSize) < 0.005;
// Set the fragment color based on whether it's a grid line or a thicker grid line
if ((isThickLineX) || (isThickLineY)) {
FragColor = vec4(gridColorThick, 1.0);
} else if (isGridX || isGridY) {
FragColor = vec4(gridColor, 1.0);
} else {
discard;
}
}
+12
View File
@@ -0,0 +1,12 @@
#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);
}