#version 150 uniform mat4 modelViewProjectionMatrix; uniform float gridSize; uniform vec2 resolution; uniform vec2 threshold; uniform sampler2DRect tex1; uniform float depth_mult; 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, 1080.0); float depth = texture(tex1, depthCoord).r; // Apply a contrast adjustment only to the range [0.5, 1.0] // if (depth > 0.4) { // // Shift the range to [0, 1] and apply pow() for more contrast, then shift it back // depth = pow((depth - 0.4) / (1.0 - 0.4), 4.0) * (1.0 - 0.4) + 0.4; // } // Normalize the depth value between 0 and 1 based on min/max float normalizedDepth = (depth); vec4 displaced = position; displaced.z = normalizedDepth * depth_mult; // 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; }