mirror of
https://github.com/3b1b/manim.git
synced 2025-11-14 06:47:51 +00:00
Small shader fixes
This commit is contained in:
parent
f0a36329b1
commit
b91284b4aa
6 changed files with 25 additions and 27 deletions
|
|
@ -148,7 +148,7 @@ class Camera(object):
|
|||
"light_source_position": [-10, 10, 10],
|
||||
"apply_depth_test": False,
|
||||
# Measured in pixel widths, used for vector graphics
|
||||
"anti_alias_width": 3,
|
||||
"anti_alias_width": 1.5,
|
||||
# Although vector graphics handle antialiasing fine
|
||||
# without multisampling, for 3d scenes one might want
|
||||
# to set samples to be greater than 0.
|
||||
|
|
@ -371,7 +371,8 @@ class Camera(object):
|
|||
return
|
||||
|
||||
pw, ph = self.get_pixel_shape()
|
||||
anti_alias_width = self.anti_alias_width / (ph / 2)
|
||||
fw, fh = self.frame.get_shape()
|
||||
anti_alias_width = self.anti_alias_width / (ph / fh)
|
||||
transform = self.frame.get_inverse_camera_position_matrix()
|
||||
light = self.light_source.get_location()
|
||||
transformed_light = np.dot(transform, [*light, 1])[:3]
|
||||
|
|
|
|||
|
|
@ -6,19 +6,19 @@
|
|||
const vec2 DEFAULT_FRAME_SHAPE = vec2(8 * 16 / 9, 8);
|
||||
|
||||
vec4 get_gl_Position(vec3 point){
|
||||
vec4 result = vec4(point, 1);
|
||||
if(!bool(is_fixed_in_frame)){
|
||||
point.x *= 2 / frame_shape.x;
|
||||
point.y *= 2 / frame_shape.y;
|
||||
point.z /= focal_distance;
|
||||
point.xy /= max(1 - point.z, 0);
|
||||
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.
|
||||
if(point.z < 0) point.z *= 0.1;
|
||||
if(result.z < 0) result.z *= 0.1;
|
||||
} else{
|
||||
point.x *= 2 / DEFAULT_FRAME_SHAPE.x;
|
||||
point.y *= 2 / DEFAULT_FRAME_SHAPE.y;
|
||||
|
||||
result.x *= 2 / DEFAULT_FRAME_SHAPE.x;
|
||||
result.y *= 2 / DEFAULT_FRAME_SHAPE.y;
|
||||
}
|
||||
return vec4(point.xy, -point.z, 1);
|
||||
return result;
|
||||
}
|
||||
|
|
@ -20,9 +20,6 @@ float modify_distance_for_endpoints(vec2 p, float dist, float t){
|
|||
return dist;
|
||||
}
|
||||
|
||||
// To my knowledge, there is no notion of #include for shaders,
|
||||
// so to share functionality between this and others, the caller
|
||||
// replaces this line with the contents of quadratic_bezier_sdf.glsl
|
||||
#INSERT quadratic_bezier_distance.glsl
|
||||
|
||||
|
||||
|
|
@ -52,13 +49,13 @@ float sdf(){
|
|||
);
|
||||
vec2 p = to_simple_space * uv_coords;
|
||||
// Sign takes care of whether we should be filling the inside or outside of curve.
|
||||
float sn = orientation * sign(v2);
|
||||
float Fp = sn * (p.x * p.x - p.y);
|
||||
vec2 grad = vec2(
|
||||
-2 * p.x * v2, // del C / del u
|
||||
4 * v2 - 4 * p.x * (2 - u2) // del C / del v
|
||||
);
|
||||
return Fp / length(grad);
|
||||
float sgn = orientation * sign(v2);
|
||||
float Fp = (p.x * p.x - p.y);
|
||||
if(sgn * Fp < 0){
|
||||
return 0;
|
||||
}else{
|
||||
return min_dist_to_curve(uv_coords, uv_b2, bezier_degree);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -110,14 +110,14 @@ void emit_pentagon(vec3[3] points, vec3 normal){
|
|||
|
||||
void main(){
|
||||
fill_all = v_fill_all[0];
|
||||
vec3 local_unit_normal = get_unit_normal(vec3[3](bp[0], bp[1], bp[2]));
|
||||
orientation = sign(dot(v_global_unit_normal[0], local_unit_normal));
|
||||
|
||||
if(fill_all == 1){
|
||||
emit_simple_triangle();
|
||||
return;
|
||||
}
|
||||
|
||||
vec3 local_unit_normal = get_unit_normal(vec3[3](bp[0], bp[1], bp[2]));
|
||||
orientation = sign(dot(v_global_unit_normal[0], local_unit_normal));
|
||||
|
||||
vec3 new_bp[3];
|
||||
bezier_degree = get_reduced_control_points(vec3[3](bp[0], bp[1], bp[2]), new_bp);
|
||||
if(bezier_degree >= 1){
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ out float v_shadow;
|
|||
|
||||
void main(){
|
||||
bp = position_point_into_frame(point);
|
||||
v_global_unit_normal = normalize(position_point_into_frame(unit_normal));
|
||||
v_global_unit_normal = normalize(to_screen_space * vec4(unit_normal, 0)).xyz;
|
||||
v_color = color;
|
||||
v_fill_all = fill_all;
|
||||
v_gloss = gloss;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ out vec4 v_color;
|
|||
out float v_gloss;
|
||||
out float v_shadow;
|
||||
|
||||
const float STROKE_WIDTH_CONVERSION = 0.0025;
|
||||
const float STROKE_WIDTH_CONVERSION = 0.01;
|
||||
|
||||
// To my knowledge, there is no notion of #include for shaders,
|
||||
// so to share functionality between this and others, the caller
|
||||
|
|
@ -36,7 +36,7 @@ void main(){
|
|||
bp = position_point_into_frame(point);
|
||||
prev_bp = position_point_into_frame(prev_point);
|
||||
next_bp = position_point_into_frame(next_point);
|
||||
v_global_unit_normal = normalize(position_point_into_frame(unit_normal));
|
||||
v_global_unit_normal = normalize(to_screen_space * vec4(unit_normal, 0)).xyz;
|
||||
|
||||
v_stroke_width = STROKE_WIDTH_CONVERSION * stroke_width;
|
||||
v_color = color;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue