Fixing lights and shadows

This commit is contained in:
Vladislav Khorev committed 2026-06-15 21:25:54 +03:00
1 parent 9f4d60036d
commit bba493ee7c
18 files changed
+308 -126

No files matched your search

@@ -8,6 +8,8 @@ uniform int uPointLightCount;
uniform vec3 uPointLightPos[4];
uniform vec3 uPointLightDir[4];
uniform vec3 uPointLightColor[4];
uniform vec2 uPointLightWorldXZ[4];
uniform vec2 uPointLightLimitXZ[4];
uniform vec3 uAmbientColor;
uniform vec3 uFogColor;
@@ -16,6 +18,7 @@ varying vec4 fragPosLightSpace;
varying vec3 fragNormal;
varying float fogDistance;
varying vec3 fragViewPos;
varying vec2 fragWorldXZ;
const float SPOT_COS_OUTER = 0.7071;
const float SPOT_COS_INNER = 0.82;
@@ -85,7 +88,11 @@ void main()
float atten = 1.0 / (1.0 + 0.35 * dist + 0.15 * dist * dist);
float diff = hasNormal ? max(dot(N, lightDir), 0.0) : 1.0;
lighting += uPointLightColor[i] * diff * atten * spotAtten * (1.0 - shadow);
vec2 worldDelta = abs(fragWorldXZ - uPointLightWorldXZ[i]);
float rectX = 1.0 - smoothstep(uPointLightLimitXZ[i].x - 0.5, uPointLightLimitXZ[i].x + 0.5, worldDelta.x);
float rectY = 1.0 - smoothstep(uPointLightLimitXZ[i].y - 0.5, uPointLightLimitXZ[i].y + 0.5, worldDelta.y);
lighting += uPointLightColor[i] * diff * atten * spotAtten * rectX * rectY * (1.0 - shadow);
}
color.rgb *= lighting;