2d map, physics, and vptree implementation for sv
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.
 
 
 
 

54 lines
1.2 KiB

#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;
// vec4 t_sample = texture(tex0, tex_c);
float depth = pow(texture(tex1, tex_c).r, 2);
// Normalize the depth value between 0 and 1 based on min/max
float normalizedDepth = (depth) / threshold.y;
vec4 displaced = position;
displaced.z = normalizedDepth * 800.0;
//vec2 resolution = vec2(1280.0, 960.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;
}