From 364d5d82fe4b33acd8679a66ecf8f9f55eeb00c8 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 26 Mar 2019 23:10:19 +0100 Subject: [PATCH 1/3] display: don't apply color-scale-via-lighting to shader inputs This isn't working properly at the moment, since the state gets set for the *next* object, causing significant artifacts. I wasn't entirely sure whether to restore the "proper" behavior or not, since applications may be relying on one or the other behavior, but enabling this feature for shaders is a minefield and it's a lot better to just tell people to use p3d_ColorScale instead. --- panda/src/display/graphicsStateGuardian.cxx | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 233d47bc09..5931024786 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -1433,12 +1433,7 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name, // Apply the default OpenGL lights otherwise. // Special exception for light 0, which defaults to white. string basename = name->get_basename(); - if (basename == "color" || basename == "diffuse") { - t.set_row(3, _light_color_scale); - return &t; - } else if (basename == "specular") { - return &LMatrix4::ones_mat(); - } + return &LMatrix4::ones_mat(); } return fetch_specified_member(NodePath(), name, t); } @@ -1551,7 +1546,6 @@ fetch_specified_member(const NodePath &np, CPT_InternalName attrib, LMatrix4 &t) nassertr(light != nullptr, &LMatrix4::ident_mat()); if (node->is_ambient_light()) { LColor c = light->get_color(); - c.componentwise_mult(_light_color_scale); t.set_row(3, c); } else { // Non-ambient lights don't currently have an ambient color in Panda3D. @@ -1570,7 +1564,6 @@ fetch_specified_member(const NodePath &np, CPT_InternalName attrib, LMatrix4 &t) t.set_row(3, LColor(0.0f, 0.0f, 0.0f, 1.0f)); } else { LColor c = light->get_color(); - c.componentwise_mult(_light_color_scale); t.set_row(3, c); } return &t; From 63a764a61b7b2fd64bdfa2fdf52a546a004457cd Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 29 Mar 2019 13:28:12 +0100 Subject: [PATCH 2/3] display: fix missed cases in 364d5d82fe4b33acd8679a66ecf8f9f55eeb00c8 --- panda/src/display/graphicsStateGuardian.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 5931024786..fd64170f63 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -1489,7 +1489,7 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name, } else if (index == 0) { // Apply the default OpenGL lights otherwise. // Special exception for light 0, which defaults to white. - t.set_row(0, _light_color_scale); + t.set_row(0, LVecBase4(1, 1, 1, 1)); } return &t; } @@ -1534,7 +1534,6 @@ fetch_specified_member(const NodePath &np, CPT_InternalName attrib, LMatrix4 &t) Light *light = node->as_light(); nassertr(light != nullptr, &LMatrix4::ident_mat()); LColor c = light->get_color(); - c.componentwise_mult(_light_color_scale); t.set_row(3, c); return &t; From 3ea562d40465fba1fb9ed9fb3ee4db94e3e3aea7 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 29 Mar 2019 13:28:53 +0100 Subject: [PATCH 3/3] collide: handle degenerate case for into-sphere test more robustly This case happens, for example, when colliding a capsule with identical begin and end points into a sphere. --- panda/src/collide/collisionSphere.cxx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/panda/src/collide/collisionSphere.cxx b/panda/src/collide/collisionSphere.cxx index aacc43fcb2..0d3275ec36 100644 --- a/panda/src/collide/collisionSphere.cxx +++ b/panda/src/collide/collisionSphere.cxx @@ -620,14 +620,20 @@ intersects_line(double &t1, double &t2, double A = dot(delta, delta); - nassertr(A != 0.0, false); - LVector3 fc = from - get_center(); - double B = 2.0f* dot(delta, fc); double fc_d2 = dot(fc, fc); double radius = get_radius() + inflate_radius; double C = fc_d2 - radius * radius; + if (A == 0.0) { + // Degenerate case where delta is zero. This is effectively a test + // against a point (or sphere, for nonzero inflate_radius). + t1 = 0.0; + t2 = 0.0; + return C < 0.0; + } + + double B = 2.0f * dot(delta, fc); double radical = B*B - 4.0*A*C; if (IS_NEARLY_ZERO(radical)) {