mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-04-08 02:51:33 +00:00
Add sunlight trace
This commit is contained in:
parent
2bcab0e34d
commit
e5848ead7a
5 changed files with 51 additions and 13 deletions
|
@ -459,6 +459,8 @@ public:
|
|||
int LMTextureCount = 0;
|
||||
int LMTextureSize = 0;
|
||||
TArray<uint16_t> LMTextureData;
|
||||
FVector3 SunDirection;
|
||||
FVector3 SunColor;
|
||||
|
||||
// Portal information.
|
||||
FDisplacementTable Displacements;
|
||||
|
|
|
@ -3343,7 +3343,12 @@ void MapLoader::LoadLightmap(MapData *map)
|
|||
|
||||
|
||||
int version = fr.ReadInt32();
|
||||
if (version != 0)
|
||||
if (version == 0)
|
||||
{
|
||||
Printf(PRINT_HIGH, "LoadLightmap: This is an old unsupported alpha version of the lightmap lump. Please rebuild the map with a newer version of zdray.\n");
|
||||
return;
|
||||
}
|
||||
if (version != 1)
|
||||
{
|
||||
Printf(PRINT_HIGH, "LoadLightmap: unsupported lightmap lump version\n");
|
||||
return;
|
||||
|
@ -3353,26 +3358,22 @@ 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 numSubsectors = fr.ReadUInt32();
|
||||
uint32_t numTexBytes = numTextures * textureSize * textureSize * 3 * 2;
|
||||
|
||||
if (numSurfaces == 0 || numTexCoords == 0 || numTexBytes == 0)
|
||||
return;
|
||||
|
||||
Printf(PRINT_HIGH, "WARNING! Lightmaps are an experimental feature and are subject to change before being finalized. Do not expect this to work as-is in future releases of %s!\n", GAMENAME);
|
||||
float sunDir[3], sunColor[3];
|
||||
fr.Read(sunDir, sizeof(float) * 3);
|
||||
fr.Read(sunColor, sizeof(float) * 3);
|
||||
Level->SunDirection = FVector3(sunDir);
|
||||
Level->SunColor = FVector3(sunColor);
|
||||
|
||||
/*if (numSubsectors != Level->subsectors.Size())
|
||||
{
|
||||
Printf(PRINT_HIGH, "LoadLightmap: subsector count for level doesn't match (%d in wad vs %d in engine)\n", (int)numSubsectors, (int)Level->subsectors.Size());
|
||||
}*/
|
||||
|
||||
if (numLightProbes > 0)
|
||||
{
|
||||
Printf(PRINT_HIGH, "LoadLightmap: This is an old unsupported alpha version of the lightmap lump. Please rebuild the map with a newer version of zdray.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Level->LMTexCoords.Resize(numTexCoords * 2);
|
||||
|
||||
// Allocate room for all surfaces
|
||||
|
|
|
@ -155,3 +155,32 @@ void AddLightToList(FDynLightData &dld, int group, FDynamicLight * light, bool f
|
|||
data[15] = 0.0f; // unused
|
||||
}
|
||||
|
||||
void AddSunLightToList(FDynLightData& dld, float x, float y, float z, float r, float g, float b)
|
||||
{
|
||||
int i = 0;
|
||||
float lightType = 0.0f;
|
||||
float spotInnerAngle = 0.0f;
|
||||
float spotOuterAngle = 0.0f;
|
||||
float spotDirX = 0.0f;
|
||||
float spotDirY = 0.0f;
|
||||
float spotDirZ = 0.0f;
|
||||
float shadowIndex = -1025.f; // Note: 1025 disables shadowmap and the attenuate flag is in the sign bit of the float
|
||||
|
||||
float* data = &dld.arrays[i][dld.arrays[i].Reserve(16)];
|
||||
data[0] = float(x);
|
||||
data[1] = float(z);
|
||||
data[2] = float(y);
|
||||
data[3] = 100000.0f;
|
||||
data[4] = r;
|
||||
data[5] = g;
|
||||
data[6] = b;
|
||||
data[7] = shadowIndex;
|
||||
data[8] = spotDirX;
|
||||
data[9] = spotDirY;
|
||||
data[10] = spotDirZ;
|
||||
data[11] = lightType;
|
||||
data[12] = spotInnerAngle;
|
||||
data[13] = spotOuterAngle;
|
||||
data[14] = 0.0f; // unused
|
||||
data[15] = 0.0f; // unused
|
||||
}
|
||||
|
|
|
@ -441,4 +441,5 @@ struct FDynLightData;
|
|||
struct FDynamicLight;
|
||||
bool GetLight(FDynLightData& dld, int group, Plane& p, FDynamicLight* light, bool checkside);
|
||||
void AddLightToList(FDynLightData &dld, int group, FDynamicLight* light, bool forceAttenuate);
|
||||
void AddSunLightToList(FDynLightData& dld, float x, float y, float z, float r, float g, float b);
|
||||
void SetSplitPlanes(FRenderState& state, const secplane_t& top, const secplane_t& bottom);
|
||||
|
|
|
@ -61,7 +61,7 @@ static bool TraceLightVisbility(FLightNode* node, const FVector3& L, float dist)
|
|||
|
||||
static bool TraceSunVisibility(float x, float y, float z)
|
||||
{
|
||||
return level.levelMesh->TraceSky(FVector3(x, y, z), FVector3(0.0f, 0.0, 1.0f), 10000.0f);
|
||||
return level.LMTextureCount != 0 && level.levelMesh->TraceSky(FVector3(x, y, z), level.SunDirection, 10000.0f);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -80,7 +80,9 @@ void HWDrawInfo::GetDynSpriteLight(AActor *self, float x, float y, float z, FLig
|
|||
|
||||
if (TraceSunVisibility(x, y, z))
|
||||
{
|
||||
//out[0] = 1.0f;
|
||||
out[0] = Level->SunColor.X;
|
||||
out[1] = Level->SunColor.Y;
|
||||
out[2] = Level->SunColor.Z;
|
||||
}
|
||||
|
||||
// Go through both light lists
|
||||
|
@ -195,7 +197,10 @@ void hw_GetDynModelLight(AActor *self, FDynLightData &modellightdata)
|
|||
|
||||
if (TraceSunVisibility(x, y, z))
|
||||
{
|
||||
//AddSunLightToList(modellightdata);
|
||||
const FVector3& sundir = self->Level->SunDirection;
|
||||
const FVector3& suncolor = self->Level->SunColor;
|
||||
float dist = 100000.0f; // Cheap way of faking a directional light
|
||||
AddSunLightToList(modellightdata, x - sundir.X * dist, y - sundir.Y * dist, z - sundir.Z * dist, suncolor.X, suncolor.Y, suncolor.Z);
|
||||
}
|
||||
|
||||
BSPWalkCircle(self->Level, x, y, radiusSquared, [&](subsector_t *subsector) // Iterate through all subsectors potentially touched by actor
|
||||
|
|
Loading…
Reference in a new issue