MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ApplyLightingToObjects

Function ApplyLightingToObjects

Descent3/lighting.cpp:992–1051  ·  view source on GitHub ↗

Applies lighting to all objects in a certain distance

Source from the content-addressed store, hash-verified

990
991// Applies lighting to all objects in a certain distance
992void ApplyLightingToObjects(vector *pos, int roomnum, float light_dist, float red_scale, float green_scale,
993 float blue_scale, vector *light_direction, float dot_range) {
994 int16_t objlist[MAX_DYNAMIC_FACES];
995 int num_objects, i;
996 float normalized_time[MAX_SUBOBJECTS];
997
998 num_objects = fvi_QuickDistObjectList(pos, roomnum, light_dist, objlist, MAX_DYNAMIC_FACES, false, false, true);
999
1000 for (i = 0; i < num_objects; i++) {
1001 object *obj = &Objects[objlist[i]];
1002
1003 if (obj->type == OBJ_ROOM) {
1004 ApplyLightingToExternalRoom(pos, obj->id, light_dist, red_scale, green_scale, blue_scale, light_direction,
1005 dot_range);
1006 continue;
1007 }
1008
1009 if (obj->renderframe != ((FrameCount - 1) % 65536)) {
1010 if (obj != Viewer_object)
1011 continue;
1012 }
1013
1014 if (obj->lm_object.used == 0) {
1015 if (obj->effect_info && ((obj->effect_info->type_flags & EF_VOLUME_LIT) ||
1016 obj->lighting_render_type == LRT_GOURAUD || obj->type == OBJ_POWERUP)) {
1017 ApplyVolumeLightToObject(pos, obj, light_dist, red_scale, green_scale, blue_scale, light_direction, dot_range);
1018 continue;
1019 } else
1020 continue;
1021 }
1022
1023 int model_num = obj->rtype.pobj_info.model_num;
1024 poly_model *pm = &Poly_models[model_num];
1025
1026 // Set our light position
1027 Light_position = *pos;
1028
1029 // Set up light direction if this is a directional light
1030 if (light_direction) {
1031 Light_direction = *light_direction;
1032 Use_light_direction = 1;
1033 } else
1034 Use_light_direction = 0;
1035
1036 StartLightingInstance(&obj->pos, &obj->orient);
1037
1038 // Now, get the lights position in the objects submodel space
1039 SetNormalizedTimeObj(obj, normalized_time);
1040 SetModelAnglesAndPos(pm, normalized_time);
1041
1042 for (int t = 0; t < pm->n_models; t++) {
1043 bsp_info *sm = &pm->submodel[t];
1044 if (sm->parent == -1)
1045 ApplyLightingToSubmodel(obj, pm, sm, light_dist, red_scale, green_scale, blue_scale, dot_range);
1046 }
1047
1048 DoneLightingInstance();
1049 ASSERT(Light_instance_depth == 0);

Callers 2

ApplyLightingToRoomsFunction · 0.85
ApplyLightingToTerrainFunction · 0.85

Calls 8

fvi_QuickDistObjectListFunction · 0.85
ApplyVolumeLightToObjectFunction · 0.85
StartLightingInstanceFunction · 0.85
SetNormalizedTimeObjFunction · 0.85
SetModelAnglesAndPosFunction · 0.85
ApplyLightingToSubmodelFunction · 0.85
DoneLightingInstanceFunction · 0.85

Tested by

no test coverage detected