aboutsummaryrefslogtreecommitdiffstats
path: root/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'shaders')
-rw-r--r--shaders/world.frag29
-rw-r--r--shaders/world.vert6
2 files changed, 17 insertions, 18 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;
}
diff --git a/shaders/world.vert b/shaders/world.vert
index df814e6..0d5e65e 100644
--- a/shaders/world.vert
+++ b/shaders/world.vert
@@ -7,11 +7,11 @@ uniform mat4 transform;
varying vec2 texCoord;
varying vec4 color;
-varying vec3 fragCoord;
+varying vec4 fragCoord;
void main(){
color = tex_color;
texCoord = tex_coord;
- gl_Position = ortho * transform * vec4(coord2d.xyz, 1.0);
- fragCoord = vec3(gl_Position.xyz);
+ fragCoord = vec4(coord2d.xyz, 1.0);
+ gl_Position = ortho * transform * fragCoord;
}