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

Function ApplyLightingToTerrain

Descent3/lighting.cpp:1466–1603  ·  view source on GitHub ↗

Changes the terrain shading to approximate lighting

Source from the content-addressed store, hash-verified

1464
1465// Changes the terrain shading to approximate lighting
1466void ApplyLightingToTerrain(vector *pos, int cellnum, float light_dist, float red_scale, float green_scale,
1467 float blue_scale, vector *light_direction, float dot_range) {
1468 int celllist[MAX_DYNAMIC_CELLS];
1469 int num_cells, i;
1470
1471 if (Dedicated_server)
1472 return;
1473
1474 ApplyLightingToObjects(pos, MAKE_ROOMNUM(cellnum), light_dist, red_scale, green_scale, blue_scale, light_direction,
1475 dot_range);
1476
1477 num_cells = fvi_QuickDistCellList(cellnum, pos, light_dist, celllist, MAX_DYNAMIC_CELLS);
1478
1479 if (num_cells < 1)
1480 return;
1481
1482 if (num_cells == MAX_DYNAMIC_CELLS) {
1483 mprintf(0, "One object has hit %d terrain cells in lighting!\n", MAX_DYNAMIC_CELLS);
1484 }
1485
1486 int red_limit = 255;
1487 int green_limit = 255;
1488 int blue_limit = 255;
1489
1490 for (i = 0; i < num_cells; i++) {
1491 int cellnum = celllist[i];
1492 terrain_segment *tseg = &Terrain_seg[cellnum];
1493
1494 int seg_x = cellnum % TERRAIN_WIDTH;
1495 int seg_z = cellnum / TERRAIN_WIDTH;
1496
1497 int subx = seg_x % 128;
1498 int subz = 127 - (seg_z % 128);
1499
1500 int whichmap = ((seg_z / 128) * 2) + (seg_x / 128);
1501 whichmap = TerrainLightmaps[whichmap];
1502
1503 // Make sure face was rendered
1504 // if (tseg->renderframe!=((FrameCount-1)%256))
1505 // continue;
1506
1507 if (Num_dynamic_cells >= MAX_DYNAMIC_CELLS) {
1508 mprintf(0, "Too many dynamic cells!\n");
1509 return;
1510 }
1511
1512 // Check for backfaces
1513 vector tpos;
1514
1515 tpos.x = (seg_x * TERRAIN_SIZE) + (TERRAIN_SIZE / 2);
1516 tpos.z = (seg_z * TERRAIN_SIZE) + (TERRAIN_SIZE / 2);
1517 tpos.y = tseg->y;
1518
1519 vector subvec = *pos - tpos;
1520
1521 float dist = vm_GetMagnitudeFast(&subvec);
1522 float scalar = 1.0 - (dist / light_dist);
1523

Callers 2

DoObjectLightFunction · 0.85
VisEffectMoveOneFunction · 0.85

Calls 6

ApplyLightingToObjectsFunction · 0.85
fvi_QuickDistCellListFunction · 0.85
GR_RGB16Function · 0.85
lm_dataFunction · 0.85
vm_GetMagnitudeFastFunction · 0.50
vm_DotProductFunction · 0.50

Tested by

no test coverage detected