aboutsummaryrefslogtreecommitdiffstats
path: root/shaders/world.frag
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-06-08 08:47:31 -0400
committerClyne Sullivan <tullivan99@gmail.com>2016-06-08 08:47:31 -0400
commit6882786999581e2280c870249ae448c744767e73 (patch)
tree665eb129c395250e3f390d5e86ac8896ac636322 /shaders/world.frag
parent7110a4ab054341c9f41972b06044853138f526a8 (diff)
parenta978ddfb98734514874231ed28d0395533afa25d (diff)
merge; lights, xmls
Diffstat (limited to 'shaders/world.frag')
-rw-r--r--shaders/world.frag29
1 files changed, 14 insertions, 15 deletions
diff --git a/shaders/world.frag b/shaders/world.frag
index 3177795..bde5fa5 100644
--- a/shaders/world.frag
+++ b/shaders/world.frag
@@ -3,7 +3,7 @@ uniform sampler2D normalTex;
varying vec2 texCoord;
varying vec4 color;
-varying vec3 fragCoord;
+varying vec4 fragCoord;
uniform vec4 ambientLight;
uniform vec4 light[128];
@@ -11,26 +11,25 @@ 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));
+ vec2 texLoc = vec2(texCoord.x, 1-texCoord.y);
+ vec4 pixTex = texture2D(texture, texLoc);
if (pixTex.a < 0.1f)
discard;
-
+
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]);
+ if (lightImpact > 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/(light[i].w*light[i].w), 0.0f, 1.0f);
+ attenuation *= attenuation;
+
+ shadeColor += (vec4(attenuation, attenuation, attenuation, 0.0f) * vec4(lightColor[i])) * lightImpact;
+ }
}
- shadeColor += ambientLight;
+ shadeColor += ambientLight;
gl_FragColor = pixTex * color * shadeColor;
}