## [SOLVED] light_world.lua incorrect lighting direction

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
0x29a
Prole
Posts: 27
Joined: Sun Jul 06, 2014 10:22 pm

### [SOLVED] light_world.lua incorrect lighting direction

Hi there!
Is anyone using LightWorld implementation of Light vs Shadow library? ( https://github.com/tanema/light_world.lua )

I expected this effect:

Which is exactly opposite result to what I expected... Does anyone knows how to fix it?

Have a good one
Last edited by 0x29a on Thu Oct 27, 2016 8:55 pm, edited 2 times in total.

pgimeno
Party member
Posts: 1978
Joined: Sun Oct 18, 2015 2:58 pm

### Re: light_world.lua incorrect lighting direction

It doesn't look like the opposite to me at all. It looks like your light is a bit high and that makes the shadows stop at a short distance from the object that casts them. But then I haven't used that lib so I can't tell if the library works that way.

0x29a
Prole
Posts: 27
Joined: Sun Jul 06, 2014 10:22 pm

### Re: light_world.lua incorrect lighting direction

Hi there!

No, shadows are not a problem. Problem is that textures are enlightened from the wrong side.
Look closer: With Light vs Shadow [upper screen] little blobs are brighter near the source of light and darker farther away. Also, blobs with Y-axis value lower than light source Y-axis value ("above" the light source) are bright from the "front" side and those with higher value ("beneath" the light source) are dark on the "front" side.
With Light_World implementation [lower screen] it's exactly opposite - blobs "beneath" the light source are bright on the "front" side and blobs "above" the light source are dark.

pgimeno
Party member
Posts: 1978
Joined: Sun Oct 18, 2015 2:58 pm

### Re: light_world.lua incorrect lighting direction

I see now. What LÖVE version is that library for, and what version is your program for? I ask because there was a swap of the shader's Y coordinate at some point, IIRC between 0.9.2 and 0.10.0, and I wonder if that's at play here.

0x29a
Prole
Posts: 27
Joined: Sun Jul 06, 2014 10:22 pm

### Re: light_world.lua incorrect lighting direction

I'm using 10.x
light_world library is a re-write of light_vs_shadow library. It's for 10.x, but it's predecessor was for 9.x series.

Also, very good hint. It very well might be that issue.

slime
Solid Snayke
Posts: 2863
Joined: Mon Aug 23, 2010 6:45 am
Contact:

### Re: light_world.lua incorrect lighting direction

light_world seems to have an "invert normals" option - maybe that will help?

0x29a
Prole
Posts: 27
Joined: Sun Jul 06, 2014 10:22 pm

### Re: light_world.lua incorrect lighting direction

Thanks, but I've tried it out already...

From what I get is that "invert normals" should give normal maps "concave' or "sunken" look instead of regular "convex" or "bulging" effect. I may be wrong, but I'm pretty much sure about that.

pgimeno
Party member
Posts: 1978
Joined: Sun Oct 18, 2015 2:58 pm

### Re: light_world.lua incorrect lighting direction

Yeah, it's not what we're seeing. If it was that, the left-right direction would also be inverted. It's only the up-down one.

It should be easy to make a quick test that inverts the Y coordinate in the shader, to determine guilt. If that fixes the problem with the orientation, regardless of whether it causes other problems, then you can dig further for how to fix it.

0x29a
Prole
Posts: 27
Joined: Sun Jul 06, 2014 10:22 pm

### Re: light_world.lua incorrect lighting direction

Do you happen to know how to do it? I'd be forever in your debt.

https://github.com/tanema/light_world.l ... hadow.glsl << I believe it might be that thing.

Code: Select all

 // if not on the normal map draw attenuated shadows
if(normalColor.a <= 0.0) {
pixel = vec4(0.0, 0.0, 0.0, 1.0);
if (lightGlow.x < 1.0 && lightGlow.y > 0.0) {
pixel.rgb = clamp(lightColor * pow(att, lightSmooth) + pow(smoothstep(lightGlow.x, 1.0, att), lightSmooth) * lightGlow.y, 0.0, 1.0);
} else {
pixel.rgb = lightColor * pow(att, lightSmooth);
}
} else {
vec3 normal = normalize(vec3(normalColor.r,invert_normal ? 1 - normalColor.g : normalColor.g, normalColor.b) * 2.0 - 1.0);
//on the normal map, draw normal shadows
vec3 dir = vec3((lightPosition.xy - pixel_coords.xy) / love_ScreenSize.xy, lightPosition.z);
dir.x *= love_ScreenSize.x / love_ScreenSize.y;
vec3 diff = lightColor * max(dot(normalize(normal), normalize(dir)), 0.0);
//return the light that is effected by the normal and attenuation
pixel = vec4(diff * att, 1.0);
}

}
return pixel;


slime
Solid Snayke
Posts: 2863
Joined: Mon Aug 23, 2010 6:45 am