From bb27a78449216c92738c31b1fbf465e786f95aae Mon Sep 17 00:00:00 2001 From: Wallbreaker5th <3277946283@qq.com> Date: Sat, 5 Jun 2021 17:33:54 +0800 Subject: [PATCH 1/2] fix: checking whether normal is facing the camera. --- manimlib/shaders/inserts/finalize_color.glsl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/manimlib/shaders/inserts/finalize_color.glsl b/manimlib/shaders/inserts/finalize_color.glsl index 0664deb0..f9d37cf3 100644 --- a/manimlib/shaders/inserts/finalize_color.glsl +++ b/manimlib/shaders/inserts/finalize_color.glsl @@ -17,16 +17,17 @@ vec4 add_light(vec4 color, float shadow){ if(gloss == 0.0 && shadow == 0.0) return color; - // TODO, do we actually want this? It effectively treats surfaces as two-sided - if(unit_normal.z < 0){ - unit_normal *= -1; - } - // TODO, read this in as a uniform? float camera_distance = 6; // Assume everything has already been rotated such that camera is in the z-direction vec3 to_camera = vec3(0, 0, camera_distance) - point; vec3 to_light = light_coords - point; + + // TODO, do we actually want this? It effectively treats surfaces as two-sided + if(dot(to_camera,unit_normal) < 0){ + unit_normal *= -1; + } + vec3 light_reflection = -to_light + 2 * unit_normal * dot(to_light, unit_normal); float dot_prod = dot(normalize(light_reflection), normalize(to_camera)); float shine = gloss * exp(-3 * pow(1 - dot_prod, 2)); From 442e7fc14daa3f3ddba467bfe606cf0754411c6d Mon Sep 17 00:00:00 2001 From: Wallbreaker5th <3277946283@qq.com> Date: Sat, 5 Jun 2021 17:43:32 +0800 Subject: [PATCH 2/2] Use focal_distance as camera_distance in shaders. --- manimlib/shaders/inserts/finalize_color.glsl | 3 +-- manimlib/shaders/surface/frag.glsl | 1 + manimlib/shaders/textured_surface/frag.glsl | 1 + manimlib/shaders/true_dot/frag.glsl | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/manimlib/shaders/inserts/finalize_color.glsl b/manimlib/shaders/inserts/finalize_color.glsl index f9d37cf3..e7b64eee 100644 --- a/manimlib/shaders/inserts/finalize_color.glsl +++ b/manimlib/shaders/inserts/finalize_color.glsl @@ -17,8 +17,7 @@ vec4 add_light(vec4 color, float shadow){ if(gloss == 0.0 && shadow == 0.0) return color; - // TODO, read this in as a uniform? - float camera_distance = 6; + float camera_distance = focal_distance; // Assume everything has already been rotated such that camera is in the z-direction vec3 to_camera = vec3(0, 0, camera_distance) - point; vec3 to_light = light_coords - point; diff --git a/manimlib/shaders/surface/frag.glsl b/manimlib/shaders/surface/frag.glsl index db905275..707621a1 100644 --- a/manimlib/shaders/surface/frag.glsl +++ b/manimlib/shaders/surface/frag.glsl @@ -3,6 +3,7 @@ uniform vec3 light_source_position; uniform float gloss; uniform float shadow; +uniform float focal_distance; in vec3 xyz_coords; in vec3 v_normal; diff --git a/manimlib/shaders/textured_surface/frag.glsl b/manimlib/shaders/textured_surface/frag.glsl index ab45dad6..616b06e2 100644 --- a/manimlib/shaders/textured_surface/frag.glsl +++ b/manimlib/shaders/textured_surface/frag.glsl @@ -6,6 +6,7 @@ uniform float num_textures; uniform vec3 light_source_position; uniform float gloss; uniform float shadow; +uniform float focal_distance; in vec3 xyz_coords; in vec3 v_normal; diff --git a/manimlib/shaders/true_dot/frag.glsl b/manimlib/shaders/true_dot/frag.glsl index a8965359..0be9a2ab 100644 --- a/manimlib/shaders/true_dot/frag.glsl +++ b/manimlib/shaders/true_dot/frag.glsl @@ -4,6 +4,7 @@ uniform vec3 light_source_position; uniform float gloss; uniform float shadow; uniform float anti_alias_width; +uniform float focal_distance; in vec4 color; in float radius;