Page 2 of 5

Re: Lighting and Shadow System

Posted: Sun Feb 02, 2014 6:55 pm
by Ranguna259
You're welcome ;)

Re: Lighting and Shadow System

Posted: Sun Feb 02, 2014 7:46 pm
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?

Re: Lighting and Shadow System

Posted: Sun Feb 02, 2014 7:52 pm
by Ranguna259
You could just make a circle with x radius and apply something like a fade from center shader to the circle.

Re: Lighting and Shadow System

Posted: Mon Feb 03, 2014 7:05 am
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?

Re: Lighting and Shadow System

Posted: Mon Feb 03, 2014 7:36 am
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

Re: Lighting and Shadow System

Posted: Mon Feb 03, 2014 7:56 am
by argh
I have updated my subtractive method with a smooth radial gradient light shader https://gist.github.com/seanpackham/8727943

Image

Image

Re: Lighting and Shadow System

Posted: Mon Feb 03, 2014 9:31 pm
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

Re: Lighting and Shadow System

Posted: Tue Feb 04, 2014 8:29 am
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.

Re: Lighting and Shadow System

Posted: Tue Feb 04, 2014 3:38 pm
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.

Re: Lighting and Shadow System

Posted: Thu Feb 06, 2014 7:16 am
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