From 69ac946e6335d00b5f9d09f03ca1fcf95634f547 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Fri, 13 Jan 2023 12:41:09 -0800 Subject: [PATCH] Simpler get_gl_Position --- manimlib/shaders/inserts/get_gl_Position.glsl | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/manimlib/shaders/inserts/get_gl_Position.glsl b/manimlib/shaders/inserts/get_gl_Position.glsl index 2f9d8934..c322a3ae 100644 --- a/manimlib/shaders/inserts/get_gl_Position.glsl +++ b/manimlib/shaders/inserts/get_gl_Position.glsl @@ -5,27 +5,16 @@ const vec2 DEFAULT_FRAME_SHAPE = vec2(8.0 * 16.0 / 9.0, 8.0); -float perspective_scale_factor(float z, float focal_distance){ - return max(0.0, focal_distance / (focal_distance - z)); -} - - vec4 get_gl_Position(vec3 point){ + vec2 shape; + if(bool(is_fixed_in_frame)) shape = DEFAULT_FRAME_SHAPE; + else shape = frame_shape; + vec4 result = vec4(point, 1.0); - if(!bool(is_fixed_in_frame)){ - result.x *= 2.0 / frame_shape.x; - result.y *= 2.0 / frame_shape.y; - float psf = perspective_scale_factor(result.z, focal_distance); - if (psf > 0){ - result.xy *= psf; - // TODO, what's the better way to do this? - // This is to keep vertices too far out of frame from getting cut. - result.z *= 0.01; - } - } else{ - result.x *= 2.0 / DEFAULT_FRAME_SHAPE.x; - result.y *= 2.0 / DEFAULT_FRAME_SHAPE.y; - } - result.z *= -1; + result.x *= 2.0 / shape.x; + result.y *= 2.0 / shape.y; + result.z /= focal_distance; + result.w = 1.0 - result.z; + result.z *= -0.1; // Flip and prevent premature clipping return result; } \ No newline at end of file