MCPcopy Create free account
hub / github.com/Segs/Segs / lightModel

Function lightModel

Projects/CoX/Clients/Client_I0/graphics/GroupDraw.cpp:263–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

261}
262
263void lightModel(Model *model, Matrix4x3 *mat, unsigned __int8 *rgb, DefTracker *light_trkr)
264{
265 int j;
266 Vector3 normal_in_ws;
267 Vector3 primary_color;
268 uint8_t max_light_colors[3];
269 DefTracker *found_trackers[1001];
270
271 int is_omnidir_light = 0;
272 int tracker_count = 0;
273 Vector3 masked_dst = { -8.0000002e16f, -8.0000002e16f, -8.0000002e16f};
274 float cell_power_of_two_size = 0.0;
275 assert(rgb && light_trkr);
276 Grid *light_grid = light_trkr->light_grid;
277 if (!light_grid)
278 return;
279
280 assert(model && model->vbo);
281 segs_modelSetupVertexObject(model, 1);
282 Vector3 *verts_pos = (Vector3 *)model->vbo->cpuside_memory;
283 Vector3 *verts_normal = (Vector3 *)(intptr_t(model->vbo->normals_offset) + (char *)model->vbo->cpuside_memory);
284 for (int i = 0; i < 3; ++i)
285 {
286 primary_color[i] = ((uint8_t *)light_trkr->def->tint_colors)[i] / 255.0f;
287 max_light_colors[i] = *((char *)&light_trkr->def->tint_colors[1] + i);
288 }
289 if (!(max_light_colors[2] | max_light_colors[1] | max_light_colors[0]))
290 {
291 max_light_colors[2] = 0xFFu;
292 max_light_colors[1] = 0xFFu;
293 max_light_colors[0] = 0xFFu;
294 }
295 if (strstri(model->bone_name_offset, "omni"))
296 is_omnidir_light = 1;
297 for (int i = 0; i < model->vertex_count; ++i)
298 {
299 Vector3 dst = *mat * verts_pos[i];
300 Vector3 calc_color = primary_color;
301 for (j = 0; j < 3; ++j)
302 {
303 float tmp = dst[j] - masked_dst[j];
304 if (tmp >= cell_power_of_two_size || tmp < 0.0f)
305 break;
306 }
307 if (j < 3)
308 {
309 ++light_grid->tag;
310 gridFindCell(light_grid, &dst, found_trackers, &tracker_count, &cell_power_of_two_size);
311 cell_power_of_two_size = std::min(128.0f, cell_power_of_two_size);
312 for (int k = 0; k < 3; ++k)
313 {
314 int32_t int_dest = int(dst[k]);
315 masked_dst[k] = (~(int(cell_power_of_two_size) - 1) & int_dest);
316 }
317 }
318 for (int l = 0; l < tracker_count; ++l)
319 {
320 DefTracker *trkr = found_trackers[l];

Callers 2

seqSetStaticLightFunction · 0.85
colorizeTrackerFunction · 0.85

Calls 4

multVertexByMatrixFunction · 0.85
normalizeMethod · 0.80
dotMethod · 0.80

Tested by

no test coverage detected