Page 1 of 2

[SOLVED] light_world.lua incorrect lighting direction

Posted: Wed Oct 26, 2016 4:39 pm
by 0x29a
Hi there!
Is anyone using LightWorld implementation of Light vs Shadow library? ( https://github.com/tanema/light_world.lua )

I expected this effect:

Image

Instead, I got

Image
Which is exactly opposite result to what I expected... Does anyone knows how to fix it?
Thanks in advance!

Have a good one

Re: light_world.lua incorrect lighting direction

Posted: Wed Oct 26, 2016 6:16 pm
by pgimeno
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.

Re: light_world.lua incorrect lighting direction

Posted: Wed Oct 26, 2016 6:24 pm
by 0x29a
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.

Re: light_world.lua incorrect lighting direction

Posted: Wed Oct 26, 2016 8:43 pm
by pgimeno
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.

Re: light_world.lua incorrect lighting direction

Posted: Thu Oct 27, 2016 5:55 am
by 0x29a
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.

Re: light_world.lua incorrect lighting direction

Posted: Thu Oct 27, 2016 4:33 pm
by slime
light_world seems to have an "invert normals" option - maybe that will help?

Re: light_world.lua incorrect lighting direction

Posted: Thu Oct 27, 2016 4:52 pm
by 0x29a
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.

Re: light_world.lua incorrect lighting direction

Posted: Thu Oct 27, 2016 5:42 pm
by pgimeno
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.

Re: light_world.lua incorrect lighting direction

Posted: Thu Oct 27, 2016 6:45 pm
by 0x29a
Do you happen to know how to do it? I'd be forever in your debt.
I've tried reading shader's code, but it's very opaque to me...

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) {
      //start with a dark color and add in the light color and shadow color
      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);
    }

    if(shadowColor.a > 0.0) {
      pixel.rgb = pixel.rgb * shadowColor.rgb;
    }
return pixel;

Re: light_world.lua incorrect lighting direction

Posted: Thu Oct 27, 2016 8:23 pm
by slime
pgimeno wrote: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.
The invert normals option in this library only seems to invert the Y (green channel) coordinate.