Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions manimlib/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(
self,
color: ManimColor = DEFAULT_MOBJECT_COLOR,
opacity: float = 1.0,
shading: Tuple[float, float, float] = (0.0, 0.0, 0.0),
shading: Tuple[float, float, float, float] = (0.0, 0.0, 0.0, 0.0),
# For shaders
texture_paths: dict[str, str] | None = None,
# If true, the mobject will not get rotated according to camera position
Expand Down Expand Up @@ -1432,16 +1432,21 @@ def set_shading(
reflectiveness: float | None = None,
gloss: float | None = None,
shadow: float | None = None,
# TODO: `glow` does nothing at the moment;
# still needs to be implemented in the shader code in
# manimlib/shaders/inserts/finalize_color.glsl
glow: float | None = None,
recurse: bool = True
) -> Self:
"""
Larger reflectiveness makes things brighter when facing the light
Larger shadow makes faces opposite the light darker
Makes parts bright where light gets reflected toward the camera
Glow should add a glowing outline around the silhouette of the mobject
"""
for mob in self.get_family(recurse):
shading = mob.uniforms["shading"]
for i, value in enumerate([reflectiveness, gloss, shadow]):
for i, value in enumerate([reflectiveness, gloss, shadow, glow]):
if value is not None:
shading[i] = value
mob.set_uniform(shading=shading, recurse=False)
Expand Down
7 changes: 5 additions & 2 deletions manimlib/shaders/inserts/finalize_color.glsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
uniform vec3 light_position;
uniform vec3 camera_position;
uniform vec3 shading;
uniform vec4 shading;

vec3 float_to_color(float value, float min_val, float max_val, vec3[9] colormap_data){
float alpha = clamp((value - min_val) / (max_val - min_val), 0.0, 1.0);
Expand All @@ -14,11 +14,14 @@ vec3 float_to_color(float value, float min_val, float max_val, vec3[9] colormap_


vec4 add_light(vec4 color, vec3 point, vec3 unit_normal){
if(shading == vec3(0.0)) return color;
if(shading == vec4(0.0)) return color;

float reflectiveness = shading.x;
float gloss = shading.y;
float shadow = shading.z;
// glow does noting at the moment;
// shader code needs to be implemented to create a glow around the mobject
float glow = shading.w;

vec4 result = color;
vec3 to_camera = normalize(camera_position - point);
Expand Down
2 changes: 1 addition & 1 deletion manimlib/shaders/inserts/get_unit_normal.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ vec3 get_unit_normal(vec3 p0, vec3 p1, vec3 p2){

if(cp_norm > tol) return cp / cp_norm;

// Otherwise, three pionts form a line, so find
// Otherwise, three points form a line, so find
// a normal vector to that line in the plane shared
// with the z-axis
vec3 comb = v1 + v2;
Expand Down
2 changes: 1 addition & 1 deletion manimlib/shaders/true_dot/frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main() {
frag_color.a *= pow(1 - r, glow_factor);
}

if(shading != vec3(0.0)){
if(shading != vec4(0.0)){
vec3 point_3d = point + radius * sqrt(1 - r * r) * to_cam;
vec3 normal = normalize(point_3d - center);
frag_color = finalize_color(frag_color, point_3d, normal);
Expand Down