Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

2D Dynamic Shadows

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

  1. Nimda001_2

    Nimda001_2

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

    Nimda001_2

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

    Nimda001_2

    Joined:
    Sep 19, 2013
    Posts:
    63
    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. StuffMattDoes

    StuffMattDoes

    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:
    63
    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. StuffMattDoes

    StuffMattDoes

    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. StuffMattDoes

    StuffMattDoes

    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:
    63
    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:
    63
    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:
    63

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


    fixes.gif
     
  11. StuffMattDoes

    StuffMattDoes

    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:
    63
    Yes!! this is inspiring. thanks for share.
     
  13. Gruguir

    Gruguir

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

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    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

     
    mgear likes this.
  15. Nimda001_2

    Nimda001_2

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

    PhilippG

    Joined:
    Jan 7, 2014
    Posts:
    257
    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:
    63
    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:
    8
    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:
    8
    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
     
  21. adrianadrian

    adrianadrian

    Joined:
    Mar 8, 2015
    Posts:
    7
    Hey @gibber10 how did you go with this? I'm looking into doing something similar with the capped shadows from a side perspective instead of top down. Would you recommend this method?
     
  22. BHUnity

    BHUnity

    Joined:
    Jul 28, 2018
    Posts:
    1
    Hey, I'm using the free version for evaluating the product, and the script is giving the error:



    Don't know where else to report this
    Code (CSharp):
    1. InvalidCastException: Cannot cast from source type to destination type.
    2. DynamicLight.getAllMeshes () (at Assets/2DLightAsset/Scripts/2DLight/DynamicLight.cs:111)
    3. DynamicLight.Update () (at Assets/2DLightAsset/Scripts/2DLight/DynamicLight.cs:95)
     
  23. Nimda001_2

    Nimda001_2

    Joined:
    Sep 19, 2013
    Posts:
    63
    upload_2018-7-30_11-13-54.png
    Check this checkbox.
     
  24. Aykutkaraca

    Aykutkaraca

    Joined:
    Jan 4, 2018
    Posts:
    33
    Hi Nimda, Do you still have the free version on the asset store? I am not able to find it.
     
  25. Nimda001_2

    Nimda001_2

    Joined:
    Sep 19, 2013
    Posts:
    63
  26. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,050
  27. unity_zHFaHnEs2Lt1ng

    unity_zHFaHnEs2Lt1ng

    Joined:
    Sep 5, 2018
    Posts:
    4
    Hi guys,

    I have a question. I'm trying to render soft edges with 2DDL pro (the way it is explained in the documentation) but here's my question : is it possible to blur the lighting system without blurring the background ? It seems impossible (at least with the documentation method) but, I don't know... Is there a way ?

    Thenk you verry much, love this asset !