Fixing lights and shadows
This commit is contained in:
1 parent
9f4d60036d
commit
bba493ee7c
18 files changed
+308
-126
No files matched your search
@@ -6,6 +6,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;
|
||||
|
||||
@@ -13,6 +15,7 @@ varying vec2 texCoord;
|
||||
varying float fogDistance;
|
||||
varying vec3 fragViewPos;
|
||||
varying vec3 fragNormal;
|
||||
varying vec2 fragWorldXZ;
|
||||
|
||||
// cos(45 deg) = half-angle for a 90-degree full-angle spotlight
|
||||
const float SPOT_COS_OUTER = 0.7071;
|
||||
@@ -46,7 +49,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;
|
||||
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;
|
||||
}
|
||||
|
||||
color.rgb *= lighting;
|
||||
|
||||
Reference in new issue
Block a user