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.
 
 
 
 

57 lines
1.5 KiB

#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;
}