Sets up the light states for an outdoor object to be rendered
| 1042 | } |
| 1043 | // Sets up the light states for an outdoor object to be rendered |
| 1044 | bool SetupTerrainObject(object *obj) { |
| 1045 | vector camlight = Terrain_sky.lightsource; |
| 1046 | vm_NormalizeVector(&camlight); |
| 1047 | #ifdef EDITOR |
| 1048 | if (!Terrain_render_ext_room_objs) |
| 1049 | return false; |
| 1050 | #endif |
| 1051 | |
| 1052 | obj->flags |= OF_SAFE_TO_RENDER; |
| 1053 | RenderObject_SetLightDirection(&camlight); |
| 1054 | rend_SetColorModel(CM_MONO); |
| 1055 | if (obj->render_type == RT_POLYOBJ || |
| 1056 | (obj->render_type == RT_WEAPON && |
| 1057 | !((Weapons[obj->id].flags & WF_IMAGE_BITMAP) || (Weapons[obj->id].flags & WF_IMAGE_VCLIP)))) { |
| 1058 | float scalar_r, scalar_g, scalar_b, scalar; |
| 1059 | if (obj->type == OBJ_POWERUP) { |
| 1060 | scalar = 1.0; |
| 1061 | scalar_r = 1.0; |
| 1062 | scalar_g = 1.0; |
| 1063 | scalar_b = 1.0; |
| 1064 | } else { |
| 1065 | scalar = GetTerrainDynamicScalar(&obj->pos, CELLNUM(obj->roomnum)); |
| 1066 | if (obj->effect_info && (obj->effect_info->type_flags & EF_VOLUME_LIT)) { |
| 1067 | scalar_r = std::min<float>(1, scalar + (obj->effect_info->dynamic_red)); |
| 1068 | scalar_g = std::min<float>(1, scalar + (obj->effect_info->dynamic_green)); |
| 1069 | scalar_b = std::min<float>(1, scalar + (obj->effect_info->dynamic_blue)); |
| 1070 | // If this is a robot, make it at least 10% for each RGB component |
| 1071 | if (obj->type == OBJ_ROBOT) { |
| 1072 | scalar_r = std::max<float>(.1, scalar_r); |
| 1073 | scalar_g = std::max<float>(.1, scalar_g); |
| 1074 | scalar_b = std::max<float>(.1, scalar_b); |
| 1075 | } |
| 1076 | if (obj->type == OBJ_PLAYER && ((Players[obj->id].flags & PLAYER_FLAGS_HEADLIGHT) || |
| 1077 | ((Game_mode & GM_MULTI) && (Netgame.flags & NF_BRIGHT_PLAYERS)))) { |
| 1078 | scalar_r = 1; |
| 1079 | scalar_g = 1; |
| 1080 | scalar_b = 1; |
| 1081 | } |
| 1082 | } else { |
| 1083 | scalar_r = scalar; |
| 1084 | scalar_g = scalar; |
| 1085 | scalar_b = scalar; |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | if (obj->lighting_render_type == LRT_STATIC || Poly_models[obj->rtype.pobj_info.model_num].new_style == 0) |
| 1090 | RenderObject_SetStatic(scalar_r, scalar_g, scalar_b); |
| 1091 | else if (obj->lighting_render_type == LRT_GOURAUD || NoLightmaps) { |
| 1092 | vector lightdir = {0, -1.0, 0}; // straight down for now |
| 1093 | RenderObject_SetGouraud(&lightdir, scalar_r, scalar_g, scalar_b, scalar); |
| 1094 | } else if (obj->lighting_render_type == LRT_LIGHTMAPS) { |
| 1095 | if (obj->lm_object.used == 0) |
| 1096 | RenderObject_SetStatic(scalar_r, scalar_g, scalar_b); |
| 1097 | else |
| 1098 | RenderObject_SetLightmaps(&obj->lm_object); |
| 1099 | } |
| 1100 | } else { |
| 1101 | RenderObject_SetStatic(1, 1, 1); |
no test coverage detected