aboutsummaryrefslogtreecommitdiffstats
path: root/shaders/world.frag
diff options
context:
space:
mode:
Diffstat (limited to 'shaders/world.frag')
-rw-r--r--shaders/world.frag25
1 files changed, 18 insertions, 7 deletions
diff --git a/shaders/world.frag b/shaders/world.frag
index d50e01d..3177795 100644
--- a/shaders/world.frag
+++ b/shaders/world.frag
@@ -3,6 +3,7 @@ uniform sampler2D normalTex;
varying vec2 texCoord;
varying vec4 color;
+varying vec3 fragCoord;
uniform vec4 ambientLight;
uniform vec4 light[128];
@@ -10,16 +11,26 @@ uniform vec4 lightColor[128];
uniform float lightImpact;
uniform int lightSize;
+float b = .0005f;
+float minLight = .05f;
+float radius = sqrt(1.0f / (b * minLight));
+
void main()
{
-
vec4 pixTex = texture2D(texture, vec2(texCoord.x, 1-texCoord.y));
- if (pixTex.a < 0.1)
+ if (pixTex.a < 0.1f)
discard;
-
- if (lightSize > 0) {
-
+
+ vec4 shadeColor = vec4(0.0f, 0.0f, 0.0f, 0.0f);
+ for (int i = 0; i < lightSize; i++) {
+ vec2 loc = light[i].xy;
+ float dist = length(loc - fragCoord.xy);
+ float attenuation = clamp(1.0f - dist*dist/(radius*radius), 0.0f, 1.0f);
+ attenuation *= attenuation;
+
+ shadeColor += vec4(attenuation, attenuation, attenuation, 1.0f) * vec4(lightColor[i]);
}
-
- gl_FragColor = pixTex * color * pixTex.a;
+ shadeColor += ambientLight;
+
+ gl_FragColor = pixTex * color * shadeColor;
}