diff --git a/src/rendering/hwrenderer/hw_dynlightdata.cpp b/src/rendering/hwrenderer/hw_dynlightdata.cpp index 68312f324..6d425c319 100644 --- a/src/rendering/hwrenderer/hw_dynlightdata.cpp +++ b/src/rendering/hwrenderer/hw_dynlightdata.cpp @@ -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; diff --git a/src/rendering/hwrenderer/scene/hw_drawstructs.h b/src/rendering/hwrenderer/scene/hw_drawstructs.h index 9a0d3c461..21de87b44 100644 --- a/src/rendering/hwrenderer/scene/hw_drawstructs.h +++ b/src/rendering/hwrenderer/scene/hw_drawstructs.h @@ -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); diff --git a/src/rendering/hwrenderer/scene/hw_spritelight.cpp b/src/rendering/hwrenderer/scene/hw_spritelight.cpp index 0ac1991a2..8a189985d 100644 --- a/src/rendering/hwrenderer/scene/hw_spritelight.cpp +++ b/src/rendering/hwrenderer/scene/hw_spritelight.cpp @@ -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 diff --git a/wadsrc/static/shaders/scene/light_shadow.glsl b/wadsrc/static/shaders/scene/light_shadow.glsl index ee5999832..8d42330cd 100644 --- a/wadsrc/static/shaders/scene/light_shadow.glsl +++ b/wadsrc/static/shaders/scene/light_shadow.glsl @@ -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