Lighting and Shadow System

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Lighting and Shadow System

Post by Ranguna259 »

You're welcome ;)
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
Jeeper
Party member
Posts: 611
Joined: Tue Mar 12, 2013 7:11 pm
Contact:

Re: Lighting and Shadow System

Post by Jeeper »

Looks really awesome! I have a few questions though, I am going to start working on a game where I would like to have multiple light sources just for aesthetics. But only the light, not that it casts shadows on objects etc. How do you think the best way of accomplishing this would be?
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Lighting and Shadow System

Post by Ranguna259 »

You could just make a circle with x radius and apply something like a fade from center shader to the circle.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
argh
Prole
Posts: 11
Joined: Fri Jan 31, 2014 7:07 am

Re: Lighting and Shadow System

Post by argh »

Ranguna259 wrote:That's a similar aproach to this one. I'm actually trying to reproduce that effect...
Me too, I'll probably start porting this Java version as the process is explained really well and the code is easy to run. I've never seen a version of this implementation with the objects lit though. How far are you with your port?
Ranguna259 wrote:Since you draw the shadows how do you set their limit ? Do they stop once they reach a certain distance from the light source or when they hit the screen borders ?
I use a very crude method at the moment, just multiply each point by a large enough scalar. I have been thinking of taking the lights height into equation to change the length, but it makes things more complicated. What do you do?
argh
Prole
Posts: 11
Joined: Fri Jan 31, 2014 7:07 am

Re: Lighting and Shadow System

Post by argh »

Jeeper wrote:Looks really awesome! I have a few questions though, I am going to start working on a game where I would like to have multiple light sources just for aesthetics. But only the light, not that it casts shadows on objects etc. How do you think the best way of accomplishing this would be?
Hey I modified the code and created a new gist with just lights https://gist.github.com/seanpackham/8779962 take a look at the code and comments for an explanation of the method. Enjoy :)

Image
argh
Prole
Posts: 11
Joined: Fri Jan 31, 2014 7:07 am

Re: Lighting and Shadow System

Post by argh »

I have updated my subtractive method with a smooth radial gradient light shader https://gist.github.com/seanpackham/8727943

Image

Image
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Lighting and Shadow System

Post by Ranguna259 »

argh wrote:Me too, I'll probably start porting this Java version as the process is explained really well and the code is easy to run. I've never seen a version of this implementation with the objects lit though. How far are you with your port?
Not far, I've been trying to find a rectangle to polar and a polar to rectangle shader but I think I'll start porting the code you linked too, let's compare results once we are done :P
argh wrote:I use a very crude method at the moment, just multiply each point by a large enough scalar. I have been thinking of taking the lights height into equation to change the length, but it makes things more complicated. What do you do?
In my previous CPU processed lightning system I used an algorithem to detect the intersection point between two lines and then I'd calculate the intersection point of a raycast with all the sides of the rectangles on the screen, the result would be the the point of where the raycast would end. Have your tried drawing the scene (the rectangles) after applying the shader ?

1st - Draw scene
2nd - Apply shaders
3rd - Stop the shaders
4th - Draw the scene once again
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
argh
Prole
Posts: 11
Joined: Fri Jan 31, 2014 7:07 am

Re: Lighting and Shadow System

Post by argh »

Ranguna259 wrote:I'll start porting the code you linked too, let's compare results once we are done :P
Hey yesterday was slow going, was busy with freelance work. This is how far I am, shaders are ported but the rest needs some tinkering. I think I won't go further with this method as it is purely for shadows. Adding lit objects would mean I would first have to detect shadow casting edges like my subtractive algorithm and then run it through the shaders.
Ranguna259 wrote: 1st - Draw scene
2nd - Apply shaders
3rd - Stop the shaders
4th - Draw the scene once again
I like this :) this article does that too http://www.gamedev.net/page/resources/_ ... dows-r2032

I really lke the simplicity of the subtractive algorithm, it just has some weird edge cases which I may be able to get around.

I was thinking about what you said about shadows overlapping, for me it is ok if a shadow overlaps an entity but not a wall/building and I might be able to get around this with smaller lights and adding big chunks of exclusion geometry for buildings.

I also want to try and add the radial gradient to the shadow and trim the shadow length to the light length.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Lighting and Shadow System

Post by Ref »

One of the limitations of your approach is that it assumes point light sources while displaying finite light sources.
Looks at the shadow of an object which is smaller than the light source.
argh
Prole
Posts: 11
Joined: Fri Jan 31, 2014 7:07 am

Re: Lighting and Shadow System

Post by argh »

Yip the subtractive approach has far to many limitations to be used as a multi light realistic shadow implementation. But it does work well for simple shadow scenarios.

Image
credit: http://forums.tigsource.com/index.php?topic=8803.0

It is also useful for visibility as seen in Teleglitch (Only boundary walls cast "shadows")

Image
Post Reply

Who is online

Users browsing this forum: No registered users and 49 guests