[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
Before you make a thread asking for help, read this.
0x29a
Prole
Posts: 27
Joined: Sun Jul 06, 2014 10:22 pm

[SOLVED] light_world.lua incorrect lighting direction

Post 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
Last edited by 0x29a on Thu Oct 27, 2016 8:55 pm, edited 2 times in total.
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: light_world.lua incorrect lighting direction

Post 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.
0x29a
Prole
Posts: 27
Joined: Sun Jul 06, 2014 10:22 pm

Re: light_world.lua incorrect lighting direction

Post 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.
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: light_world.lua incorrect lighting direction

Post 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.
0x29a
Prole
Posts: 27
Joined: Sun Jul 06, 2014 10:22 pm

Re: light_world.lua incorrect lighting direction

Post 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.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: light_world.lua incorrect lighting direction

Post by slime »

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

Post 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.
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: light_world.lua incorrect lighting direction

Post 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.
0x29a
Prole
Posts: 27
Joined: Sun Jul 06, 2014 10:22 pm

Re: light_world.lua incorrect lighting direction

Post 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;
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: light_world.lua incorrect lighting direction

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 87 guests