Clamp perspective_scale_factor

This commit is contained in:
Grant Sanderson 2021-01-09 10:29:45 -08:00
parent ff37b589ff
commit ac4755459a

View file

@ -6,8 +6,7 @@
const vec2 DEFAULT_FRAME_SHAPE = vec2(8.0 * 16.0 / 9.0, 8.0); const vec2 DEFAULT_FRAME_SHAPE = vec2(8.0 * 16.0 / 9.0, 8.0);
float perspective_scale_factor(float z, float focal_distance){ float perspective_scale_factor(float z, float focal_distance){
// TODO, what happens when focal_distance < z? return max(0.0, focal_distance / (focal_distance - z));
return focal_distance / (focal_distance - z);
} }
@ -16,10 +15,13 @@ vec4 get_gl_Position(vec3 point){
if(!bool(is_fixed_in_frame)){ if(!bool(is_fixed_in_frame)){
result.x *= 2.0 / frame_shape.x; result.x *= 2.0 / frame_shape.x;
result.y *= 2.0 / frame_shape.y; result.y *= 2.0 / frame_shape.y;
result.xy *= perspective_scale_factor(result.z, focal_distance); float psf = perspective_scale_factor(result.z, focal_distance);
if (psf > 0){
result.xy *= psf;
// TODO, what's the better way to do this? // TODO, what's the better way to do this?
// This is to keep vertices too far out of frame from getting cut. // This is to keep vertices too far out of frame from getting cut.
result.z *= 0.01; result.z *= 0.01;
}
} else{ } else{
result.x *= 2.0 / DEFAULT_FRAME_SHAPE.x; result.x *= 2.0 / DEFAULT_FRAME_SHAPE.x;
result.y *= 2.0 / DEFAULT_FRAME_SHAPE.y; result.y *= 2.0 / DEFAULT_FRAME_SHAPE.y;