Fix sunlight not working on models

This commit is contained in:
Magnus Norddahl 2023-04-07 18:00:48 +02:00 committed by Christoph Oelckers
parent c23a109105
commit d97f9f3055
4 changed files with 19 additions and 10 deletions

View file

@ -155,8 +155,15 @@ 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)
void AddSunLightToList(FDynLightData& dld, float x, float y, float z, const FVector3& sundir, const FVector3& suncolor)
{
// Cheap way of faking a directional light
float dist = 100000.0f;
float radius = 100000000.0f;
x += sundir.X * dist;
y += sundir.Y * dist;
z += sundir.Z * dist;
int i = 0;
float lightType = 0.0f;
float spotInnerAngle = 0.0f;
@ -170,10 +177,10 @@ void AddSunLightToList(FDynLightData& dld, float x, float y, float z, float r, f
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[3] = radius;
data[4] = suncolor.X;
data[5] = suncolor.Y;
data[6] = suncolor.Z;
data[7] = shadowIndex;
data[8] = spotDirX;
data[9] = spotDirY;

View file

@ -441,5 +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 AddSunLightToList(FDynLightData& dld, float x, float y, float z, const FVector3& sundir, const FVector3& suncolor);
void SetSplitPlanes(FRenderState& state, const secplane_t& top, const secplane_t& bottom);

View file

@ -197,10 +197,7 @@ void hw_GetDynModelLight(AActor *self, FDynLightData &modellightdata)
if (TraceSunVisibility(x, y, z))
{
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);
AddSunLightToList(modellightdata, x, y, z, self->Level->SunDirection, self->Level->SunColor);
}
BSPWalkCircle(self->Level, x, y, radiusSquared, [&](subsector_t *subsector) // Iterate through all subsectors potentially touched by actor

View file

@ -74,6 +74,8 @@ float traceShadow(vec4 lightpos, int quality)
float shadowAttenuation(vec4 lightpos, float lightcolorA)
{
if (lightpos.w > 1000000.0)
return 1.0; // Sunlight
return traceShadow(lightpos, uShadowmapFilter);
}
@ -206,6 +208,9 @@ float shadowmapAttenuation(vec4 lightpos, float shadowIndex)
float shadowAttenuation(vec4 lightpos, float lightcolorA)
{
if (lightpos.w > 1000000.0)
return 1.0; // Sunlight
float shadowIndex = abs(lightcolorA) - 1.0;
if (shadowIndex >= 1024.0)
return 1.0; // No shadowmap available for this light