This commit is contained in:
David Rose 2004-06-14 21:40:51 +00:00
parent 7a50b49b13
commit 1cb510e7c1
5 changed files with 79 additions and 79 deletions

View File

@ -155,7 +155,7 @@ get_weight() const {
// _contribution_type is a string that controls how
// this division occurs.
// "proximal" : A light only contributes if the node
// is inside its volume
// is inside its volume
// "all" : All lights added to the effect are used in
// division irrespective of their light volumes
////////////////////////////////////////////////////////////////////

View File

@ -60,55 +60,55 @@ do_poly_light(const CullTraverserData *data, const TransformState *node_transfor
// Cycle through all the lights in this effect's lightgroup
for (light_iter = _lightgroup.begin(); light_iter != _lightgroup.end(); light_iter++){
const PolylightNode *light = DCAST(PolylightNode,light_iter->second->node());
// light holds the current PolylightNode
if(light->is_enabled()) { // if enabled get all the properties
float light_radius = light->get_radius();
string light_attenuation = light->get_attenuation();
float light_a0 = light->get_a0();
float light_a1 = light->get_a1();
float light_a2 = light->get_a2();
if(light_a0 == 0 && light_a1 == 0 && light_a2 == 0) { // To prevent division by zero
// light holds the current PolylightNode
if(light->is_enabled()) { // if enabled get all the properties
float light_radius = light->get_radius();
string light_attenuation = light->get_attenuation();
float light_a0 = light->get_a0();
float light_a1 = light->get_a1();
float light_a2 = light->get_a2();
if(light_a0 == 0 && light_a1 == 0 && light_a2 == 0) { // To prevent division by zero
light_a0 = 1.0;
}
Colorf light_color;
if(light->is_flickering()) { // If flickering, modify color
light_color = light->flicker();
}
else {
light_color = light->get_color();
}
// Calculate the distance of the node from the light
dist = light_iter->second->get_distance(data->_node_path.get_node_path());
}
Colorf light_color;
if(light->is_flickering()) { // If flickering, modify color
light_color = light->flicker();
}
else {
light_color = light->get_color();
}
// Calculate the distance of the node from the light
dist = light_iter->second->get_distance(data->_node_path.get_node_path());
if(dist < light_radius) { // If node is in range of this light
if(light_attenuation == "linear") {
light_scale = (light_radius - dist)/light_radius;
}
else if(light_attenuation == "quadratic") {
fd = 1.0 / (light_a0 + light_a1 * dist + light_a2 * dist * dist);
if(fd<1.0) {
light_scale=fd;
}
else {
light_scale=1.0;
}
}
if(dist < light_radius) { // If node is in range of this light
if(light_attenuation == "linear") {
light_scale = (light_radius - dist)/light_radius;
}
else if(light_attenuation == "quadratic") {
fd = 1.0 / (light_a0 + light_a1 * dist + light_a2 * dist * dist);
if(fd<1.0) {
light_scale=fd;
}
else {
light_scale=1.0;
}
}
// Keep accumulating each lights contribution... we divide by
// number of lights later.
Rcollect += light_color[0] * light_scale;
Gcollect += light_color[1] * light_scale;
Bcollect += light_color[2] * light_scale;
num_lights++;
} // if dist< radius
} // if light is enabled
// number of lights later.
Rcollect += light_color[0] * light_scale;
Gcollect += light_color[1] * light_scale;
Bcollect += light_color[2] * light_scale;
num_lights++;
} // if dist< radius
} // if light is enabled
} // for all lights
if( _contribution_type == "all") {
// Sometimes to prevent snapping of color at light volume boundaries
// just divide total contribution by all the lights in the effect
// whether or not they contribute color
// just divide total contribution by all the lights in the effect
// whether or not they contribute color
num_lights = _lightgroup.size();
}
@ -148,7 +148,7 @@ compare_to_impl(const RenderEffect *other) const {
DCAST_INTO_R(ta, other, 0);
if (_enabled != ta->_enabled) {
return _enabled ? 1 : -1;
return _enabled ? 1 : -1;
}
if (_contribution_type != ta->_contribution_type) {
@ -156,7 +156,7 @@ compare_to_impl(const RenderEffect *other) const {
}
if (_weight != ta->_weight) {
return _weight < ta->_weight ? -1 :1;
return _weight < ta->_weight ? -1 :1;
}
if (_lightgroup != ta->_lightgroup) {

View File

@ -33,10 +33,10 @@
////////////////////////////////////////////////////////////////////
// Class : PolylightEffect
// Description : A PolylightEffect can be used on a node to define a
// LightGroup for that node. A LightGroup contains
// LightGroup for that node. A LightGroup contains
// Polylights which are essentially nodes that add
// color to the polygons of a model based on distance.
// PolylightNode is a cheap way to get lighting effects
// color to the polygons of a model based on distance.
// PolylightNode is a cheap way to get lighting effects
// specially for night scenes
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA PolylightEffect : public RenderEffect {

View File

@ -83,27 +83,27 @@ Colorf PolylightNode::flicker() const {
if(_flicker_type == "random") {
//srand((int)ClockObject::get_global_clock()->get_frame_time());
variation = (rand()%100);// * ClockObject::get_global_clock()->get_dt();
variation /= 100.0;
//printf("Random Variation: %f\n",variation);
variation += _offset;
variation *= _scale;
variation /= 100.0;
//printf("Random Variation: %f\n",variation);
variation += _offset;
variation *= _scale;
}
else if(_flicker_type == "sin") {
double now = ClockObject::get_global_clock()->get_frame_time();
double now = ClockObject::get_global_clock()->get_frame_time();
variation = sinf(now*_sin_freq);// * ClockObject::get_global_clock()->get_dt();
//printf("Variation: %f\n",variation);
variation += _offset;
variation *= _scale;
//printf("Variation: %f\n",variation);
variation += _offset;
variation *= _scale;
}
else if(_flicker_type == "fixed_point") {
// fixed point list of variation values coming soon...
//double index = (ClockObject::get_global_clock()->get_frame_time() % len(fixed_points)) * ClockObject::get_global_clock()->get_dt();
//index *= _speed;
/*if(!(int)index > len(fixed_points) {
variation = _fixed_points[(int)index];
variation += _offset;
variation *= _scale;
}*/
//index *= _speed;
/*if(!(int)index > len(fixed_points) {
variation = _fixed_points[(int)index];
variation += _offset;
variation *= _scale;
}*/
}
//printf("Variation: %f\n",variation);
r+=variation;
@ -130,7 +130,7 @@ Colorf PolylightNode::flicker() const {
//
// Two PolylightNodes are considered equivalent if they
// consist of exactly the same properties
// Otherwise, they are different; different
// Otherwise, they are different; different
// PolylightNodes will be ranked in a consistent but
// undefined ordering; the ordering is useful only for
// placing the PolylightNodes in a sorted container like an
@ -140,62 +140,62 @@ int PolylightNode::
compare_to(const PolylightNode &other) const {
if (_enabled != other._enabled) {
return _enabled ? 1 :-1;
return _enabled ? 1 :-1;
}
if (_radius != other._radius) {
return _radius < other._radius ? -1 :1;
return _radius < other._radius ? -1 :1;
}
LVecBase3f position = get_pos();
LVecBase3f other_position = other.get_pos();
if (position != other_position) {
return position < other_position ? -1 :1;
return position < other_position ? -1 :1;
}
Colorf color = get_color();
Colorf other_color = other.get_color();
if (color != other_color) {
return color < other_color ? -1 :1;
return color < other_color ? -1 :1;
}
if (_attenuation_type != other._attenuation_type) {
return _attenuation_type < other._attenuation_type ? -1 :1;
return _attenuation_type < other._attenuation_type ? -1 :1;
}
if (_a0 != other._a0) {
return _a0 < other._a0 ? -1 :1;
return _a0 < other._a0 ? -1 :1;
}
if (_a1 != other._a1) {
return _a1 < other._a1 ? -1 :1;
return _a1 < other._a1 ? -1 :1;
}
if (_a2 != other._a2) {
return _a2 < other._a2 ? -1 :1;
return _a2 < other._a2 ? -1 :1;
}
if (_flickering != other._flickering) {
return _flickering ? 1 :-1;
return _flickering ? 1 :-1;
}
if (_flicker_type != other._flicker_type) {
return _flicker_type < other._flicker_type ? -1 :1;
return _flicker_type < other._flicker_type ? -1 :1;
}
if (_offset != other._offset) {
return _offset < other._offset ? -1 :1;
return _offset < other._offset ? -1 :1;
}
if (_scale != other._scale) {
return _scale < other._scale ? -1 :1;
return _scale < other._scale ? -1 :1;
}
if (_step_size != other._step_size) {
return _step_size < other._step_size ? -1 :1;
return _step_size < other._step_size ? -1 :1;
}
if (_sin_freq != other._sin_freq) {
return _sin_freq < other._sin_freq ? -1 :1;
return _sin_freq < other._sin_freq ? -1 :1;
}

View File

@ -38,9 +38,9 @@ class EXPCL_PANDA PolylightNode : public PandaNode{
PUBLISHED:
PolylightNode(const string &name, float x = 0.0, float y = 0.0, float z = 0.0,
float r = 1.0, float g = 1.0, float b = 1.0,
float radius=50.0, string attenuation_type= "linear",
bool flickering =false, string flicker_type="random");
float r = 1.0, float g = 1.0, float b = 1.0,
float radius=50.0, string attenuation_type= "linear",
bool flickering =false, string flicker_type="random");
INLINE void enable();
INLINE void disable();
INLINE void set_pos(float x,float y, float z);