From 2b797afeed3ac43ffa9b798a1282418715c287d3 Mon Sep 17 00:00:00 2001 From: LJW-Dev <48092720+LJW-Dev@users.noreply.github.com> Date: Thu, 23 Apr 2026 17:20:19 +0800 Subject: [PATCH] feat: Minor fixups and improvements --- src/ObjLoading/Game/T6/BSP/BSPCreator.cpp | 18 ++++---------- .../Game/T6/BSP/Linker/GfxWorldLinker.cpp | 24 ++++++++++++++----- .../Game/T6/BSP/Linker/GfxWorldLinker.h | 2 +- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/ObjLoading/Game/T6/BSP/BSPCreator.cpp b/src/ObjLoading/Game/T6/BSP/BSPCreator.cpp index fc502398..e527ad59 100644 --- a/src/ObjLoading/Game/T6/BSP/BSPCreator.cpp +++ b/src/ObjLoading/Game/T6/BSP/BSPCreator.cpp @@ -1038,20 +1038,10 @@ namespace throw GltfLoadException("Materials must have a name."); material.materialType = MATERIAL_TYPE_TEXTURE; - if (jsMaterial.pbrMetallicRoughness && jsMaterial.pbrMetallicRoughness->baseColorFactor) - { - material.materialColour.x = (*jsMaterial.pbrMetallicRoughness->baseColorFactor)[0]; - material.materialColour.y = (*jsMaterial.pbrMetallicRoughness->baseColorFactor)[1]; - material.materialColour.z = (*jsMaterial.pbrMetallicRoughness->baseColorFactor)[2]; - material.materialColour.w = (*jsMaterial.pbrMetallicRoughness->baseColorFactor)[3]; - } - else - { - material.materialColour.x = 1.0f; - material.materialColour.y = 1.0f; - material.materialColour.z = 1.0f; - material.materialColour.w = 1.0f; - } + material.materialColour.x = 1.0f; + material.materialColour.y = 1.0f; + material.materialColour.z = 1.0f; + material.materialColour.w = 1.0f; material.surfaceFlags = 0; material.contentFlags = 1; diff --git a/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.cpp b/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.cpp index 9ad676f6..e4400783 100644 --- a/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.cpp +++ b/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.cpp @@ -429,7 +429,7 @@ namespace BSP gfxWorld->primaryLightEntityShadowVis = nullptr; } - void GfxWorldLinker::loadLightGrid(GfxWorld* gfxWorld) + void GfxWorldLinker::loadLightGrid(BSPData* bsp, GfxWorld* gfxWorld) { // gfxWorld->lightGrid.mins[0] = static_cast((static_cast(gfxWorld->lightGrid.mins[0]) + 0x20000) >> 5); // gfxWorld->lightGrid.mins[1] = static_cast((static_cast(gfxWorld->lightGrid.mins[1]) + 0x20000) >> 5); @@ -453,7 +453,7 @@ namespace BSP int rowDataStartSize = gfxWorld->lightGrid.maxs[gfxWorld->lightGrid.rowAxis] - gfxWorld->lightGrid.mins[gfxWorld->lightGrid.rowAxis] + 1; gfxWorld->lightGrid.rowDataStart = m_memory.Alloc(rowDataStartSize); - // Adding 0x0F so the lookup table will be 0x10 bytes in size + // Adding 0x1FF so the lookup table will be 0x200 bytes in size gfxWorld->lightGrid.rawRowDataSize = static_cast(sizeof(GfxLightGridRow) + 0x1FF); GfxLightGridRow* row = static_cast(m_memory.AllocRaw(gfxWorld->lightGrid.rawRowDataSize)); row->colStart = 0; @@ -476,10 +476,22 @@ namespace BSP } gfxWorld->lightGrid.entries = entryArray; + char color = 32; + float sunIntensity = bsp->sunlight.intensity; + if (sunIntensity < 0.0f || sunIntensity > 20000.0f) + con::warn("Sun intensity ({}) needs to be between 0 and 20000", sunIntensity); + else + { + float normalised = sunIntensity / 20000.0f; + normalised *= 255.0f; + float clean = roundf(normalised); + color = static_cast(clean); + } + // colours are looked up with a lightgrid entries colorsIndex gfxWorld->lightGrid.colorCount = 0x1000; // 0x1000 as it should be enough to hold every index gfxWorld->lightGrid.colors = m_memory.Alloc(gfxWorld->lightGrid.colorCount); - memset(gfxWorld->lightGrid.colors, 32, rowDataStartSize * sizeof(uint16_t)); + memset(gfxWorld->lightGrid.colors, color, rowDataStartSize * sizeof(uint16_t)); // we use the colours array instead of coeffs array gfxWorld->lightGrid.coeffCount = 0; @@ -692,7 +704,7 @@ namespace BSP gfxWorld->draw.reflectionProbes[0].probeVolumeCount = 0; gfxWorld->draw.reflectionProbes[0].probeVolumes = nullptr; - std::string probeImageName = "reflection_probe0"; + std::string probeImageName = "$white"; auto probeImageAsset = m_context.LoadDependency(probeImageName); if (probeImageAsset == nullptr) { @@ -711,7 +723,7 @@ namespace BSP gfxWorld->draw.lightmapPrimaryTextures = m_memory.Alloc(gfxWorld->draw.lightmapCount); gfxWorld->draw.lightmapSecondaryTextures = m_memory.Alloc(gfxWorld->draw.lightmapCount); - std::string secondaryTexture = "lightmap0_secondary"; + std::string secondaryTexture = ",$white"; auto secondaryTextureAsset = m_context.LoadDependency(secondaryTexture); if (secondaryTextureAsset == nullptr) { @@ -842,7 +854,7 @@ namespace BSP // gfx cells depend on surface/smodel count loadGfxCells(gfxWorld); - loadLightGrid(gfxWorld); + loadLightGrid(bsp, gfxWorld); loadGfxLights(bsp, gfxWorld); // requires xmodels and surfaces diff --git a/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.h b/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.h index 570df5ac..1ed12d56 100644 --- a/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.h +++ b/src/ObjLoading/Game/T6/BSP/Linker/GfxWorldLinker.h @@ -23,7 +23,7 @@ namespace BSP bool loadXModels(BSPData* projInfo, GfxWorld* gfxWorld); void cleanGfxWorld(GfxWorld* gfxWorld); void loadGfxLights(BSPData* bsp, GfxWorld* gfxWorld); - void loadLightGrid(GfxWorld* gfxWorld); + void loadLightGrid(BSPData* bsp, GfxWorld* gfxWorld); void loadGfxCells(GfxWorld* gfxWorld); void loadModels(BSPData* bsp, GfxWorld* gfxWorld); bool loadReflectionProbeData(GfxWorld* gfxWorld);