mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-22 20:21:26 +00:00
Add light probe support for sprites
This commit is contained in:
parent
d2b8f1aaff
commit
e0ea5e3b55
5 changed files with 40 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -429,6 +429,7 @@ public:
|
|||
|
||||
void SetMusic();
|
||||
|
||||
void GetLightProbeLight(float x, float y, float z, float* out);
|
||||
|
||||
TArray<vertex_t> vertexes;
|
||||
TArray<sector_t> sectors;
|
||||
|
@ -457,6 +458,7 @@ public:
|
|||
int LMTextureCount = 0;
|
||||
int LMTextureSize = 0;
|
||||
TArray<uint16_t> LMTextureData;
|
||||
TArray<LightProbe> LightProbes;
|
||||
|
||||
// Portal information.
|
||||
FDisplacementTable Displacements;
|
||||
|
|
|
@ -1687,6 +1687,12 @@ struct LightmapSurface
|
|||
float *TexCoords;
|
||||
};
|
||||
|
||||
struct LightProbe
|
||||
{
|
||||
float X, Y, Z;
|
||||
float Red, Green, Blue;
|
||||
};
|
||||
|
||||
//
|
||||
// OTHER TYPES
|
||||
//
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue