3b1b-manim/manimlib/shaders/get_gl_Position.glsl

24 lines
899 B
Text
Raw Normal View History

2020-06-01 16:21:18 -07:00
// Assumes the following uniforms exist in the surrounding context:
// uniform vec2 frame_shape;
2020-06-02 16:18:44 -07:00
// uniform float focal_distance;
// uniform float is_fixed_in_frame;
const vec2 DEFAULT_FRAME_SHAPE = vec2(8 * 16 / 9, 8);
2020-06-01 16:21:18 -07:00
vec4 get_gl_Position(vec3 point){
2020-06-09 12:34:00 -07:00
vec4 result = vec4(point, 1);
if(!bool(is_fixed_in_frame)){
2020-06-09 12:34:00 -07:00
result.x *= 2 / frame_shape.x;
result.y *= 2 / frame_shape.y;
result.z /= focal_distance;
result.xy /= max(1 - point.z, 0);
// Todo, does this discontinuity add weirdness? Theoretically, by this point,
// the z-coordiante of gl_Position only matter for z-indexing. The reason
// for thie line is to avoid agressive clipping of distant points.
2020-06-09 12:34:00 -07:00
if(result.z < 0) result.z *= 0.1;
} else{
2020-06-09 12:34:00 -07:00
result.x *= 2 / DEFAULT_FRAME_SHAPE.x;
result.y *= 2 / DEFAULT_FRAME_SHAPE.y;
}
2020-06-09 12:34:00 -07:00
return result;
2020-06-01 16:21:18 -07:00
}