-
playing with light v2
hello. Due to the bad performance of the other light version I had to investigate another method. And with a little research it has payed off :D
here's the result:
(Main) http://littlemofo.soap.com.au/gamedev/lights/
(Debug) http://littlemofo.soap.com.au/gamede...ght_debug.html
the inspiration came from this great article: http://www.gamedev.net/reference/pro.../2dsoftshadow/
but the problem that I quickly found was dealing with a light positioned close to a wall whose length is much greater than the lights radius. The projected edges of the wall would need projections of 20000000 px or similar to mask out the lights radius. So what I did was this:
http://littlemofo.soap.com.au/gamede...ightTheory.png
1 - find intersecting points on the circle add them to edge array.
2 - project line edges out at (radius - edge distance), if > 0 add the edge, otherwise disregard it
3 - sort found edges based on distance to light + distance to lines start
4 - get first 2 closest edges
5 - find angle difference between edges
6 - interpolate between these angles projecting more points
7 - draw from edges to points and back to start to create the shadow geometry
tada!
removing all bitmap drawing / copying and simply using shapes / blendModes gives hardly any performance drop (for 1 light) and light can be massive.
next is giving walls height values. I don't think that trying to implement soft edges is going to be worth it, seeing as you need a custom texture for it to work. I don't like that.
anyway, I'm much happier now :D
-
-
(thats just envy voicing itself)
Looks wicked
-
Looks good and really fast, I guess you got a game in mind which needs semi-advanced lighting?
-
-
Hehe, looks very fast, the debug version is great to udnerstand how you do it.
-
its faster but the light distribution is wrong,- there is no light bouncing this time.
But I guess the more catchy thing this time is that the light shape has a stronger contrast - that might work for games.
-
Very neat demo! I love math toys like this. If you were to extend it to a noncircular footprint you could make a very neat soft shadowed lamp effect (like link to the past but higher quality). As long as the pre-clipped lamp footprint remains convex I think it could be done with similar math.
-
on another thought:
this would be perfectly for a AI checking if items or characters are visible to them and trigger events based on that.
-
Coming from a LJ: "Nice!" It feels real natural, but if you're going for cavernlike envoriments with hard and wet walls, you really should have some radiosity going on
-
thanks everyone :)
hopefully soon i'll have an actual implementation to show you. Moving around a large world with multiple lights / effects.
render - yeah, my thoughts exactly, would also be nice to build the light geometry, so AI could run away and hide from light. Vampire game!
rachil0 - are you talking about spot lights?
thanks again.
-
This looks great, will be keeping an eye out for what you produce with it.. lots of potential!
-
Looks great, I know the lighting in diablo was done tile based but this effect would look cool in a diablo sort of clone. Or zombie game like left for dead except top down. Nice work mate.
-
-
yeah thats what I'm trying to achieve. Never played that game, looks kinda cool.
-
http://littlemofo.soap.com.au/gamedev/lights/
just another update, this time with multiple lights + spot light.
click to move spot light origin. Refresh to get a new layout
there is a big problem with this version though as you may soon find out. And that is the intersection test for a spot light. Currently, if a line exists within the light's cone without intersecting the edges it is not checked and therefore light passes through. I need to somehow check the inner area of the light.
There is a quick and dirty solution (possibly the only solution) which is to create a circle around the extents of the spot light and use that for intersection tests. However walls will be checked that never actually hit the light because the radius will be much larger than the lights edges.
that is the only solution I can think of, a greedy one, but one none the less.
any math guru's out there have any creative input ;)
thanks.
-
success!
thanks to this little page: http://ozviz.wasp.uwa.edu.au/~pbourk...ry/insidepoly/
http://littlemofo.soap.com.au/gamedev/lights/v2/
not sure if its better than simply doing a greedy circluar based intersection test as I need to loop over the points of the spotlight polygon. but its all working nicely. Works like this:
1 - update spot light (if need to) - drawing, plotting polygon edges
2 - loop over polygon checking intersection with polygon
3 - if no intersection, find if the line is within polygon. If so return true (shadow is cast at line edges)
4 - if intersection with polygon (shadow is cast using best intersections.
hoorah!
now to test the speed difference using lots of lines :D (I hope to god this comes out better)
-
ok, last one for tonight:
http://littlemofo.soap.com.au/gamedev/lights/v3/
It only takes around 0-2ms (on my computer) to calculate. But the rendering takes everything. :sigh:
-
-