diff --git a/src/g_level.cpp b/src/g_level.cpp index 6468dd29df..358e567e08 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -2283,3 +2283,26 @@ void FLevelLocals::SetMusic() S_ChangeMusic(Music, musicorder); } +void FLevelLocals::GetLightProbeLight(float x, float y, float z, float* out) +{ + out[0] = out[1] = out[2] = 0.f; + + // To do: Pretty stupid algorithm. Use something better once we confirmed this looks alright. + + float lastdist = 0.0f; + for (unsigned int i = 0; i < LightProbes.Size(); i++) + { + const LightProbe& probe = LightProbes[i]; + float dx = probe.X - x; + float dy = probe.Y - y; + float dz = probe.Z - z; + float dist = dx * dx + dy * dy + dz * dz; + if (i == 0 || dist < lastdist) + { + out[0] = probe.Red; + out[1] = probe.Green; + out[2] = probe.Blue; + lastdist = dist; + } + } +} diff --git a/src/g_levellocals.h b/src/g_levellocals.h index 94f7a5d91b..a6e6fe9f27 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -429,6 +429,7 @@ public: void SetMusic(); + void GetLightProbeLight(float x, float y, float z, float* out); TArray vertexes; TArray sectors; @@ -457,6 +458,7 @@ public: int LMTextureCount = 0; int LMTextureSize = 0; TArray LMTextureData; + TArray LightProbes; // Portal information. FDisplacementTable Displacements; diff --git a/src/gamedata/r_defs.h b/src/gamedata/r_defs.h index 3dc9497c01..33149e63a6 100644 --- a/src/gamedata/r_defs.h +++ b/src/gamedata/r_defs.h @@ -1687,6 +1687,12 @@ struct LightmapSurface float *TexCoords; }; +struct LightProbe +{ + float X, Y, Z; + float Red, Green, Blue; +}; + // // OTHER TYPES // diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index 5a8efc5281..ad1667abd5 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -3340,6 +3340,7 @@ void MapLoader::LoadLightmap(MapData *map) uint16_t numTextures = fr.ReadUInt16(); uint32_t numSurfaces = fr.ReadUInt32(); uint32_t numTexCoords = fr.ReadUInt32(); + uint32_t numLightProbes = fr.ReadUInt32(); uint32_t numTexBytes = numTextures * textureSize * textureSize * 3 * 2; if (numSurfaces == 0 || numTexCoords == 0 || numTexBytes == 0) @@ -3347,6 +3348,12 @@ void MapLoader::LoadLightmap(MapData *map) Level->LMTexCoords.Resize(numTexCoords * 2); + if (numLightProbes > 0) + { + Level->LightProbes.Resize(numLightProbes); + fr.Read(&Level->LightProbes[0], sizeof(LightProbe) * numLightProbes); + } + // Allocate room for all surfaces unsigned int allSurfaces = 0; diff --git a/src/rendering/hwrenderer/scene/hw_spritelight.cpp b/src/rendering/hwrenderer/scene/hw_spritelight.cpp index 71b4868882..b928e209b2 100644 --- a/src/rendering/hwrenderer/scene/hw_spritelight.cpp +++ b/src/rendering/hwrenderer/scene/hw_spritelight.cpp @@ -57,7 +57,8 @@ void HWDrawInfo::GetDynSpriteLight(AActor *self, float x, float y, float z, FLig float frac, lr, lg, lb; float radius; - out[0] = out[1] = out[2] = 0.f; + self->Level->GetLightProbeLight(x, y, z, out); + // Go through both light lists while (node) {