Skip to content

Commit

Permalink
Merge pull request #6484 from Kestrellius/weapon-light-followup
Browse files Browse the repository at this point in the history
Weapon light followup
  • Loading branch information
Goober5000 authored Dec 25, 2024
2 parents 82304a2 + 2375ea3 commit 7c82072
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 28 deletions.
33 changes: 23 additions & 10 deletions code/graphics/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ void hdr_color::set_rgb(int new_r, int new_g, int new_b)
this->blue = i2fl(new_b) / 255.0f;
}

/**
* @brief Sets RGB values from three 0.0-1.0 floats
*/
void hdr_color::set_rgb(float new_r, float new_g, float new_b)
{
this->red = new_r;
this->green = new_g;
this->blue = new_b;
}

/**
* @brief Sets RGBA values from an old style color object
*/
Expand All @@ -97,6 +87,29 @@ void hdr_color::set_rgb(const int* const new_rgb)
this->set_rgb(new_rgb[0], new_rgb[1], new_rgb[2]);
}

/**
* @brief Sets RGBAI values from five 0.0-1.0 floats
*/
void hdr_color::set_rgbai(float new_r, float new_g, float new_b, float new_a, float new_i)
{
this->red = new_r;
this->green = new_g;
this->blue = new_b;
this->alpha = new_a;
this->intensity = new_i;
}

/**
* @brief Multiplies RGBAI values with five 0.0-1.0 floats
*/
void hdr_color::multiply_rgbai(float r_mult, float g_mult, float b_mult, float a_mult, float i_mult)
{
this->red *= r_mult;
this->green *= g_mult;
this->blue *= b_mult;
this->alpha *= a_mult;
this->intensity *= i_mult;
}

/**
* @brief retreives unmultiplied 0.0f-1.0f color component.
Expand Down
3 changes: 2 additions & 1 deletion code/graphics/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class hdr_color{
void set_vecf(const SCP_vector<float>& input);

void set_rgb(const int new_r,const int new_g,const int new_b);
void set_rgb(const float new_r,const float new_g,const float new_b);
void set_rgb(const color* const new_rgb);
void set_rgb(const int* const new_rgb);
void set_rgbai(const float new_r,const float new_g,const float new_b,const float new_a = 1.f,const float new_i = 1.f);
void multiply_rgbai(const float r_mult,const float g_mult,const float b_mult,const float a_mult = 1.f,const float i_mult = 1.f);

float r() const;
float r(const float in);
Expand Down
38 changes: 21 additions & 17 deletions code/object/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1264,31 +1264,35 @@ void obj_move_all_post(object *objp, float frametime)
float g_mult = wi->weapon_curves.get_output(weapon_info::WeaponCurveOutputs::LIGHT_G_MULT, *wp, &wp->modular_curves_instance);
float b_mult = wi->weapon_curves.get_output(weapon_info::WeaponCurveOutputs::LIGHT_B_MULT, *wp, &wp->modular_curves_instance);

float source_radius = objp->radius;
float light_radius;
float light_brightness;

// Handle differing adjustments depending on weapon type.
if (wi->render_type == WRT_LASER) {
light_radius = lp->laser_light_radius.handle(wi->light_radius) * radius_mult;
// intensity is stored in the light color even if no user setting is done.
light_brightness = lp->laser_light_brightness.handle(wi->light_color.i());
} else {
// Missiles should typically not be treated as lights for their whole radius. TODO: make configurable.
source_radius *= 0.05f;
light_radius = lp->missile_light_radius.handle(wi->light_radius) * radius_mult;
light_brightness = lp->missile_light_brightness.handle(wi->light_color.i());
}

// If there is no specific color set in the table, laser render weapons have a dynamic color.
if (!wi->light_color_set && wi->render_type == WRT_LASER) {
// Classic dynamic laser color is handled with an old color object
color c;
weapon_get_laser_color(&c, objp);
light_color.set_rgb((c.red/255.f) * r_mult, (c.green/255.f) * g_mult, (c.blue/255.f) * b_mult);
// intensity is stored in the light color even if no user setting is done.
light_color.i(wi->light_color.i() * intensity_mult);
light_color.set_rgbai((c.red/255.f), (c.green/255.f), (c.blue/255.f), 1.f, light_brightness);
} else {
// If not a laser then all default information needed is stored in the weapon light color
light_color.set_rgb(wi->light_color.r() * r_mult, wi->light_color.g() * g_mult, wi->light_color.b() * b_mult);
}
//handles both defaults and adjustments.
float light_radius = wi->light_radius;
float source_radius = objp->radius;
if (wi->render_type == WRT_LASER) {
light_radius = lp->laser_light_radius.handle(light_radius) * radius_mult;
light_color.i(lp->laser_light_brightness.handle(light_color.i()) * intensity_mult);
} else {
//Missiles should typically not be treated as lights for their whole radius. TODO: make configurable.
source_radius *= 0.05f;
light_radius = lp->missile_light_radius.handle(light_radius) * radius_mult;
light_color.i(lp->missile_light_brightness.handle(light_color.i()) * intensity_mult);
light_color.set_rgb(light_color.r() * r_mult, light_color.g() * g_mult, light_color.b() * b_mult);
light_color.set_rgbai(wi->light_color.r(), wi->light_color.g(), wi->light_color.b(), 1.f, light_brightness);
}

light_color.multiply_rgbai(r_mult, g_mult, b_mult, 1.f, intensity_mult);

if(light_radius > 0.0f && intensity_mult > 0.0f && light_color.i() > 0.0f)
light_add_point(&objp->pos, light_radius, light_radius, &light_color, source_radius);
}
Expand Down

0 comments on commit 7c82072

Please sign in to comment.