You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
834 B
37 lines
834 B
#version 150
|
|
|
|
uniform mat4 modelViewProjectionMatrix;
|
|
uniform float gridSize;
|
|
uniform vec2 resolution;
|
|
|
|
in vec2 texcoord;
|
|
in vec4 position;
|
|
|
|
out vec2 tex_c;
|
|
|
|
void main()
|
|
{
|
|
tex_c = texcoord;
|
|
|
|
//vec2 resolution = vec2(1280.0, 960.0);
|
|
|
|
// Transform the vertex position to clip space
|
|
vec4 clipPos = modelViewProjectionMatrix * position;
|
|
|
|
// Perform perspective division
|
|
vec3 ndcPos = clipPos.xyz / clipPos.w;
|
|
|
|
// Convert to screen space
|
|
vec2 screenPos = (ndcPos.xy + 1.0) * 0.5 * resolution;
|
|
|
|
// Snap to grid
|
|
screenPos = floor(screenPos / gridSize) * gridSize;
|
|
|
|
// Convert back to NDC space
|
|
ndcPos.xy = (screenPos / resolution) * 2.0 - 1.0;
|
|
|
|
// Reconstruct the clip space position
|
|
clipPos = vec4(ndcPos * clipPos.w, clipPos.w);
|
|
|
|
gl_Position = clipPos;
|
|
}
|
|
|