#version 150 uniform mat4 modelViewProjectionMatrix; uniform float gridSize; uniform vec2 resolution; uniform vec2 threshold; uniform sampler2DRect tex1; in vec2 texcoord; in vec4 position; out vec2 tex_c; void main() { tex_c = texcoord; //float depth = pow(texture(tex1, tex_c).r, 2); vec2 depthCoord = texcoord * vec2(1920.0/2.0, 960.0); float depth = texture(tex1, depthCoord).r; // Normalize the depth value between 0 and 1 based on min/max float normalizedDepth = (depth); vec4 displaced = position; displaced.z = normalizedDepth * 400.0; // Transform the vertex position to clip space vec4 clipPos = modelViewProjectionMatrix * displaced; // 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; //gl_Position = modelViewProjectionMatrix * position; }