mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Make gloss and shadow uniforms
This commit is contained in:
parent
1cab58ac49
commit
8af879236e
11 changed files with 54 additions and 71 deletions
|
@ -1143,8 +1143,17 @@ class Mobject(Container):
|
|||
pass # To implement in subclass
|
||||
|
||||
def interpolate_light_style(self, mobject1, mobject2, alpha):
|
||||
self.set_gloss(interpolate(mobject1.get_gloss(), mobject2.get_gloss(), alpha))
|
||||
self.set_shadow(interpolate(mobject1.get_shadow(), mobject2.get_shadow(), alpha))
|
||||
g0 = self.get_gloss()
|
||||
g1 = mobject1.get_gloss()
|
||||
g2 = mobject2.get_gloss()
|
||||
if not (g0 == g1 == g2):
|
||||
self.set_gloss(interpolate(g1, g2, alpha))
|
||||
|
||||
s0 = self.get_shadow()
|
||||
s1 = mobject1.get_shadow()
|
||||
s2 = mobject2.get_shadow()
|
||||
if not (s0 == s1 == s2):
|
||||
self.set_shadow(interpolate(s1, s2, alpha))
|
||||
return self
|
||||
|
||||
def become_partial(self, mobject, a, b):
|
||||
|
@ -1258,6 +1267,8 @@ class Mobject(Container):
|
|||
def get_shader_uniforms(self):
|
||||
return {
|
||||
"is_fixed_in_frame": float(self.is_fixed_in_frame),
|
||||
"gloss": self.gloss,
|
||||
"shadow": self.shadow,
|
||||
}
|
||||
|
||||
def get_shader_data(self):
|
||||
|
|
|
@ -35,8 +35,6 @@ class ParametricSurface(Mobject):
|
|||
('du_point', np.float32, (3,)),
|
||||
('dv_point', np.float32, (3,)),
|
||||
('color', np.float32, (4,)),
|
||||
('gloss', np.float32, (1,)),
|
||||
('shadow', np.float32, (1,)),
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -133,8 +131,6 @@ class ParametricSurface(Mobject):
|
|||
data["point"] = s_points[tri_indices]
|
||||
data["du_point"] = du_points[tri_indices]
|
||||
data["dv_point"] = dv_points[tri_indices]
|
||||
data["gloss"] = self.gloss
|
||||
data["shadow"] = self.shadow
|
||||
self.fill_in_shader_color_info(data)
|
||||
return data
|
||||
|
||||
|
@ -170,8 +166,6 @@ class TexturedSurface(ParametricSurface):
|
|||
('dv_point', np.float32, (3,)),
|
||||
('im_coords', np.float32, (2,)),
|
||||
('opacity', np.float32, (1,)),
|
||||
('gloss', np.float32, (1,)),
|
||||
('shadow', np.float32, (1,)),
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ from manimlib.utils.bezier import bezier
|
|||
from manimlib.utils.bezier import get_smooth_quadratic_bezier_handle_points
|
||||
from manimlib.utils.bezier import get_quadratic_approximation_of_cubic
|
||||
from manimlib.utils.bezier import interpolate
|
||||
from manimlib.utils.bezier import set_array_by_interpolation
|
||||
from manimlib.utils.bezier import integer_interpolate
|
||||
from manimlib.utils.bezier import partial_quadratic_bezier_points
|
||||
from manimlib.utils.color import color_to_rgba
|
||||
|
@ -64,9 +65,8 @@ class VMobject(Mobject):
|
|||
('point', np.float32, (3,)),
|
||||
('unit_normal', np.float32, (3,)),
|
||||
('color', np.float32, (4,)),
|
||||
('fill_all', np.float32, (1,)),
|
||||
('gloss', np.float32, (1,)),
|
||||
('shadow', np.float32, (1,)),
|
||||
# ('fill_all', np.float32, (1,)),
|
||||
('vert_index', np.float32, (1,)),
|
||||
],
|
||||
"stroke_dtype": [
|
||||
("point", np.float32, (3,)),
|
||||
|
@ -75,8 +75,6 @@ class VMobject(Mobject):
|
|||
('unit_normal', np.float32, (3,)),
|
||||
("stroke_width", np.float32, (1,)),
|
||||
("color", np.float32, (4,)),
|
||||
("gloss", np.float32, (1,)),
|
||||
("shadow", np.float32, (1,)),
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -828,10 +826,12 @@ class VMobject(Mobject):
|
|||
"stroke_width",
|
||||
]
|
||||
for attr in attrs:
|
||||
arr = getattr(self, attr)
|
||||
m1a = getattr(mobject1, attr)
|
||||
m2a = getattr(mobject2, attr)
|
||||
arr[:] = interpolate(m1a, m2a, alpha)
|
||||
set_array_by_interpolation(
|
||||
getattr(self, attr),
|
||||
getattr(mobject1, attr),
|
||||
getattr(mobject2, attr),
|
||||
alpha
|
||||
)
|
||||
|
||||
def pointwise_become_partial(self, vmobject, a, b):
|
||||
assert(isinstance(vmobject, VMobject))
|
||||
|
@ -972,8 +972,6 @@ class VMobject(Mobject):
|
|||
data["unit_normal"] = self.get_unit_normal()
|
||||
data["stroke_width"][:, 0] = stroke_width
|
||||
data["color"] = rgbas
|
||||
data["gloss"] = self.gloss
|
||||
data["shadow"] = self.shadow
|
||||
return data
|
||||
|
||||
def lock_triangulation(self, family=True):
|
||||
|
@ -1058,12 +1056,7 @@ class VMobject(Mobject):
|
|||
data["point"] = points[tri_indices]
|
||||
data["unit_normal"] = unit_normal
|
||||
data["color"] = rgbas
|
||||
# Assume the triangulation is such that the first n_points points
|
||||
# are on the boundary, and the rest are in the interior
|
||||
data["fill_all"][:len(points)] = 0
|
||||
data["fill_all"][len(points):] = 1
|
||||
data["gloss"] = self.gloss
|
||||
data["shadow"] = self.shadow
|
||||
data["vert_index"][:, 0] = tri_indices
|
||||
return data
|
||||
|
||||
|
||||
|
|
|
@ -9,13 +9,14 @@ uniform vec2 frame_shape;
|
|||
uniform float focal_distance;
|
||||
uniform float is_fixed_in_frame;
|
||||
uniform vec3 light_source_position;
|
||||
uniform float gloss;
|
||||
uniform float shadow;
|
||||
|
||||
in vec3 bp[3];
|
||||
in vec3 v_global_unit_normal[3];
|
||||
in vec4 v_color[3];
|
||||
in float v_fill_all[3];
|
||||
in float v_gloss[3];
|
||||
in float v_shadow[3];
|
||||
// in float v_fill_all[3];
|
||||
in float v_vert_index[3];
|
||||
|
||||
out vec4 color;
|
||||
out float fill_all;
|
||||
|
@ -43,8 +44,8 @@ void emit_vertex_wrapper(vec3 point, int index){
|
|||
point,
|
||||
v_global_unit_normal[index],
|
||||
light_source_position,
|
||||
v_gloss[index],
|
||||
v_shadow[index]
|
||||
gloss,
|
||||
shadow
|
||||
);
|
||||
xyz_coords = point;
|
||||
gl_Position = get_gl_Position(xyz_coords);
|
||||
|
@ -109,8 +110,13 @@ void emit_pentagon(vec3[3] points, vec3 normal){
|
|||
|
||||
|
||||
void main(){
|
||||
fill_all = v_fill_all[0];
|
||||
if(fill_all == 1){
|
||||
// If vert indices are sequential, don't fill all
|
||||
fill_all = float(
|
||||
(v_vert_index[1] - v_vert_index[0]) != 1.0 ||
|
||||
(v_vert_index[2] - v_vert_index[1]) != 1.0
|
||||
);
|
||||
|
||||
if(fill_all == 1.0){
|
||||
emit_simple_triangle();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -6,16 +6,14 @@ uniform float is_fixed_in_frame;
|
|||
in vec3 point;
|
||||
in vec3 unit_normal;
|
||||
in vec4 color;
|
||||
in float fill_all; // Either 0 or 1
|
||||
in float gloss;
|
||||
in float shadow;
|
||||
// in float fill_all; // Either 0 or 1
|
||||
in float vert_index;
|
||||
|
||||
out vec3 bp; // Bezier control point
|
||||
out vec3 v_global_unit_normal;
|
||||
out vec4 v_color;
|
||||
out float v_fill_all;
|
||||
out float v_gloss;
|
||||
out float v_shadow;
|
||||
// out float v_fill_all;
|
||||
out float v_vert_index;
|
||||
|
||||
// To my knowledge, there is no notion of #include for shaders,
|
||||
// so to share functionality between this and others, the caller
|
||||
|
@ -26,7 +24,6 @@ void main(){
|
|||
bp = position_point_into_frame(point);
|
||||
v_global_unit_normal = normalize(to_screen_space * vec4(unit_normal, 0)).xyz;
|
||||
v_color = color;
|
||||
v_fill_all = fill_all;
|
||||
v_gloss = gloss;
|
||||
v_shadow = shadow;
|
||||
// v_fill_all = fill_all;
|
||||
v_vert_index = vert_index;
|
||||
}
|
|
@ -10,6 +10,8 @@ uniform float is_fixed_in_frame;
|
|||
uniform float anti_alias_width;
|
||||
uniform vec3 light_source_position;
|
||||
uniform float joint_type;
|
||||
uniform float gloss;
|
||||
uniform float shadow;
|
||||
|
||||
in vec3 bp[3];
|
||||
in vec3 prev_bp[3];
|
||||
|
@ -18,8 +20,6 @@ in vec3 v_global_unit_normal[3];
|
|||
|
||||
in vec4 v_color[3];
|
||||
in float v_stroke_width[3];
|
||||
in float v_gloss[3];
|
||||
in float v_shadow[3];
|
||||
|
||||
out vec4 color;
|
||||
out float uv_stroke_width;
|
||||
|
@ -256,8 +256,8 @@ void main() {
|
|||
xyz_coords,
|
||||
v_global_unit_normal[index_map[i]],
|
||||
light_source_position,
|
||||
v_gloss[index_map[i]],
|
||||
v_shadow[index_map[i]]
|
||||
gloss,
|
||||
shadow
|
||||
);
|
||||
gl_Position = get_gl_Position(xyz_coords);
|
||||
EmitVertex();
|
||||
|
|
|
@ -11,8 +11,6 @@ in vec3 unit_normal;
|
|||
|
||||
in float stroke_width;
|
||||
in vec4 color;
|
||||
in float gloss;
|
||||
in float shadow;
|
||||
|
||||
// Bezier control point
|
||||
out vec3 bp;
|
||||
|
@ -22,8 +20,6 @@ out vec3 v_global_unit_normal;
|
|||
|
||||
out float v_stroke_width;
|
||||
out vec4 v_color;
|
||||
out float v_gloss;
|
||||
out float v_shadow;
|
||||
|
||||
const float STROKE_WIDTH_CONVERSION = 0.01;
|
||||
|
||||
|
@ -40,6 +36,4 @@ void main(){
|
|||
|
||||
v_stroke_width = STROKE_WIDTH_CONVERSION * stroke_width;
|
||||
v_color = color;
|
||||
v_gloss = gloss;
|
||||
v_shadow = shadow;
|
||||
}
|
|
@ -4,12 +4,12 @@
|
|||
// out vec4 frag_color;
|
||||
|
||||
uniform vec3 light_source_position;
|
||||
uniform float gloss;
|
||||
uniform float shadow;
|
||||
|
||||
in vec3 xyz_coords;
|
||||
in vec3 v_normal;
|
||||
in vec4 v_color;
|
||||
in float v_gloss;
|
||||
in float v_shadow;
|
||||
|
||||
out vec4 frag_color;
|
||||
|
||||
|
@ -21,7 +21,7 @@ void main() {
|
|||
xyz_coords,
|
||||
normalize(v_normal),
|
||||
light_source_position,
|
||||
v_gloss,
|
||||
v_shadow
|
||||
gloss,
|
||||
shadow
|
||||
);
|
||||
}
|
|
@ -10,14 +10,10 @@ in vec3 point;
|
|||
in vec3 du_point;
|
||||
in vec3 dv_point;
|
||||
in vec4 color;
|
||||
in float gloss;
|
||||
in float shadow;
|
||||
|
||||
out vec3 xyz_coords;
|
||||
out vec3 v_normal;
|
||||
out vec4 v_color;
|
||||
out float v_gloss;
|
||||
out float v_shadow;
|
||||
|
||||
// These lines will get replaced
|
||||
#INSERT position_point_into_frame.glsl
|
||||
|
@ -28,7 +24,5 @@ void main(){
|
|||
xyz_coords = position_point_into_frame(point);
|
||||
v_normal = get_rotated_surface_unit_normal_vector(point, du_point, dv_point);
|
||||
v_color = color;
|
||||
v_gloss = gloss;
|
||||
v_shadow = shadow;
|
||||
gl_Position = get_gl_Position(xyz_coords);
|
||||
}
|
|
@ -4,13 +4,13 @@ uniform sampler2D LightTexture;
|
|||
uniform sampler2D DarkTexture;
|
||||
uniform float num_textures;
|
||||
uniform vec3 light_source_position;
|
||||
uniform float gloss;
|
||||
uniform float shadow;
|
||||
|
||||
in vec3 xyz_coords;
|
||||
in vec3 v_normal;
|
||||
in vec2 v_im_coords;
|
||||
in float v_opacity;
|
||||
in float v_gloss;
|
||||
in float v_shadow;
|
||||
|
||||
out vec4 frag_color;
|
||||
|
||||
|
@ -35,8 +35,8 @@ void main() {
|
|||
xyz_coords,
|
||||
normalize(v_normal),
|
||||
light_source_position,
|
||||
v_gloss,
|
||||
v_shadow
|
||||
gloss,
|
||||
shadow
|
||||
);
|
||||
frag_color.a = v_opacity;
|
||||
}
|
|
@ -11,15 +11,11 @@ in vec3 du_point;
|
|||
in vec3 dv_point;
|
||||
in vec2 im_coords;
|
||||
in float opacity;
|
||||
in float gloss;
|
||||
in float shadow;
|
||||
|
||||
out vec3 xyz_coords;
|
||||
out vec3 v_normal;
|
||||
out vec2 v_im_coords;
|
||||
out float v_opacity;
|
||||
out float v_gloss;
|
||||
out float v_shadow;
|
||||
|
||||
// These lines will get replaced
|
||||
#INSERT position_point_into_frame.glsl
|
||||
|
@ -31,7 +27,5 @@ void main(){
|
|||
v_normal = get_rotated_surface_unit_normal_vector(point, du_point, dv_point);
|
||||
v_im_coords = im_coords;
|
||||
v_opacity = opacity;
|
||||
v_gloss = gloss;
|
||||
v_shadow = shadow;
|
||||
gl_Position = get_gl_Position(xyz_coords);
|
||||
}
|
Loading…
Add table
Reference in a new issue