rodecomp/Source/Contents/Ground/GroundLightingInitialization.cpp
ragnarok-clanker 7037c0b18c Decompile 13 functions in Source/Contents/Ground/GroundGeometry.h, Source/Contents/Ground/GroundGeometry.cpp, ...
Batch #2778 by youko: 13 byte-identical, 0 confirmed by peer review.

- fn_17564 GroundGeometry::Slot01: byte-identical
- fn_17557 GroundGeometry::Slot02: byte-identical
- fn_17566 GroundGeometry::Ground15Slot04: byte-identical
- fn_17567 GroundGeometry::Slot04: byte-identical
- fn_17591 GroundGeometry::Slot05: byte-identical
- fn_17586 GroundGeometry::Slot06: byte-identical
- fn_17576 GroundGeometry::Slot07: byte-identical
- fn_17575 GroundGeometry::Slot08: byte-identical
- fn_17561 GroundGeometry::Slot09: byte-identical
- fn_17584 GroundGeometry::Slot10: byte-identical
- fn_17583 GroundGeometry::Ground15Slot10: byte-identical
- fn_17559 GroundGeometry::Slot11: byte-identical
- fn_17582 GroundGeometry::Slot19: byte-identical

Merged automatically: every function is byte-identical to the original.
2026-10-29 18:57:00 +00:00

68 lines
2.2 KiB
C++

#include "Contents/Ground/GroundGeometry.h"
#include "Resource/World/TerrainResource.h"
// OFFSET: 0x00ABFB10
// FUNCTION: fn_17558
void GroundGeometry::InitializeLighting(const C3dAttr& terrain) {
// STATIC: 0x01348128
constexpr int offsets[5][2] = {{0, 0}, {0, -1}, {0, 1}, {1, 0}, {-1, 0}};
const int columns = 2 * this->width;
const int rows = 2 * this->height;
for (int row = 0; row < rows; ++row) {
for (int column = 0; column < columns; ++column) {
float average = 0.0f;
const TerrainHeightCell* cell = terrain.Grid().CellAt(column, row);
if (cell) {
average = ((cell->heights[1] + cell->heights[0]) + cell->heights[2] + cell->heights[3]) * 0.25f;
}
float minimum;
float maximum;
this->CellBounds(column / 2, row / 2, minimum, maximum);
float red = 1.0f;
float green = 1.0f;
float blue = 1.0f;
if (average >= minimum - 2.5f) {
unsigned sums[4]{};
for (const auto& offset : offsets) {
unsigned char alpha;
unsigned char sampleRed;
unsigned char sampleGreen;
unsigned char sampleBlue;
this->LightmapSample(column + offset[0], row + offset[1], alpha, sampleRed, sampleGreen, sampleBlue);
sums[0] += alpha;
sums[1] += sampleRed;
sums[2] += sampleGreen;
sums[3] += sampleBlue;
}
const float alpha = (static_cast<float>(sums[0]) / 5.0f) / 255.0f;
red = ((static_cast<float>(sums[1]) / 5.0f) * 0.0078125f) + alpha;
green = ((static_cast<float>(sums[2]) / 5.0f) * 0.0078125f) + alpha;
blue = ((static_cast<float>(sums[3]) / 5.0f) * 0.0078125f) + alpha;
const float first = green > red ? green : red;
const float largest = blue > first ? blue : first;
if (largest > 1.0f) {
red = red / largest;
green = green / largest;
blue = blue / largest;
}
}
if (!this->lighting.empty()) {
const auto index = static_cast<unsigned>(column) + 2u * static_cast<unsigned>(row) * static_cast<unsigned>(this->width);
this->lighting[index] = {red, green, blue};
}
}
}
}
// OFFSET: 0x00ABFD50
// FUNCTION: fn_17559
void GroundGeometry::Slot11() {
}