2006-03-20 17:12:09 +00:00
|
|
|
/*
|
2014-06-01 17:55:23 +00:00
|
|
|
* Portions of this file are copyright Rebirth contributors and licensed as
|
|
|
|
* described in COPYING.txt.
|
|
|
|
* Portions of this file are copyright Parallax Software and licensed
|
|
|
|
* according to the Parallax license below.
|
|
|
|
* See COPYING.txt for license details.
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
|
|
|
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Lighting functions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
#include <algorithm>
|
2015-10-18 21:01:19 +00:00
|
|
|
#include <bitset>
|
2014-08-12 03:02:50 +00:00
|
|
|
#include <numeric>
|
2006-03-20 17:12:09 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h> // for memset()
|
|
|
|
|
2015-08-03 03:11:25 +00:00
|
|
|
#include "render_state.h"
|
2012-07-01 02:54:33 +00:00
|
|
|
#include "maths.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "vecmat.h"
|
|
|
|
#include "gr.h"
|
|
|
|
#include "inferno.h"
|
|
|
|
#include "segment.h"
|
2012-07-07 18:35:06 +00:00
|
|
|
#include "dxxerror.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "render.h"
|
|
|
|
#include "game.h"
|
|
|
|
#include "vclip.h"
|
|
|
|
#include "lighting.h"
|
|
|
|
#include "3d.h"
|
2011-04-07 20:32:51 +00:00
|
|
|
#include "interp.h"
|
2013-12-26 04:18:28 +00:00
|
|
|
#include "gameseg.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "laser.h"
|
|
|
|
#include "timer.h"
|
|
|
|
#include "player.h"
|
2011-04-07 20:32:51 +00:00
|
|
|
#include "playsave.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "weapon.h"
|
|
|
|
#include "powerup.h"
|
|
|
|
#include "fvi.h"
|
2014-11-23 04:36:58 +00:00
|
|
|
#include "object.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "robot.h"
|
|
|
|
#include "multi.h"
|
2011-04-07 20:32:51 +00:00
|
|
|
#include "palette.h"
|
|
|
|
#include "bm.h"
|
|
|
|
#include "rle.h"
|
2011-07-09 19:39:22 +00:00
|
|
|
#include "wall.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2014-10-12 23:05:46 +00:00
|
|
|
#include "compiler-range_for.h"
|
2014-12-05 03:08:10 +00:00
|
|
|
#include "partial_range.h"
|
2019-05-04 18:27:37 +00:00
|
|
|
#include "d_range.h"
|
2014-10-12 23:05:46 +00:00
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
using std::min;
|
|
|
|
|
2014-12-22 04:35:49 +00:00
|
|
|
static int Do_dynamic_light=1;
|
|
|
|
static int use_fcd_lighting;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
#define HEADLIGHT_CONE_DOT (F1_0*9/10)
|
|
|
|
#define HEADLIGHT_SCALE (F1_0*10)
|
|
|
|
|
2019-04-13 18:00:07 +00:00
|
|
|
namespace dcx {
|
|
|
|
|
2014-08-16 18:15:16 +00:00
|
|
|
static void add_light_div(g3s_lrgb &d, const g3s_lrgb &light, const fix &scale)
|
|
|
|
{
|
|
|
|
d.r += fixdiv(light.r, scale);
|
|
|
|
d.g += fixdiv(light.g, scale);
|
|
|
|
d.b += fixdiv(light.b, scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_light_dot_square(g3s_lrgb &d, const g3s_lrgb &light, const fix &dot)
|
|
|
|
{
|
|
|
|
auto square = fixmul(dot, dot);
|
|
|
|
d.r += fixmul(square, light.r)/8;
|
|
|
|
d.g += fixmul(square, light.g)/8;
|
|
|
|
d.b += fixmul(square, light.b)/8;
|
|
|
|
}
|
|
|
|
|
2019-04-13 18:00:07 +00:00
|
|
|
static fix compute_player_light_emission_intensity(const object_base &objp)
|
|
|
|
{
|
|
|
|
auto &phys_info = objp.mtype.phys_info;
|
|
|
|
const auto drag = phys_info.drag;
|
|
|
|
const fix k = fixmuldiv(phys_info.mass, drag, (F1_0 - drag));
|
|
|
|
// smooth thrust value like set_thrust_from_velocity()
|
|
|
|
const auto sthrust = vm_vec_copy_scale(phys_info.velocity, k);
|
|
|
|
return std::max(static_cast<fix>(vm_vec_mag_quick(sthrust) / 4), F2_0) + F0_5;
|
|
|
|
}
|
|
|
|
|
|
|
|
static fix compute_fireball_light_emission_intensity(const d_vclip_array &Vclip, const object_base &objp)
|
|
|
|
{
|
|
|
|
const auto oid = get_fireball_id(objp);
|
|
|
|
if (oid >= Vclip.size())
|
|
|
|
return 0;
|
|
|
|
auto &v = Vclip[oid];
|
|
|
|
const auto light_intensity = v.light_value;
|
|
|
|
if (objp.lifeleft < F1_0*4)
|
|
|
|
return fixmul(fixdiv(objp.lifeleft, v.play_time), light_intensity);
|
|
|
|
return light_intensity;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
// ----------------------------------------------------------------------------------------------
|
2016-08-25 04:05:32 +00:00
|
|
|
namespace dsx {
|
2017-07-26 03:15:59 +00:00
|
|
|
|
|
|
|
static void apply_light(fvmsegptridx &vmsegptridx, const g3s_lrgb obj_light_emission, const vcsegptridx_t obj_seg, const vms_vector &obj_pos, const unsigned n_render_vertices, array<unsigned, MAX_VERTICES> &render_vertices, const array<segnum_t, MAX_VERTICES> &vert_segnum_list, const icobjptridx_t objnum)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2011-04-07 20:32:51 +00:00
|
|
|
if (((obj_light_emission.r+obj_light_emission.g+obj_light_emission.b)/3) > 0)
|
|
|
|
{
|
|
|
|
fix obji_64 = ((obj_light_emission.r+obj_light_emission.g+obj_light_emission.b)/3)*64;
|
2011-09-26 17:03:20 +00:00
|
|
|
sbyte is_marker = 0;
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2017-01-31 04:25:06 +00:00
|
|
|
if (objnum && objnum->type == OBJ_MARKER)
|
2011-09-26 17:03:20 +00:00
|
|
|
is_marker = 1;
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2018-12-30 00:43:58 +00:00
|
|
|
auto &Dynamic_light = LevelUniqueLightState.Dynamic_light;
|
2018-12-30 00:43:57 +00:00
|
|
|
auto &Vertices = LevelSharedVertexState.get_vertices();
|
|
|
|
auto &vcvertptr = Vertices.vcptr;
|
2006-03-20 17:12:09 +00:00
|
|
|
// for pretty dim sources, only process vertices in object's own segment.
|
|
|
|
// 12/04/95, MK, markers only cast light in own segment.
|
2011-09-26 17:03:20 +00:00
|
|
|
if ((abs(obji_64) <= F1_0*8) || is_marker) {
|
2016-01-09 16:38:14 +00:00
|
|
|
auto &vp = obj_seg->verts;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-02-05 03:03:49 +00:00
|
|
|
range_for (const auto vertnum, vp)
|
2014-12-05 03:08:10 +00:00
|
|
|
{
|
2006-03-20 17:12:09 +00:00
|
|
|
fix dist;
|
2017-08-11 23:43:54 +00:00
|
|
|
auto &vertpos = *vcvertptr(vertnum);
|
2014-11-01 03:18:32 +00:00
|
|
|
dist = vm_vec_dist_quick(obj_pos, vertpos);
|
2013-04-18 09:56:32 +00:00
|
|
|
dist = fixmul(dist/4, dist/4);
|
|
|
|
if (dist < abs(obji_64)) {
|
|
|
|
if (dist < MIN_LIGHT_DIST)
|
|
|
|
dist = MIN_LIGHT_DIST;
|
|
|
|
|
2014-08-16 18:15:16 +00:00
|
|
|
add_light_div(Dynamic_light[vertnum], obj_light_emission, dist);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int headlight_shift = 0;
|
|
|
|
fix max_headlight_dist = F1_0*200;
|
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2017-01-31 04:25:06 +00:00
|
|
|
if (objnum)
|
2015-12-03 03:26:49 +00:00
|
|
|
{
|
2017-01-31 04:25:06 +00:00
|
|
|
const object &obj = *objnum;
|
|
|
|
if (obj.type == OBJ_PLAYER)
|
|
|
|
if (obj.ctype.player_info.powerup_flags & PLAYER_FLAGS_HEADLIGHT_ON) {
|
2011-09-26 17:03:20 +00:00
|
|
|
headlight_shift = 3;
|
2017-01-31 04:25:06 +00:00
|
|
|
if (get_player_id(obj) != Player_num)
|
2015-11-27 03:56:13 +00:00
|
|
|
{
|
2011-09-26 17:03:20 +00:00
|
|
|
fvi_query fq;
|
|
|
|
fvi_info hit_data;
|
|
|
|
int fate;
|
|
|
|
|
2017-01-31 04:25:06 +00:00
|
|
|
const auto tvec = vm_vec_scale_add(obj.pos, obj.orient.fvec, F1_0*200);
|
2011-09-26 17:03:20 +00:00
|
|
|
|
2017-01-31 04:25:06 +00:00
|
|
|
fq.startseg = obj_seg;
|
|
|
|
fq.p0 = &obj.pos;
|
2011-09-26 17:03:20 +00:00
|
|
|
fq.p1 = &tvec;
|
|
|
|
fq.rad = 0;
|
|
|
|
fq.thisobjnum = objnum;
|
2015-02-05 03:03:51 +00:00
|
|
|
fq.ignore_obj_list.first = nullptr;
|
2011-09-26 17:03:20 +00:00
|
|
|
fq.flags = FQ_TRANSWALL;
|
|
|
|
|
2015-01-20 02:46:42 +00:00
|
|
|
fate = find_vector_intersection(fq, hit_data);
|
2011-09-26 17:03:20 +00:00
|
|
|
if (fate != HIT_NONE)
|
2017-01-31 04:25:06 +00:00
|
|
|
max_headlight_dist = vm_vec_mag_quick(vm_vec_sub(hit_data.hit_pnt, obj.pos)) + F1_0*4;
|
2011-09-26 17:03:20 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
2015-12-03 03:26:49 +00:00
|
|
|
}
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2019-05-04 18:27:37 +00:00
|
|
|
range_for (const unsigned vv, xrange(n_render_vertices))
|
|
|
|
{
|
2006-03-20 17:12:09 +00:00
|
|
|
fix dist;
|
2011-07-09 19:39:22 +00:00
|
|
|
int apply_light = 0;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2017-02-19 19:33:38 +00:00
|
|
|
const auto vertnum = render_vertices[vv];
|
2014-11-20 03:00:36 +00:00
|
|
|
auto vsegnum = vert_segnum_list[vv];
|
2017-08-11 23:43:54 +00:00
|
|
|
auto &vertpos = *vcvertptr(vertnum);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-04-18 09:56:32 +00:00
|
|
|
if (use_fcd_lighting && abs(obji_64) > F1_0*32)
|
|
|
|
{
|
2017-06-10 03:31:02 +00:00
|
|
|
dist = find_connected_distance(obj_pos, obj_seg, vertpos, vmsegptridx(vsegnum), n_render_vertices, WID_RENDPAST_FLAG|WID_FLY_FLAG);
|
2013-04-18 09:56:32 +00:00
|
|
|
if (dist >= 0)
|
2011-07-09 19:39:22 +00:00
|
|
|
apply_light = 1;
|
2013-04-18 09:56:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-01 03:18:32 +00:00
|
|
|
dist = vm_vec_dist_quick(obj_pos, vertpos);
|
2013-04-18 09:56:32 +00:00
|
|
|
apply_light = 1;
|
|
|
|
}
|
2011-07-09 19:39:22 +00:00
|
|
|
|
2013-04-18 09:56:32 +00:00
|
|
|
if (apply_light && ((dist >> headlight_shift) < abs(obji_64))) {
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2013-04-18 09:56:32 +00:00
|
|
|
if (dist < MIN_LIGHT_DIST)
|
|
|
|
dist = MIN_LIGHT_DIST;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2017-01-31 04:25:06 +00:00
|
|
|
if (headlight_shift && objnum)
|
2013-04-18 09:56:32 +00:00
|
|
|
{
|
|
|
|
fix dot;
|
2014-10-29 03:24:31 +00:00
|
|
|
// MK, Optimization note: You compute distance about 15 lines up, this is partially redundant
|
2014-11-01 03:18:32 +00:00
|
|
|
const auto vec_to_point = vm_vec_normalized_quick(vm_vec_sub(vertpos, obj_pos));
|
2017-01-31 04:25:06 +00:00
|
|
|
dot = vm_vec_dot(vec_to_point, objnum->orient.fvec);
|
2013-04-18 09:56:32 +00:00
|
|
|
if (dot < F1_0/2)
|
|
|
|
{
|
|
|
|
// Do the normal thing, but darken around headlight.
|
2014-08-16 18:15:16 +00:00
|
|
|
add_light_div(Dynamic_light[vertnum], obj_light_emission, fixmul(HEADLIGHT_SCALE, dist));
|
2013-04-18 09:56:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-05 20:49:09 +00:00
|
|
|
if (!(Game_mode & GM_MULTI) || dist < max_headlight_dist)
|
2013-04-18 09:56:32 +00:00
|
|
|
{
|
2014-08-16 18:15:16 +00:00
|
|
|
add_light_dot_square(Dynamic_light[vertnum], obj_light_emission, dot);
|
2013-04-18 09:56:32 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
2013-04-18 09:56:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-16 18:15:16 +00:00
|
|
|
add_light_div(Dynamic_light[vertnum], obj_light_emission, dist);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-25 04:05:32 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2011-04-07 20:32:51 +00:00
|
|
|
#define FLASH_LEN_FIXED_SECONDS (F1_0/3)
|
|
|
|
#define FLASH_SCALE (3*F1_0/FLASH_LEN_FIXED_SECONDS)
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
2017-07-26 03:15:59 +00:00
|
|
|
static void cast_muzzle_flash_light(fvmsegptridx &vmsegptridx, int n_render_vertices, array<unsigned, MAX_VERTICES> &render_vertices, const array<segnum_t, MAX_VERTICES> &vert_segnum_list)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2010-12-10 23:18:17 +00:00
|
|
|
fix64 current_time;
|
2011-04-07 20:32:51 +00:00
|
|
|
short time_since_flash;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2010-12-10 23:18:17 +00:00
|
|
|
current_time = timer_query();
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-02-14 22:48:27 +00:00
|
|
|
range_for (auto &i, Muzzle_data)
|
2011-04-07 20:32:51 +00:00
|
|
|
{
|
2015-02-14 22:48:27 +00:00
|
|
|
if (i.create_time)
|
2011-04-07 20:32:51 +00:00
|
|
|
{
|
2015-02-14 22:48:27 +00:00
|
|
|
time_since_flash = current_time - i.create_time;
|
2006-03-20 17:12:09 +00:00
|
|
|
if (time_since_flash < FLASH_LEN_FIXED_SECONDS)
|
2011-04-07 20:32:51 +00:00
|
|
|
{
|
|
|
|
g3s_lrgb ml;
|
|
|
|
ml.r = ml.g = ml.b = ((FLASH_LEN_FIXED_SECONDS - time_since_flash) * FLASH_SCALE);
|
2017-07-26 03:15:59 +00:00
|
|
|
apply_light(vmsegptridx, ml, vmsegptridx(i.segnum), i.pos, n_render_vertices, render_vertices, vert_segnum_list, object_none);
|
2011-04-07 20:32:51 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
else
|
2011-04-07 20:32:51 +00:00
|
|
|
{
|
2015-02-14 22:48:27 +00:00
|
|
|
i.create_time = 0; // turn off this muzzle flash
|
2011-04-07 20:32:51 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-07 20:32:51 +00:00
|
|
|
// Translation table to make flares flicker at different rates
|
2015-04-02 02:36:52 +00:00
|
|
|
const array<fix, 16> Obj_light_xlate{{0x1234, 0x3321, 0x2468, 0x1735,
|
2011-04-07 20:32:51 +00:00
|
|
|
0x0123, 0x19af, 0x3f03, 0x232a,
|
|
|
|
0x2123, 0x39af, 0x0f03, 0x132a,
|
2015-04-02 02:36:52 +00:00
|
|
|
0x3123, 0x29af, 0x1f03, 0x032a
|
|
|
|
}};
|
2019-04-13 18:00:07 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
2019-04-13 18:00:07 +00:00
|
|
|
#define compute_player_light_emission_intensity(LevelUniqueHeadlightState, obj) compute_player_light_emission_intensity(obj)
|
2019-04-13 18:00:07 +00:00
|
|
|
#define compute_light_emission(LevelSharedRobotInfoState, LevelUniqueHeadlightState, Vclip, obj) compute_light_emission(Vclip, obj)
|
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
2019-04-13 18:00:07 +00:00
|
|
|
#undef compute_player_light_emission_intensity
|
2019-04-13 18:00:07 +00:00
|
|
|
#undef compute_light_emission
|
2017-03-11 19:56:25 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// ---------------------------------------------------------
|
2016-08-25 04:05:32 +00:00
|
|
|
namespace dsx {
|
2019-04-13 18:00:07 +00:00
|
|
|
|
2019-04-13 18:00:07 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
|
|
|
static fix compute_player_light_emission_intensity(d_level_unique_headlight_state &LevelUniqueHeadlightState, const object &objp)
|
|
|
|
{
|
|
|
|
if (objp.ctype.player_info.powerup_flags & PLAYER_FLAGS_HEADLIGHT_ON)
|
|
|
|
{
|
|
|
|
auto &Headlights = LevelUniqueHeadlightState.Headlights;
|
|
|
|
auto &Num_headlights = LevelUniqueHeadlightState.Num_headlights;
|
|
|
|
if (Num_headlights < Headlights.size())
|
|
|
|
Headlights[Num_headlights++] = &objp;
|
|
|
|
return HEADLIGHT_SCALE;
|
|
|
|
}
|
|
|
|
uint8_t hoard_orbs;
|
|
|
|
// If hoard game and player, add extra light based on how many orbs you have Pulse as well.
|
|
|
|
if (game_mode_hoard() && (hoard_orbs = objp.ctype.player_info.hoard.orbs))
|
|
|
|
{
|
|
|
|
const fix hoardlight = 1 + (i2f(hoard_orbs) / 2);
|
|
|
|
const auto s = fix_sin(static_cast<fix>(GameTime64 >> 1) & 0xFFFF); // probably a bad way to do it
|
|
|
|
return fixmul((s + F1_0) >> 1, hoardlight);
|
|
|
|
}
|
|
|
|
return compute_player_light_emission_intensity(objp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-04-13 18:00:07 +00:00
|
|
|
static g3s_lrgb compute_light_emission(const d_level_shared_robot_info_state &LevelSharedRobotInfoState, d_level_unique_headlight_state &LevelUniqueHeadlightState, const d_vclip_array &Vclip, const vcobjptridx_t obj)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2011-04-07 20:32:51 +00:00
|
|
|
int compute_color = 0;
|
2013-03-03 01:03:33 +00:00
|
|
|
fix light_intensity = 0;
|
2018-12-30 00:43:59 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
|
|
|
auto &Robot_info = LevelSharedRobotInfoState.Robot_info;
|
|
|
|
#endif
|
2019-04-13 18:00:07 +00:00
|
|
|
const object &objp = obj;
|
|
|
|
switch (objp.type)
|
2011-04-07 20:32:51 +00:00
|
|
|
{
|
2006-03-20 17:12:09 +00:00
|
|
|
case OBJ_PLAYER:
|
2019-04-13 18:00:07 +00:00
|
|
|
light_intensity = compute_player_light_emission_intensity(LevelUniqueHeadlightState, objp);
|
2006-03-20 17:12:09 +00:00
|
|
|
break;
|
|
|
|
case OBJ_FIREBALL:
|
2019-04-13 18:00:07 +00:00
|
|
|
light_intensity = compute_fireball_light_emission_intensity(Vclip, objp);
|
2006-03-20 17:12:09 +00:00
|
|
|
break;
|
|
|
|
case OBJ_ROBOT:
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
|
|
|
light_intensity = F1_0/2; // F1_0*Robot_info[obj->id].lightcast;
|
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
2019-04-13 18:00:07 +00:00
|
|
|
light_intensity = F1_0*Robot_info[get_robot_id(objp)].lightcast;
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
break;
|
2011-04-07 20:32:51 +00:00
|
|
|
case OBJ_WEAPON:
|
|
|
|
{
|
2019-04-13 18:00:07 +00:00
|
|
|
const auto wid = get_weapon_id(objp);
|
|
|
|
const fix tval = Weapon_info[wid].light;
|
|
|
|
if (wid == weapon_id_type::FLARE_ID)
|
|
|
|
light_intensity = 2 * (min(tval, objp.lifeleft) + ((static_cast<fix>(GameTime64) ^ Obj_light_xlate[obj.get_unchecked_index() % Obj_light_xlate.size()]) & 0x3fff));
|
2006-03-20 17:12:09 +00:00
|
|
|
else
|
2011-04-07 20:32:51 +00:00
|
|
|
light_intensity = tval;
|
|
|
|
break;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2011-04-07 20:32:51 +00:00
|
|
|
case OBJ_MARKER:
|
|
|
|
{
|
2019-04-13 18:00:07 +00:00
|
|
|
fix lightval = objp.lifeleft;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
lightval &= 0xffff;
|
|
|
|
lightval = 8 * abs(F1_0/2 - lightval);
|
|
|
|
|
2011-04-07 20:32:51 +00:00
|
|
|
light_intensity = lightval;
|
|
|
|
break;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
case OBJ_POWERUP:
|
2019-04-13 18:00:07 +00:00
|
|
|
light_intensity = Powerup_info[get_powerup_id(objp)].light;
|
2006-03-20 17:12:09 +00:00
|
|
|
break;
|
|
|
|
case OBJ_DEBRIS:
|
2011-04-07 20:32:51 +00:00
|
|
|
light_intensity = F1_0/4;
|
2006-03-20 17:12:09 +00:00
|
|
|
break;
|
|
|
|
case OBJ_LIGHT:
|
2019-04-13 18:00:07 +00:00
|
|
|
light_intensity = objp.ctype.light_info.intensity;
|
2006-03-20 17:12:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
2011-04-07 20:32:51 +00:00
|
|
|
light_intensity = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-03-12 04:01:08 +00:00
|
|
|
const auto &&white_light = [light_intensity] {
|
|
|
|
return g3s_lrgb{light_intensity, light_intensity, light_intensity};
|
|
|
|
};
|
2011-04-07 20:32:51 +00:00
|
|
|
|
|
|
|
if (!PlayerCfg.DynLightColor) // colored lights not desired so use intensity only OR no intensity (== no light == no color) at all
|
2019-03-12 04:01:08 +00:00
|
|
|
return white_light();
|
2011-04-07 20:32:51 +00:00
|
|
|
|
2019-04-13 18:00:07 +00:00
|
|
|
switch (objp.type) // find out if given object should cast colored light and compute if so
|
2011-04-07 20:32:51 +00:00
|
|
|
{
|
2016-11-20 23:12:00 +00:00
|
|
|
default:
|
|
|
|
break;
|
2011-04-07 20:32:51 +00:00
|
|
|
case OBJ_FIREBALL:
|
|
|
|
case OBJ_WEAPON:
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2011-04-07 20:32:51 +00:00
|
|
|
case OBJ_MARKER:
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2011-04-07 20:32:51 +00:00
|
|
|
compute_color = 1;
|
|
|
|
break;
|
|
|
|
case OBJ_POWERUP:
|
|
|
|
{
|
2019-04-13 18:00:07 +00:00
|
|
|
switch (get_powerup_id(objp))
|
2011-04-07 20:32:51 +00:00
|
|
|
{
|
|
|
|
case POW_EXTRA_LIFE:
|
|
|
|
case POW_ENERGY:
|
|
|
|
case POW_SHIELD_BOOST:
|
|
|
|
case POW_KEY_BLUE:
|
|
|
|
case POW_KEY_RED:
|
|
|
|
case POW_KEY_GOLD:
|
|
|
|
case POW_CLOAK:
|
|
|
|
case POW_INVULNERABILITY:
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2011-04-07 20:32:51 +00:00
|
|
|
case POW_HOARD_ORB:
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2011-04-07 20:32:51 +00:00
|
|
|
compute_color = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
break;
|
2011-04-07 20:32:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (compute_color)
|
|
|
|
{
|
2014-09-26 02:42:10 +00:00
|
|
|
int t_idx_s = -1, t_idx_e = -1;
|
2011-04-12 01:02:51 +00:00
|
|
|
|
2011-04-07 20:32:51 +00:00
|
|
|
if (light_intensity < F1_0) // for every effect we want color, increase light_intensity so the effect becomes barely visible
|
|
|
|
light_intensity = F1_0;
|
|
|
|
|
2019-03-12 04:01:08 +00:00
|
|
|
g3s_lrgb obj_color = { 255, 255, 255 };
|
2011-04-12 01:02:51 +00:00
|
|
|
|
2019-04-13 18:00:07 +00:00
|
|
|
switch (objp.render_type)
|
2011-04-12 01:02:51 +00:00
|
|
|
{
|
2011-06-20 09:30:12 +00:00
|
|
|
case RT_NONE:
|
|
|
|
break; // no object - no light
|
2011-04-12 01:02:51 +00:00
|
|
|
case RT_POLYOBJ:
|
|
|
|
{
|
2018-12-30 00:43:59 +00:00
|
|
|
auto &Polygon_models = LevelSharedPolygonModelState.Polygon_models;
|
2019-04-13 18:00:07 +00:00
|
|
|
const polymodel *const po = &Polygon_models[objp.rtype.pobj_info.model_num];
|
2011-04-12 01:02:51 +00:00
|
|
|
if (po->n_textures <= 0)
|
|
|
|
{
|
2014-07-24 03:12:57 +00:00
|
|
|
int color = g3_poly_get_color(po->model_data.get());
|
2011-04-12 01:02:51 +00:00
|
|
|
if (color)
|
|
|
|
{
|
2013-01-06 21:11:53 +00:00
|
|
|
obj_color.r = gr_current_pal[color].r;
|
|
|
|
obj_color.g = gr_current_pal[color].g;
|
|
|
|
obj_color.b = gr_current_pal[color].b;
|
2011-04-12 01:02:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
t_idx_s = ObjBitmaps[ObjBitmapPtrs[po->first_texture]].index;
|
|
|
|
t_idx_e = t_idx_s + po->n_textures - 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-05-05 18:45:24 +00:00
|
|
|
case RT_LASER:
|
|
|
|
{
|
2019-04-13 18:00:07 +00:00
|
|
|
t_idx_s = t_idx_e = Weapon_info[get_weapon_id(objp)].bitmap.index;
|
2011-05-05 18:45:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-06-01 13:49:06 +00:00
|
|
|
case RT_POWERUP:
|
|
|
|
{
|
2019-04-13 18:00:07 +00:00
|
|
|
auto &v = Vclip[objp.rtype.vclip_info.vclip_num];
|
|
|
|
auto &f = v.frames;
|
|
|
|
t_idx_s = f[0].index;
|
|
|
|
t_idx_e = f[v.num_frames - 1].index;
|
2011-06-01 13:49:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-04-12 01:02:51 +00:00
|
|
|
case RT_WEAPON_VCLIP:
|
|
|
|
{
|
2019-04-13 18:00:07 +00:00
|
|
|
auto &v = Vclip[Weapon_info[get_weapon_id(objp)].weapon_vclip];
|
|
|
|
auto &f = v.frames;
|
|
|
|
t_idx_s = f[0].index;
|
|
|
|
t_idx_e = f[v.num_frames - 1].index;
|
2011-04-12 01:02:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2019-04-13 18:00:07 +00:00
|
|
|
const auto &vc = Vclip[objp.id];
|
2015-11-27 03:56:13 +00:00
|
|
|
t_idx_s = vc.frames[0].index;
|
|
|
|
t_idx_e = vc.frames[vc.num_frames-1].index;
|
2011-04-12 01:02:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-04-07 20:32:51 +00:00
|
|
|
|
2011-04-12 01:02:51 +00:00
|
|
|
if (t_idx_s != -1 && t_idx_e != -1)
|
|
|
|
{
|
|
|
|
obj_color.r = obj_color.g = obj_color.b = 0;
|
2019-05-04 18:27:37 +00:00
|
|
|
range_for (const int i, xrange(t_idx_s, t_idx_e + 1))
|
2011-04-12 01:02:51 +00:00
|
|
|
{
|
|
|
|
grs_bitmap *bm = &GameBitmaps[i];
|
2011-06-04 08:04:39 +00:00
|
|
|
bitmap_index bi;
|
|
|
|
bi.index = i;
|
|
|
|
PIGGY_PAGE_IN(bi);
|
2011-04-12 01:02:51 +00:00
|
|
|
obj_color.r += bm->avg_color_rgb[0];
|
|
|
|
obj_color.g += bm->avg_color_rgb[1];
|
|
|
|
obj_color.b += bm->avg_color_rgb[2];
|
|
|
|
}
|
|
|
|
}
|
2011-04-07 20:32:51 +00:00
|
|
|
|
2019-03-12 04:01:08 +00:00
|
|
|
const fix rgbsum = obj_color.r + obj_color.g + obj_color.b;
|
2011-04-13 19:18:18 +00:00
|
|
|
// obviously this object did not give us any usable color. so let's do our own but with blackjack and hookers!
|
2019-03-12 04:01:08 +00:00
|
|
|
if (rgbsum <= 0)
|
|
|
|
return white_light();
|
2011-04-07 20:32:51 +00:00
|
|
|
// scale color to light intensity
|
2019-03-12 04:01:08 +00:00
|
|
|
const float cscale = static_cast<float>(light_intensity * 3) / rgbsum;
|
|
|
|
return g3s_lrgb{
|
|
|
|
static_cast<fix>(obj_color.r * cscale),
|
|
|
|
static_cast<fix>(obj_color.g * cscale),
|
|
|
|
static_cast<fix>(obj_color.b * cscale)
|
|
|
|
};
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
2011-04-07 20:32:51 +00:00
|
|
|
|
2019-03-12 04:01:08 +00:00
|
|
|
return white_light();
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------------
|
2014-08-12 02:28:03 +00:00
|
|
|
void set_dynamic_light(render_state_t &rstate)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2019-03-03 00:31:08 +00:00
|
|
|
auto &Objects = LevelUniqueObjectState.Objects;
|
|
|
|
auto &vcobjptridx = Objects.vcptridx;
|
2017-02-19 19:33:38 +00:00
|
|
|
array<unsigned, MAX_VERTICES> render_vertices;
|
2015-05-05 03:20:42 +00:00
|
|
|
array<segnum_t, MAX_VERTICES> vert_segnum_list;
|
2013-04-18 09:56:32 +00:00
|
|
|
static fix light_time;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2017-03-11 19:56:25 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2019-04-13 18:00:07 +00:00
|
|
|
LevelUniqueLightState.Num_headlights = 0;
|
2017-03-11 19:56:25 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
if (!Do_dynamic_light)
|
|
|
|
return;
|
|
|
|
|
2013-04-18 09:56:32 +00:00
|
|
|
light_time += FrameTime;
|
|
|
|
if (light_time < (F1_0/60)) // it's enough to stress the CPU 60 times per second
|
|
|
|
return;
|
|
|
|
light_time = light_time - (F1_0/60);
|
2011-06-04 08:04:39 +00:00
|
|
|
|
2015-10-18 21:01:19 +00:00
|
|
|
std::bitset<MAX_VERTICES> render_vertex_flags;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Create list of vertices that need to be looked at for setting of ambient light.
|
2018-12-30 00:43:58 +00:00
|
|
|
auto &Dynamic_light = LevelUniqueLightState.Dynamic_light;
|
2014-12-05 03:08:10 +00:00
|
|
|
uint_fast32_t n_render_vertices = 0;
|
2018-12-30 00:43:57 +00:00
|
|
|
auto &Vertices = LevelSharedVertexState.get_vertices();
|
2016-02-12 04:02:28 +00:00
|
|
|
range_for (const auto segnum, partial_const_range(rstate.Render_list, rstate.N_render_segs))
|
2014-12-05 03:08:10 +00:00
|
|
|
{
|
2013-12-26 22:21:16 +00:00
|
|
|
if (segnum != segment_none) {
|
2014-08-16 18:14:00 +00:00
|
|
|
auto &vp = Segments[segnum].verts;
|
2015-02-05 03:03:49 +00:00
|
|
|
range_for (const auto vnum, vp)
|
2014-12-05 03:08:10 +00:00
|
|
|
{
|
2018-12-30 00:43:57 +00:00
|
|
|
if (vnum > Vertices.get_count() - 1)
|
2017-02-19 19:33:37 +00:00
|
|
|
{
|
2006-03-20 17:12:09 +00:00
|
|
|
Int3(); //invalid vertex number
|
|
|
|
continue; //ignore it, and go on to next one
|
|
|
|
}
|
2015-10-18 21:01:19 +00:00
|
|
|
auto &&b = render_vertex_flags[vnum];
|
|
|
|
if (!b)
|
|
|
|
{
|
|
|
|
b = true;
|
2011-07-09 19:39:22 +00:00
|
|
|
render_vertices[n_render_vertices] = vnum;
|
|
|
|
vert_segnum_list[n_render_vertices] = segnum;
|
|
|
|
n_render_vertices++;
|
2015-10-18 21:01:19 +00:00
|
|
|
Dynamic_light[vnum] = {};
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-26 03:15:59 +00:00
|
|
|
cast_muzzle_flash_light(vmsegptridx, n_render_vertices, render_vertices, vert_segnum_list);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2019-03-03 00:31:08 +00:00
|
|
|
range_for (const auto &&obj, vcobjptridx)
|
2011-04-12 01:02:51 +00:00
|
|
|
{
|
2019-03-12 04:01:08 +00:00
|
|
|
const object &objp = obj;
|
|
|
|
if (objp.type == OBJ_NONE)
|
|
|
|
continue;
|
2019-04-13 18:00:07 +00:00
|
|
|
const auto &&obj_light_emission = compute_light_emission(LevelSharedRobotInfoState, LevelUniqueLightState, Vclip, obj);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2011-04-12 01:02:51 +00:00
|
|
|
if (((obj_light_emission.r+obj_light_emission.g+obj_light_emission.b)/3) > 0)
|
2019-04-13 18:00:07 +00:00
|
|
|
apply_light(vmsegptridx, obj_light_emission, vcsegptridx(objp.segnum), objp.pos, n_render_vertices, render_vertices, vert_segnum_list, obj);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------
|
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2017-03-11 19:56:25 +00:00
|
|
|
|
2017-04-22 21:23:55 +00:00
|
|
|
void toggle_headlight_active(object &player)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2017-04-22 21:23:55 +00:00
|
|
|
auto &player_info = player.ctype.player_info;
|
2016-10-02 00:34:40 +00:00
|
|
|
if (player_info.powerup_flags & PLAYER_FLAGS_HEADLIGHT) {
|
|
|
|
player_info.powerup_flags ^= PLAYER_FLAGS_HEADLIGHT_ON;
|
2006-03-20 17:12:09 +00:00
|
|
|
if (Game_mode & GM_MULTI)
|
2017-04-22 21:23:55 +00:00
|
|
|
multi_send_flags(player.id);
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-13 18:00:07 +00:00
|
|
|
static fix compute_headlight_light_on_object(const d_level_unique_headlight_state &LevelUniqueHeadlightState, const object_base &objp)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
fix light;
|
|
|
|
|
|
|
|
// Let's just illuminate players and robots for speed reasons, ok?
|
2016-04-23 17:59:47 +00:00
|
|
|
if (objp.type != OBJ_ROBOT && objp.type != OBJ_PLAYER)
|
2006-03-20 17:12:09 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
light = 0;
|
|
|
|
|
2019-04-13 18:00:07 +00:00
|
|
|
range_for (const object_base *const light_objp, partial_const_range(LevelUniqueHeadlightState.Headlights, LevelUniqueHeadlightState.Num_headlights))
|
2015-02-14 22:48:27 +00:00
|
|
|
{
|
2016-04-23 17:59:47 +00:00
|
|
|
auto vec_to_obj = vm_vec_sub(objp.pos, light_objp->pos);
|
2019-04-13 18:00:07 +00:00
|
|
|
const fix dist = vm_vec_normalize_quick(vec_to_obj);
|
2006-03-20 17:12:09 +00:00
|
|
|
if (dist > 0) {
|
2019-04-13 18:00:07 +00:00
|
|
|
const fix dot = vm_vec_dot(light_objp->orient.fvec, vec_to_obj);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
if (dot < F1_0/2)
|
|
|
|
light += fixdiv(HEADLIGHT_SCALE, fixmul(HEADLIGHT_SCALE, dist)); // Do the normal thing, but darken around headlight.
|
|
|
|
else
|
|
|
|
light += fixmul(fixmul(dot, dot), HEADLIGHT_SCALE)/8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return light;
|
|
|
|
}
|
2019-04-13 18:00:07 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2017-03-11 19:56:25 +00:00
|
|
|
}
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
//compute the average dynamic light in a segment. Takes the segment number
|
2019-04-13 18:00:07 +00:00
|
|
|
static g3s_lrgb compute_seg_dynamic_light(const array<g3s_lrgb, MAX_VERTICES> &Dynamic_light, const shared_segment &seg)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2018-12-30 00:43:58 +00:00
|
|
|
const auto &&op = [&Dynamic_light](g3s_lrgb r, const unsigned v) {
|
2014-08-12 03:02:50 +00:00
|
|
|
r.r += Dynamic_light[v].r;
|
|
|
|
r.g += Dynamic_light[v].g;
|
|
|
|
r.b += Dynamic_light[v].b;
|
|
|
|
return r;
|
|
|
|
};
|
2017-11-05 20:49:09 +00:00
|
|
|
g3s_lrgb sum = std::accumulate(begin(seg.verts), end(seg.verts), g3s_lrgb{0, 0, 0}, op);
|
2015-10-18 21:01:19 +00:00
|
|
|
sum.r >>= 3;
|
|
|
|
sum.g >>= 3;
|
|
|
|
sum.b >>= 3;
|
|
|
|
return sum;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2015-08-12 03:11:46 +00:00
|
|
|
static array<g3s_lrgb, MAX_OBJECTS> object_light;
|
2015-03-22 18:49:21 +00:00
|
|
|
static array<object_signature_t, MAX_OBJECTS> object_sig;
|
2018-09-25 03:44:09 +00:00
|
|
|
const object *old_viewer;
|
2015-08-12 03:11:46 +00:00
|
|
|
static int reset_lighting_hack;
|
2011-04-07 20:32:51 +00:00
|
|
|
#define LIGHT_RATE i2f(4) //how fast the light ramps up
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2018-09-25 03:44:09 +00:00
|
|
|
void start_lighting_frame(const object &viewer)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2018-09-25 03:44:09 +00:00
|
|
|
reset_lighting_hack = (&viewer != old_viewer);
|
|
|
|
old_viewer = &viewer;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2019-04-13 18:00:07 +00:00
|
|
|
namespace dsx {
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
//compute the lighting for an object. Takes a pointer to the object,
|
|
|
|
//and possibly a rotated 3d point. If the point isn't specified, the
|
|
|
|
//object's center point is rotated.
|
2019-04-13 18:00:07 +00:00
|
|
|
g3s_lrgb compute_object_light(const d_level_unique_light_state &LevelUniqueLightState, const vcobjptridx_t obj)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2017-03-11 19:56:24 +00:00
|
|
|
g3s_lrgb light;
|
|
|
|
const vcobjidx_t objnum = obj;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2011-04-07 20:32:51 +00:00
|
|
|
//First, get static (mono) light for this segment
|
2015-10-18 21:01:19 +00:00
|
|
|
const auto &&objsegp = vcsegptr(obj->segnum);
|
|
|
|
light.r = light.g = light.b = objsegp->static_light;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2017-03-11 19:56:24 +00:00
|
|
|
auto &os = object_sig[objnum];
|
|
|
|
auto &ol = object_light[objnum];
|
2006-03-20 17:12:09 +00:00
|
|
|
//Now, maybe return different value to smooth transitions
|
2017-03-11 19:56:24 +00:00
|
|
|
if (!reset_lighting_hack && os == obj->signature)
|
2011-04-07 20:32:51 +00:00
|
|
|
{
|
|
|
|
fix frame_delta;
|
|
|
|
g3s_lrgb delta_light;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2017-03-11 19:56:24 +00:00
|
|
|
delta_light.r = light.r - ol.r;
|
|
|
|
delta_light.g = light.g - ol.g;
|
|
|
|
delta_light.b = light.b - ol.b;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
frame_delta = fixmul(LIGHT_RATE,FrameTime);
|
|
|
|
|
2011-04-07 20:32:51 +00:00
|
|
|
if (abs(((delta_light.r+delta_light.g+delta_light.b)/3)) <= frame_delta)
|
|
|
|
{
|
2017-03-11 19:56:24 +00:00
|
|
|
ol = light; //we've hit the goal
|
2011-04-07 20:32:51 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
else
|
2011-04-07 20:32:51 +00:00
|
|
|
{
|
|
|
|
if (((delta_light.r+delta_light.g+delta_light.b)/3) < 0)
|
2017-03-11 19:56:24 +00:00
|
|
|
frame_delta = -frame_delta;
|
|
|
|
ol.r += frame_delta;
|
|
|
|
ol.g += frame_delta;
|
|
|
|
ol.b += frame_delta;
|
|
|
|
light = ol;
|
2011-04-07 20:32:51 +00:00
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
}
|
2011-04-07 20:32:51 +00:00
|
|
|
else //new object, initialize
|
|
|
|
{
|
2017-03-11 19:56:24 +00:00
|
|
|
os = obj->signature;
|
|
|
|
ol = light;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2017-03-11 19:56:24 +00:00
|
|
|
//Finally, add in dynamic light for this segment
|
2018-12-30 00:43:58 +00:00
|
|
|
auto &Dynamic_light = LevelUniqueLightState.Dynamic_light;
|
|
|
|
const auto &&seg_dl = compute_seg_dynamic_light(Dynamic_light, objsegp);
|
2017-03-11 19:56:25 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2011-04-07 20:32:51 +00:00
|
|
|
//Next, add in (NOTE: WHITE) headlight on this object
|
2019-04-13 18:00:07 +00:00
|
|
|
const fix mlight = compute_headlight_light_on_object(LevelUniqueLightState, obj);
|
2011-04-07 20:32:51 +00:00
|
|
|
light.r += mlight;
|
|
|
|
light.g += mlight;
|
|
|
|
light.b += mlight;
|
2017-03-11 19:56:25 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2011-04-07 20:32:51 +00:00
|
|
|
light.r += seg_dl.r;
|
|
|
|
light.g += seg_dl.g;
|
|
|
|
light.b += seg_dl.b;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
return light;
|
|
|
|
}
|
2019-04-13 18:00:07 +00:00
|
|
|
|
|
|
|
}
|