Help with 2D lighting

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.
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Help with 2D lighting

Post by yetneverdone »

Hi, im trying to learn and apply 2d lighting for my game. There are libraries available for love but those are mainly for top down view, what im aiming is for 2D. Can anyone guide me? Will i be dealing with canvas with blend modes, or shaders?

also, what about sprite illuminator? im pretty sure that software is useful, but have anyone tried using it with love?

Thanks
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Help with 2D lighting

Post by zorg »

Top-Down is also a 2D view, are you thinking about Side-Scrollers perhaps? (Or maybe isometric, those are indeed harder to shadow/light correctly)

I'm pretty sure both canvases, blendmodes and shaders are needed to get a good effect, and i'm suspecting that existing libraries (showcasing top-down demos) could work with side-scrollers as well.

Haven't used SpriteIlluminator myself, but with some simple shaders, it could be used, as well as any of the other 2 sprite lighting editors i know (though those aren't free):
https://www.codeandweb.com/spriteilluminator
http://www.2deegameart.com/p/sprite-dlight.html
http://www.spritelamp.com/
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Help with 2D lighting

Post by yetneverdone »

zorg wrote: Thu Jan 18, 2018 3:46 pm Top-Down is also a 2D view, are you thinking about Side-Scrollers perhaps? (Or maybe isometric, those are indeed harder to shadow/light correctly)
Yes, im talking about sidescroller, sorry i didnt specify.
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: Help with 2D lighting

Post by erasio »

As zorg was mentioning. The "top down lighting" can work with sidescrollers too.

What exactly are you missing?

Or to reword that question. What's the difference between top down and sidescroller lighting?

Knowing that makes helping a lot easier :nyu:
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Help with 2D lighting

Post by yetneverdone »

erasio wrote: Thu Jan 18, 2018 6:05 pm As zorg was mentioning. The "top down lighting" can work with sidescrollers too. What exactly are you missing? Or to reword that question. What's the difference between top down and sidescroller lighting? Knowing that makes helping a lot easier :nyu:
I cant imagine how that would look :/ looking at the demo picture of the other libraries, i just fail to realize how that would look. For example, in the demo pics, there is shadow cast when the rays are blocked right? but how that would be in platformer? the light source is indeed in top, but not to cast shadow as in no visibility? Sorry i cant explain it well :/ thanks for helping btw
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Help with 2D lighting

Post by yetneverdone »

It kind of look like this:
zombie_horizontalpreview_grey2.gif
zombie_horizontalpreview_grey2.gif (318.4 KiB) Viewed 7636 times
Note: that is a sample pic of Sprite Lamp
drunken_munki
Party member
Posts: 134
Joined: Tue Mar 29, 2011 11:05 pm

Re: Help with 2D lighting

Post by drunken_munki »

Without any technical information I can only say that a lighting system that advanced (in the zombie image) would require separate normals maps (bump maps) that are pre computed, with the possible addition of depth maps and ambient occlusions maps as well.

These can be created with various software, some of them can work with only an input image and can create the maps for you.

For you then the original image plus the maps can be used real time (most likely in a pixel shader) that also takes in the lighting systems of the level to produce the final image drawn to screen

So all of this is pretty advanced and complicated, but if you want to have a look I believe there is a guy who made a kick starter project for creating these normal maps: http://www.2deegameart.com/p/sprite-dlight.html

There was a thread here: https://love2d.org/forums/viewtopic.php?t=79177

In that thread someone was working on a light vs. shadow library implemenation with the bump maps, however I have no other info:
file.png
file.png (167.55 KiB) Viewed 7629 times
A lot of people will abandon this kind of system because they are using spritesheet animations, which means you will create these bumpmaps for every frame of every animation of every character and object for your entire game.



You could check out this link: https://github.com/tanema/light_world.lua
for some love code with several lighting examples selectable from a menu, might help you out.


Then the inevitable will hit you, you now need detailed and realist shadows to match the lighting; which becomes another problem to solve.

In my own game I went for a simple lighting system with a simple 'fake shadow' that I draw underneath. I play with colours to make some magic and I get something like this (time of day is sunset with lighting from the nearby fires):
2018-01-19-04-14-40.png
2018-01-19-04-14-40.png (945.42 KiB) Viewed 7629 times
Not as fancy but there you are.
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Help with 2D lighting

Post by yetneverdone »

Awesome! thanks for the input.
Currently i cant afford sprite dlamp, I might just use spriteulliminator.

Another thing is, i dont have any idea on how to apply those normal maps thingy. Will i draw them as well? how?
I would really be grateful if you give me the general workflow or the procedure on how to apply such. :)

BTW, is that your game? I like the style :)
User avatar
erasio
Party member
Posts: 118
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: Help with 2D lighting

Post by erasio »

Lighting is done via a shader on the graphics card. So the normal map needs to be used there as well. Since it's not changing the color but just defining additional information to have the light look more realistic.

An introduction to shaders and lighting I liked quite a bit is by catlike coding.

It's for unity and 3D rendering. But the techniques are essentially the same. 2D is just a bit easier, though also has significantly less tutorials.

Be warned. This is a quite advanced topic which requires a bunch of uni level math.
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Help with 2D lighting

Post by yetneverdone »

erasio wrote: Fri Jan 19, 2018 8:44 am Lighting is done via a shader on the graphics card. So the normal map needs to be used there as well. Since it's not changing the color but just defining additional information to have the light look more realistic.

An introduction to shaders and lighting I liked quite a bit is by catlike coding.

It's for unity and 3D rendering. But the techniques are essentially the same. 2D is just a bit easier, though also has significantly less tutorials.

Be warned. This is a quite advanced topic which requires a bunch of uni level math.
Thanks, is there another way instead of using shader? My laptop cant handle that much shader :/
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 21 guests