mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
Clean up changes associated with fixing aspect ratio issue
This commit is contained in:
parent
05a89d754e
commit
6d23df0497
5 changed files with 18 additions and 16 deletions
|
@ -6,9 +6,11 @@ import OpenGL.GL as gl
|
|||
from PIL import Image
|
||||
|
||||
from manimlib.camera.camera_frame import CameraFrame
|
||||
from manimlib.constants import ASPECT_RATIO
|
||||
from manimlib.constants import BLACK
|
||||
from manimlib.constants import DEFAULT_FPS
|
||||
from manimlib.constants import DEFAULT_PIXEL_HEIGHT, DEFAULT_PIXEL_WIDTH
|
||||
from manimlib.constants import FRAME_HEIGHT
|
||||
from manimlib.constants import FRAME_WIDTH
|
||||
from manimlib.mobject.mobject import Mobject
|
||||
from manimlib.mobject.mobject import Point
|
||||
|
@ -244,8 +246,12 @@ class Camera(object):
|
|||
|
||||
self.uniforms.update(
|
||||
view=tuple(view_matrix.T.flatten()),
|
||||
focal_distance=frame.get_focal_distance() / frame.get_scale(),
|
||||
frame_scale=frame.get_scale(),
|
||||
frame_rescale_factors=(
|
||||
2.0 / FRAME_WIDTH,
|
||||
2.0 / FRAME_HEIGHT,
|
||||
frame.get_scale() / frame.get_focal_distance(),
|
||||
),
|
||||
pixel_size=self.get_pixel_size(),
|
||||
camera_position=tuple(cam_pos),
|
||||
light_position=tuple(light_pos),
|
||||
|
|
|
@ -523,17 +523,21 @@ def get_configuration(args: Namespace) -> dict:
|
|||
"embed_error_sound": custom_config["embed_error_sound"],
|
||||
}
|
||||
|
||||
|
||||
def get_frame_height():
|
||||
return 8.0
|
||||
|
||||
|
||||
def get_aspect_ratio():
|
||||
cam_config = get_camera_config(parse_cli(), get_custom_config())
|
||||
return cam_config['pixel_width'] / cam_config['pixel_height']
|
||||
|
||||
|
||||
def get_default_pixel_width():
|
||||
cam_config = get_camera_config(parse_cli(), get_custom_config())
|
||||
return cam_config['pixel_width']
|
||||
|
||||
|
||||
def get_default_pixel_height():
|
||||
cam_config = get_camera_config(parse_cli(), get_custom_config())
|
||||
return cam_config['pixel_height']
|
|
@ -1,7 +1,10 @@
|
|||
from __future__ import annotations
|
||||
import numpy as np
|
||||
|
||||
from manimlib.config import get_aspect_ratio,get_default_pixel_width,get_default_pixel_height,get_frame_height
|
||||
from manimlib.config import get_aspect_ratio
|
||||
from manimlib.config import get_default_pixel_width
|
||||
from manimlib.config import get_default_pixel_height
|
||||
from manimlib.config import get_frame_height
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
|
|
|
@ -1,20 +1,14 @@
|
|||
uniform float is_fixed_in_frame;
|
||||
uniform mat4 view;
|
||||
uniform float focal_distance;
|
||||
|
||||
const float DEFAULT_FRAME_HEIGHT = 8.0;
|
||||
const float ASPECT_RATIO = 16.0 / 9.0;
|
||||
const float X_SCALE = 2.0 / DEFAULT_FRAME_HEIGHT / ASPECT_RATIO;
|
||||
const float Y_SCALE = 2.0 / DEFAULT_FRAME_HEIGHT;
|
||||
uniform vec3 frame_rescale_factors;
|
||||
|
||||
void emit_gl_Position(vec3 point){
|
||||
vec4 result = vec4(point, 1.0);
|
||||
// This allow for smooth transitions between objects fixed and unfixed from frame
|
||||
result = mix(view * result, result, is_fixed_in_frame);
|
||||
// Essentially a projection matrix
|
||||
result.x *= X_SCALE;
|
||||
result.y *= Y_SCALE;
|
||||
result.z /= focal_distance;
|
||||
result.xyz *= frame_rescale_factors;
|
||||
result.w = 1.0 - result.z;
|
||||
// Flip and scale to prevent premature clipping
|
||||
result.z *= -0.1;
|
||||
|
|
|
@ -7,9 +7,6 @@ import moderngl
|
|||
from PIL import Image
|
||||
import numpy as np
|
||||
|
||||
from manimlib.config import parse_cli
|
||||
from manimlib.config import get_configuration
|
||||
from manimlib.constants import ASPECT_RATIO
|
||||
from manimlib.utils.directories import get_shader_dir
|
||||
from manimlib.utils.file_ops import find_file
|
||||
|
||||
|
@ -99,8 +96,6 @@ def get_shader_code_from_file(filename: str) -> str | None:
|
|||
with open(filepath, "r") as f:
|
||||
result = f.read()
|
||||
|
||||
result = re.sub(r"\s+ASPECT_RATIO\s+=\s+[\s0-9/.]+", f" ASPECT_RATIO = {ASPECT_RATIO}", result)
|
||||
|
||||
# To share functionality between shaders, some functions are read in
|
||||
# from other files an inserted into the relevant strings before
|
||||
# passing to ctx.program for compiling
|
||||
|
|
Loading…
Add table
Reference in a new issue