Batch #2457 by ragnarok-clanker: 0 byte-identical, 48 confirmed by peer review. - fn_00152 TextureCache::TextureCache: logic confirmed by peer review - fn_01952 DrawAlphaRectangle: logic confirmed by peer review - fn_01953 DrawBlendedRectangle: logic confirmed by peer review - fn_01954 DrawTexturedRectangle: logic confirmed by peer review - fn_01955 DrawTextureRegion: logic confirmed by peer review - fn_02237 CRendererDX9::SaveLogo: logic confirmed by peer review - fn_02353 CRenderSystemDX9::CRenderSystemDX9: logic confirmed by peer review - fn_02447 TextureCache::~TextureCache: logic confirmed by peer review (already on main) - fn_02449 TextureCache::Upload: logic confirmed by peer review - fn_02451 TextureCache::Clear: logic confirmed by peer review (already on main) - fn_02452 TextureCache::Remove: logic confirmed by peer review (already on main) - fn_02453 TextureCache::Default: logic confirmed by peer review - fn_02454 TextureCache::Load: logic confirmed by peer review (already on main) - fn_02455 TextureCache::Create: logic confirmed by peer review - fn_02456 TextureCache::Reload: logic confirmed by peer review - fn_02457 TextureCache::ClearUnused: logic confirmed by peer review - fn_07897 EZeffectClip::Texture: logic confirmed by peer review - fn_07898 EZeffectClip::Texture: logic confirmed by peer review - fn_07958 C3dAnimModelRes::Load: logic confirmed by peer review - fn_07996 ModelNode::~ModelNode: logic confirmed by peer review - fn_08010 C3dGrannyModelRes::CreateTexture: logic confirmed by peer review - fn_08020 C3dModelResV2::ReadVersion1: logic confirmed by peer review - fn_08021 C3dModelResV2::ReadVersion2: logic confirmed by peer review - fn_08022 C3dModelResV2::ReadVersion3: logic confirmed by peer review - fn_09166 BinkMovies::Update: logic confirmed by peer review - fn_10122 UIRPData::DrawNamed: logic confirmed by peer review - fn_12091 UIWhisperWnd::Slot43: logic confirmed by peer review - fn_17556 GroundGeometry::Build: logic confirmed by peer review - fn_17565 GroundGeometry::BuildLightmaps: logic confirmed by peer review - fn_17581 GroundWaterState::Update: logic confirmed by peer review - fn_17587 GroundGeometry::DrawGrid: logic confirmed by peer review - fn_17599 GroundWaterState::Import: logic confirmed by peer review - fn_17842 ModeFade::Draw: logic confirmed by peer review - fn_17847 FadeOutMode: logic confirmed by peer review - fn_20019 CRagEffect::Blessing: logic confirmed by peer review - fn_20023 CRagEffect::Bottom: logic confirmed by peer review - fn_20024 CRagEffect::BowlingBash: logic confirmed by peer review - fn_20025 CRagEffect::CartRevolution: logic confirmed by peer review - fn_20042 CRagEffect::Entry: logic confirmed by peer review - fn_20054 CRagEffect::FrostDiver: logic confirmed by peer review - fn_20058 CRagEffect::GrimTooth: logic confirmed by peer review - fn_20066 CRagEffect::Hit4: logic confirmed by peer review - fn_20088 UpdatePartyEffect: logic confirmed by peer review - fn_20105 CRagEffect::SonicBlowHit: logic confirmed by peer review - fn_20109 CRagEffect::SprayPond: logic confirmed by peer review - fn_20124 CRagEffect::Yufitel: logic confirmed by peer review - fn_20132 CRagEffect::AirTexture: logic confirmed by peer review - fn_20133 CRagEffect::AttackEnergy2: logic confirmed by peer review Reviewed-by: ragnarok-clanker
77 lines
3.1 KiB
C++
77 lines
3.1 KiB
C++
#include "Contents/Ground/GroundGeometry.h"
|
|
#include "Render/Textures/Texture.h"
|
|
#include "Render/Textures/TextureCache.h"
|
|
#include "Resource/World/GroundResource.h"
|
|
|
|
#include <algorithm>
|
|
#include <array>
|
|
|
|
// OFFSET: 0x00AC3040
|
|
// FUNCTION: fn_17597
|
|
void GroundGeometry::ClearLightmaps() {
|
|
this->lightmaps.clear();
|
|
|
|
while (!this->lightmapTextures.empty()) {
|
|
delete this->lightmapTextures.back();
|
|
this->lightmapTextures.pop_back();
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00AC0360
|
|
// FUNCTION: fn_17565
|
|
void GroundGeometry::BuildLightmaps(CGndRes& resource) {
|
|
this->ClearLightmaps();
|
|
this->lightmaps.resize(static_cast<unsigned>(resource.lightmapCount));
|
|
const unsigned atlasCount = (static_cast<unsigned>(resource.lightmapCount) + 1023u) / 1024u;
|
|
this->lightmapTextures.reserve(atlasCount);
|
|
std::array<std::uint32_t, 256 * 256> pixels;
|
|
|
|
for (int first = 0; first < resource.lightmapCount; first += 1024) {
|
|
for (int index = 0; index < 1024 && first + index < resource.lightmapCount; ++index) {
|
|
unsigned char decoded[256];
|
|
resource.Lightmap(first + index, decoded);
|
|
const unsigned column = static_cast<unsigned>(index) % 32;
|
|
const unsigned row = static_cast<unsigned>(index) / 32;
|
|
|
|
for (unsigned y = 0; y < 8; ++y) {
|
|
for (unsigned x = 0; x < 8; ++x) {
|
|
const unsigned pixel = y * 8 + x;
|
|
pixels[(row * 8 + y) * 256 + column * 8 + x] = (static_cast<unsigned>(decoded[pixel]) << 24) |
|
|
(static_cast<unsigned>(decoded[64 + pixel * 3]) << 16) |
|
|
(static_cast<unsigned>(decoded[65 + pixel * 3]) << 8) | decoded[66 + pixel * 3];
|
|
}
|
|
}
|
|
|
|
GroundLightmap& map = this->lightmaps[first + index];
|
|
const float left = std::clamp(static_cast<float>(8 * column + 1) / 256.0f, 0.0f, 1.0f);
|
|
const float right = std::clamp(static_cast<float>(8 * column + 7) / 256.0f, 0.0f, 1.0f);
|
|
const float top = std::clamp(static_cast<float>(8 * row + 1) / 256.0f, 0.0f, 1.0f);
|
|
const float bottom = std::clamp(static_cast<float>(8 * row + 7) / 256.0f, 0.0f, 1.0f);
|
|
|
|
map.uv[0][0] = left;
|
|
map.uv[0][1] = top;
|
|
map.uv[1][0] = right;
|
|
map.uv[1][1] = top;
|
|
map.uv[2][0] = left;
|
|
map.uv[2][1] = bottom;
|
|
map.uv[3][0] = right;
|
|
map.uv[3][1] = bottom;
|
|
map.color[0] = decoded[172];
|
|
map.color[1] = decoded[173];
|
|
map.color[2] = decoded[174];
|
|
const unsigned samples[4] = {9, 13, 41, 45};
|
|
|
|
for (unsigned corner = 0; corner < 4; ++corner) {
|
|
const unsigned pixel = samples[corner];
|
|
map.unknown_0028[corner] = (static_cast<unsigned>(decoded[pixel]) << 24) | (static_cast<unsigned>(decoded[64 + pixel * 3]) << 16) |
|
|
(static_cast<unsigned>(decoded[65 + pixel * 3]) << 8) | decoded[66 + pixel * 3];
|
|
}
|
|
}
|
|
|
|
this->lightmapTextures.push_back(g_texMgr.Upload(256, 256, pixels.data(), 4, 0, false, false, false));
|
|
}
|
|
|
|
for (unsigned index = 0; index < this->lightmaps.size(); ++index) {
|
|
this->lightmaps[index].texture = this->lightmapTextures[index / 1024];
|
|
}
|
|
}
|