From 4cad0620c5e83ca7f940e6d63c9794c590637589 Mon Sep 17 00:00:00 2001 From: "Asad M. Zaman" Date: Thu, 16 Sep 2004 01:13:34 +0000 Subject: [PATCH] instead of parent light_color get the root node's color for scene_color. It is more reliable --- panda/src/pgraph/polylightEffect.cxx | 22 +++++++++++++++------- panda/src/pgraph/polylightEffect.h | 2 +- panda/src/pgraph/polylightNode.cxx | 8 ++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/panda/src/pgraph/polylightEffect.cxx b/panda/src/pgraph/polylightEffect.cxx index 0c5cda734f..ba4d153d70 100755 --- a/panda/src/pgraph/polylightEffect.cxx +++ b/panda/src/pgraph/polylightEffect.cxx @@ -104,10 +104,10 @@ has_cull_callback() const { // level. //////////////////////////////////////////////////////////////////// void PolylightEffect:: -cull_callback(CullTraverser *, CullTraverserData &data, +cull_callback(CullTraverser *trav, CullTraverserData &data, CPT(TransformState) &node_transform, CPT(RenderState) &node_state) const { - CPT(RenderAttrib) poly_light_attrib = do_poly_light(&data, node_transform); + CPT(RenderAttrib) poly_light_attrib = do_poly_light(trav->get_scene()->get_scene_root(), &data, node_transform); CPT(RenderState) poly_light_state = RenderState::make(poly_light_attrib); node_state = node_state->compose(poly_light_state); } @@ -123,7 +123,7 @@ cull_callback(CullTraverser *, CullTraverserData &data, // in respect to that light's proximity. //////////////////////////////////////////////////////////////////// CPT(RenderAttrib) PolylightEffect:: -do_poly_light(const CullTraverserData *data, const TransformState *node_transform) const { +do_poly_light(const NodePath & root, const CullTraverserData *data, const TransformState *node_transform) const { //static bool was_under_polylight = false; float dist; // To calculate the distance of each light from the node float r,g,b; // To hold the color calculation @@ -138,11 +138,9 @@ do_poly_light(const CullTraverserData *data, const TransformState *node_transfor Rcollect = Gcollect = Bcollect = 0.0; // get the avatar's base color scale - NodePath parent = data->_node_path.get_node_path().get_parent(); - Colorf scene_color = parent.get_color_scale(); + Colorf scene_color = root.get_color_scale(); if (polylight_info) { - pgraph_cat.info() << "parent node name " << parent.get_name() << endl; - pgraph_cat.info() << "parent color scale = " << scene_color << endl; + pgraph_cat.info() << "scene color scale = " << scene_color << endl; } min_dist = 100000.0; // Cycle through all the lights in this effect's lightgroup @@ -167,7 +165,16 @@ do_poly_light(const CullTraverserData *data, const TransformState *node_transfor dist = xz.length(); // this does not count height difference } + if (polylight_info) { + pgraph_cat.debug() << "light's position = " << light->get_pos() << endl; + pgraph_cat.debug() << "relative position = " << point << endl; + pgraph_cat.debug() << "effect center = " << _effect_center << endl; + //pgraph_cat.info() << "close to this light = " << light->get_name() << endl; + pgraph_cat.info() << "dist = " << dist << ";radius = " << light_radius << endl; + } + if (dist <= light_radius) { // If node is in range of this light + /* if (polylight_info) { pgraph_cat.debug() << "light's position = " << light->get_pos() << endl; pgraph_cat.debug() << "relative position = " << point << endl; @@ -175,6 +182,7 @@ do_poly_light(const CullTraverserData *data, const TransformState *node_transfor //pgraph_cat.info() << "close to this light = " << light->get_name() << endl; pgraph_cat.info() << "dist = " << dist << ";radius = " << light_radius << endl; } + */ PolylightNode::Attenuation_Type light_attenuation = light->get_attenuation(); Colorf light_color; diff --git a/panda/src/pgraph/polylightEffect.h b/panda/src/pgraph/polylightEffect.h index aca7557ebd..da1c3cbb6d 100755 --- a/panda/src/pgraph/polylightEffect.h +++ b/panda/src/pgraph/polylightEffect.h @@ -73,7 +73,7 @@ public: CPT(TransformState) &node_transform, CPT(RenderState) &node_state) const; - CPT(RenderAttrib) do_poly_light(const CullTraverserData *data, const TransformState *node_transform) const; + CPT(RenderAttrib) do_poly_light(const NodePath &root, const CullTraverserData *data, const TransformState *node_transform) const; virtual void output(ostream &out) const; diff --git a/panda/src/pgraph/polylightNode.cxx b/panda/src/pgraph/polylightNode.cxx index 4062b18d72..92e610ad3e 100755 --- a/panda/src/pgraph/polylightNode.cxx +++ b/panda/src/pgraph/polylightNode.cxx @@ -115,12 +115,12 @@ Colorf PolylightNode::flicker() const { } //variation += _offset; - variation *= _scale; + //variation *= _scale; //printf("Variation: %f\n",variation); - r+=variation; - g+=variation; - b+=variation; + r += r * variation; + g += g * variation; + b += b * variation; /* CLAMPING if (fabs(r - color[0]) > 0.5 || fabs(g - color[1]) > 0.5 || fabs(b - color[2]) > 0.5) {