2023-01-13 22:07:28 -08:00
|
|
|
uniform float is_fixed_in_frame;
|
|
|
|
uniform vec3 camera_offset;
|
|
|
|
uniform mat3 camera_rotation;
|
|
|
|
uniform vec2 frame_shape;
|
|
|
|
uniform float focal_distance;
|
2020-06-08 20:27:07 -07:00
|
|
|
|
2020-06-09 17:12:52 -07:00
|
|
|
const vec2 DEFAULT_FRAME_SHAPE = vec2(8.0 * 16.0 / 9.0, 8.0);
|
2020-06-01 16:21:18 -07:00
|
|
|
|
|
|
|
vec4 get_gl_Position(vec3 point){
|
2023-01-13 12:41:09 -08:00
|
|
|
vec2 shape;
|
|
|
|
if(bool(is_fixed_in_frame)) shape = DEFAULT_FRAME_SHAPE;
|
|
|
|
else shape = frame_shape;
|
|
|
|
|
2020-06-09 17:12:52 -07:00
|
|
|
vec4 result = vec4(point, 1.0);
|
2023-01-13 12:41:09 -08:00
|
|
|
result.x *= 2.0 / shape.x;
|
|
|
|
result.y *= 2.0 / shape.y;
|
|
|
|
result.z /= focal_distance;
|
|
|
|
result.w = 1.0 - result.z;
|
2023-01-13 21:43:01 -08:00
|
|
|
// Flip and scale to prevent premature clipping
|
|
|
|
result.z *= -0.1;
|
2020-06-09 12:34:00 -07:00
|
|
|
return result;
|
2023-01-13 22:07:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vec3 rotate_point_into_frame(vec3 point){
|
|
|
|
if(bool(is_fixed_in_frame)){
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
return camera_rotation * point;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vec3 position_point_into_frame(vec3 point){
|
|
|
|
if(bool(is_fixed_in_frame)){
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
return rotate_point_into_frame(point - camera_offset);
|
|
|
|
}
|