A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: playing with light v2

  1. #1
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139

    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

    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:



    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
    Last edited by mr_malee; 10-23-2008 at 10:19 PM.
    lather yourself up with soap - soap arcade

  2. #2
    FK founder & general loiterer Flashkit's Avatar
    Join Date
    Feb 2000
    Location
    Sydney
    Posts
    1,149
    nerd
    Regards Mark Fennell - Flash Kit Founder, general loiterer
    -------------------------------
    I Hate Zombies - iPhone Game | markfennell.com

  3. #3
    FK founder & general loiterer Flashkit's Avatar
    Join Date
    Feb 2000
    Location
    Sydney
    Posts
    1,149
    (thats just envy voicing itself)
    Looks wicked
    Regards Mark Fennell - Flash Kit Founder, general loiterer
    -------------------------------
    I Hate Zombies - iPhone Game | markfennell.com

  4. #4
    Senior Member hatu's Avatar
    Join Date
    Jan 2007
    Posts
    480
    Looks good and really fast, I guess you got a game in mind which needs semi-advanced lighting?
    http://hatu.biz
    Portfolio & games

  5. #5
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139


    and thankyou.
    lather yourself up with soap - soap arcade

  6. #6
    Senior Member Sietjp's Avatar
    Join Date
    Jan 2005
    Location
    Paris, France
    Posts
    711
    Hehe, looks very fast, the debug version is great to udnerstand how you do it.

  7. #7
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    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.

  8. #8
    Senior Member rachil0's Avatar
    Join Date
    Jul 2007
    Location
    Columbus, OH.
    Posts
    465
    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.

  9. #9
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    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.

  10. #10
    Funkalicious TOdorus's Avatar
    Join Date
    Nov 2006
    Location
    Nijmegen, Netherlands
    Posts
    697

    Thumbs up

    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

  11. #11
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    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.
    lather yourself up with soap - soap arcade

  12. #12
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    This looks great, will be keeping an eye out for what you produce with it.. lots of potential!

    fracture2 - the sequel
    fracture - retro shooter
    blog - games, design and the rest

    "2D is a format, not a limitation" -Luis Barriga

  13. #13
    formerly hooligan2001 :) .hooligan's Avatar
    Join Date
    Mar 2008
    Posts
    405
    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.

  14. #14
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    actually nox from westwood had it pretty much the same very well used,- depending on the distance the shadow would fade more or less:



  15. #15
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    yeah thats what I'm trying to achieve. Never played that game, looks kinda cool.
    lather yourself up with soap - soap arcade

  16. #16
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    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.
    Last edited by mr_malee; 10-28-2008 at 03:57 AM.
    lather yourself up with soap - soap arcade

  17. #17
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    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 (I hope to god this comes out better)
    Last edited by mr_malee; 10-28-2008 at 08:58 AM.
    lather yourself up with soap - soap arcade

  18. #18
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    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:
    lather yourself up with soap - soap arcade

  19. #19
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    very sick

  20. #20
    Developer dVyper's Avatar
    Join Date
    Oct 2008
    Location
    UK
    Posts
    168
    very slick!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center