Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  6. Unity 2017.2 beta is now available for download.
    Dismiss Notice

2D Dynamic Shadows

Discussion in 'Scripting' started by Clopay, Jan 7, 2013.

  1. Nimda001_2

    Nimda001_2

    Joined:
    Sep 19, 2013
    Posts:
    60
    Hi Cloplay, Excellent ideas. i'll work on that.Your help is welcome. :)
     
  2. Nimda001_2

    Nimda001_2

    Joined:
    Sep 19, 2013
    Posts:
    60
    Excellent ideas. i'll work on that. Your help is welcome :)
     
  3. Nimda001_2

    Nimda001_2

    Joined:
    Sep 19, 2013
    Posts:
    60
    Since the algorithm detect endpoints of each shape is very easy to get this optimization ..

    I'll change the lines: ->

    allVertices.AddRange(tempVerts);

    by ->

    allVertices.Add(tempVerts[0]);
    allVertices.Add(tempVerts[tempVerts.Count - 1]);
     
  4. Clopay

    Clopay

    Joined:
    Aug 15, 2012
    Posts:
    29
    If I understood you correctly, you swapped

    allVertices.AddRange(tempVerts);


    and put

    allVertices.Add(tempVerts[0]);
    allVertices.Add(tempVerts[tempVerts.Count - 1]);


    in its place? I noticed you had those lines commented out. I tried that, and I got some odd errors :/

    On a sidenote, here's an interesting bug I'm experiencing.
    Screen Shot 2015-01-21 at 8.33.38 PM.png

    It's persistent even when more segments are added to the light mesh. I wonder if it's because the collider extends the radius of the light? I wonder if you just made the initial light mesh a big square?

    Also, thank you for the quick responses & awesome work :D
     
    MaZy likes this.
  5. Nimda001_2

    Nimda001_2

    Joined:
    Sep 19, 2013
    Posts:
    60
    I think that yes, the collider is bigger than light radius.
    I think that yes, the collider is bigger than light radius.

    With tempVerts, maybe should been use when have in scene only convex AND ISOLATE shapes, yes , without contact betweent colliders is the only way that lines commented work.

    Would have to improve this cheap "IntelliMesh" system but risks losing some fps on the road. :)
     
  6. Clopay

    Clopay

    Joined:
    Aug 15, 2012
    Posts:
    29
    Maybe it's not worth it then?

    As for the bug - although the collider extends the radius of the light, I think it could be fixed if you stored the intersection between the light area's mesh boundary and the collider, like this:

    Dynamic-Lighting.png

    What do you think?
     
  7. Clopay

    Clopay

    Joined:
    Aug 15, 2012
    Posts:
    29
    OR...

    I can just increase the light radius, which doesn't affect the UV offset :)
    Adds a few more tris, but nothing significant. Lol.
     
  8. Nimda001_2

    Nimda001_2

    Joined:
    Sep 19, 2013
    Posts:
    60
    I think it would have to store the contact point, however, I can not see a successful outcome in that place of light, therefore store an extra vertex where the result is sloppy in both cases does not seem appropriate. Although clear whether it could be left as an option if you want to add only in certain situations where it is noted the untidiness of the mesh.

    OR... Extends the light radius PLEASE !! lol

    by the way, I love your art
     
  9. Nimda001_2

    Nimda001_2

    Joined:
    Sep 19, 2013
    Posts:
    60
    A little progress with smart mesh builder... call it "Intellider" :)

    intellider.gif

    the only thing is run with single Light ....
     
  10. Nimda001_2

    Nimda001_2

    Joined:
    Sep 19, 2013
    Posts:
    60

    thinking better this may be a more elegant solution.
    you're right.


    fixes.gif
     
  11. Clopay

    Clopay

    Joined:
    Aug 15, 2012
    Posts:
    29
    Thank you! Here's a quick rendering of how I plan to use the lighting in my game. Sadly, it's not an in-game screenshot...yet

    Art-Concept.png

    I know that blindly creating assets without seeing the end result gets a little sterile. I hope this inspires you!

    Wow! That is fantastic and works very well. "Intellider" is a great name for it!

    Here's an idea I have about expanding it for multiple light sources:

    User Implementation

    1. Create a circle sprite like you have (a sphere object or any art will do, really)
    2. Create a child object, add a circular collider to it
    3. Assign this shadow caster to the appropriate shadow layer

    Behind the scenes
    4. Detect if a shadow caster has a circular collider on it.
    5. Detect if this shadow caster is within any light radius
    6. For every light radii this collider sits within, create one polygon 2d collider that extends to the boundary of the circle collider and is perpendicular to each light source.
    7. Make sure it always faces the light source!

    So basically, the circular collider component will not cast the shadow, but let the logic know it is a circle. Also it would be a very easy way for a non-programmer to add a component to game object that would result in circular light.

    What do you think?
     
    Last edited: Jan 23, 2015
  12. Nimda001_2

    Nimda001_2

    Joined:
    Sep 19, 2013
    Posts:
    60
    Yes!! this is inspiring. thanks for share.
     
  13. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    200
    Do you know if it is compatible with Echologin's Core Framework ?
     
  14. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    815
    Hey guys I am sure you already know of it but if you do not, feel free to take a look at my 2d light project on GitHub. I use a custom edge generator in that version but it could easily be adapted to reference 2D collider vertices right out of the gate. You are free to use ideas from that project if you wish.

    https://github.com/reveriejake/VLS2D

    Full disclosure though I might end up re-writing my code into something simple for the Asset Store

    [​IMG]
     
    mgear likes this.
  15. Nimda001_2

    Nimda001_2

    Joined:
    Sep 19, 2013
    Posts:
    60
    reveriejake likes this.
  16. PhilippG

    PhilippG

    Joined:
    Jan 7, 2014
    Posts:
    209
    Hey guys, I just bought 2DDL for a game I'm working on. I really like it, but please warn in your documentation that you use and overwrite Layer 8 for your scripts cause I used it too, surprise surprise ;-)
     
  17. Nimda001_2

    Nimda001_2

    Joined:
    Sep 19, 2013
    Posts:
    60
    Hi @PhilippG ,
    i've just release a new version of 2DDL with layerTagManager fixed.
    Thanks for your feedback.

    https://www.assetstore.unity3d.com/en/#!/content/25933
     
    PhilippG likes this.
  18. RayJr

    RayJr

    Joined:
    Oct 10, 2014
    Posts:
    3
    Has anyone seen an issue like this?

    My game works great on Android. Not so great on iOS. This is the exact same project running on Android and iOS. iOS is the one that looks strange.


    iPod

    2D light iPod.png
    Android
    2D light Android.png
     
  19. gibber10

    gibber10

    Joined:
    Dec 18, 2016
    Posts:
    7
    Anyone know of an asset that caps the ends of the 2D shadows, so that they don't extend off to infinity?

    It would involve projecting the back-facing edges from the light source by a certain amount (that would translate to a kind of fake height above the ground for the light source).
     
  20. gibber10

    gibber10

    Joined:
    Dec 18, 2016
    Posts:
    7
    I'm working on my own 2D shadowing code to accomplish this. I'm generating the shadow geometry instead of the lighting geometry. I'll layer this on top of a quad or something with the light texture/shader.

    I've got this far. The shadows are all stuffed into one unity mesh so rendering should be fast. Whether my shadow generation will be I'm not sure yet!

    The gap in the shadow on the left is due to the verts not being ideally sorted by angle. The nice thing is that the shadows still work when the light is inside a collider, the shadow just appears under the object. Though i do need to detect that there are no terminators and close the triangle loop/ strip in those cases.

    shadows2.JPG

    shadows.JPG