Search Unity

2D Mesh Based Volumetric Lights

Discussion in 'Assets and Asset Store' started by reveriejake, Jul 5, 2012.

  1. rosevelt

    rosevelt

    Joined:
    Oct 23, 2012
    Posts:
    47
    Hello,

    I'm interested in your package for a 2.5D game.
    Sorry for my ignorance but Is your system capable of creating all it lighting/shadows without an underneath plane? (scene is floating in space)
    game is PC only, still are any consideration to take in regards to performance (might have up to 80-100 moving object in camera view)?

    Thanks
     
    Last edited: Oct 14, 2013
  2. Azzizi

    Azzizi

    Joined:
    Mar 7, 2013
    Posts:
    5
    Think I've figured out what's going on! 2D Toolkit builds a non-standard collider, and it appears that the errors crop up because sometimes the raycasts miss the polygons of the collider. This might be a PhysX/Unity limitation at work.Basically, though, the tilemap collider doesn't seem to be 'solid' enough for the lights to always pick them up in certain cases.
     
  3. Yukichu

    Yukichu

    Joined:
    Apr 2, 2013
    Posts:
    420
    Did the latest version break webplayer compatibility? It seemed to work previously and after upgrade... doesn't seem to work. No scripting or prefabs, just create a new Light2D object and that's it.
     
  4. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Maybe their colliders just have a small depth in the z direction?

    Glad you have found the issue though! I was kind of stumped.

    Jake
     
  5. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Not sure if you are the same person who emailed me with this issue but I ran a couple of tests and cannot get it to break in the webplayer. Is there a specific way you are setting up your scene or instantiating the lights that I need to check out to duplicate this bug?

    Jake
     
  6. Azzizi

    Azzizi

    Joined:
    Mar 7, 2013
    Posts:
    5
    You can set up 2D toolkit colliders with whatever amount of z-size you want-- mine are definitely clipping the lights. It seems to just be the way Unity's raycasts work against a mesh collider or whatever 2D toolkit is using-- my raycast-based character control also sometimes misses the collider. For now, it's manageable, so I'm considering it No Big Deal<tm>.

    Another question: any chance we could get a feature where we can have colliders that trigger events but don't cast shadows, maybe when they're set as triggers? I was looking through the code a bit, but I don't know the code well enough yet to hack such a thing in. I'd like to use the light events to set a flag on characters (one of my core concepts is that Friendly fire turns on if you aren't illuminated)-- but I don't want the characters casting shadows. I can work around it a bit, but I'd rather avoid it if possible.
     
  7. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    I am definitely interested in doing something like this and it has been requested a few times now. But for now the easiest way to do this would be to create 2 light objects. One with a transparent texture that has your events on it and another which is your visual representation.

    Jake
     
  8. marcdes

    marcdes

    Joined:
    Oct 16, 2013
    Posts:
    4
    Hi just got the plugin and it's working nicely for what i need.
    I was wondering about these 2 errors i keep on getting:

    NullReferenceException
    Light2D.UpdateMesh () (at Assets/Light2D/Core/Light2D.cs:569)
    Light2D.Draw () (at Assets/Light2D/Core/Light2D.cs:465)
    Light2DEditor.OnEnable () (at Assets/Light2D/Core/Editor/Light2DEditor.cs:38 )

    and

    UnassignedReferenceException: The variable _renderer of 'Light2DRadial' has not been assigned.
    You probably need to assign the _renderer variable of the Light2DRadial script in the inspector.
    Light2D.Draw () (at Assets/Light2D/Core/Light2D.cs:486)
    Light2DEditor.OnEnable () (at Assets/Light2D/Core/Editor/Light2DEditor.cs:38 )

    Any ideas on how to get rid of them ?
     
    Last edited: Oct 24, 2013
  9. Azzizi

    Azzizi

    Joined:
    Mar 7, 2013
    Posts:
    5
    Yeah, that's what I'm planning to do as a workaround for now. If it's on your list for enhancements, that'll do for me for now. It'll probably be a bit of a performance issue eventually, but I'm a long ways off from worrying about that.
     
  10. John-Lattin

    John-Lattin

    Joined:
    Oct 7, 2013
    Posts:
    14
    How would you want this to interact with shadowcasters? Do you want it to ignore all Light2D interactions (other than events)? This is actually super easy, just check where it does the ray calls and an if statement to check if the object is "skippable" if it is, just add it to the event list as normal, and skip over the rest of that code. Alternatively you can make it even easier, but slightly less accurate, by having it add to the event list in the pre-check, where it calculates which objects are in the plane and in the correct angles, or area, depending on if it is in the Light2DRadial or Light2DBeam (you will need to add this in both spots), and if it is, just add it to the list, but don't add the points for scanning. This is less accurate as a few bugs can come up such as another scan zone being near this area and it will still hit your object, etc. but it is faster.

    Unfortunately I don't have the code in front of me, but if I remember when I get back I can give you an example of each.


    *EDIT* this will actually improve performance, because less operations will need to be done, however it only improves performance for those specific objects, not overall. On other objects it adds an insignificant amount of overhead. *EDIT*
     
  11. marcdes

    marcdes

    Joined:
    Oct 16, 2013
    Posts:
    4
    Nevermind, I reimported the plugging and the errors went away, I have another issue though, when using an orthographic cam, a plane with a decal shader on it and a cylinder with radial light, rotated x=90 as a child (360 angle, 4 radius, hide if covered un-ticked) using the 2DVLS/Light, if the plane isn't underneath the light shows, but it won't if its over it. (and i'm using the OpenGL ES2.0 setting).
    I'm have no idea what i'm doing wrong and any help would be greatly appreciated.
     
  12. _Simmo

    _Simmo

    Joined:
    Oct 20, 2013
    Posts:
    17
    Hey, I bought this recently, and it's super easy to set up and use, loving it :)

    But I'm having the same issue as Azzizi where my generated terrain with script generated collision doesn't cast shadows properly a lot of the time (misses corners, etc), and causes strange artifacts as i move around the level

    Here's a shot of the collision mesh and a bad raycast in the editor:
    $bug4.png

    You can see the ray casting at a strange angle, as if it think the collision mesh isn't the shape it is. Maybe it's confused by the vertices?

    Is there a way around this? Can I make the ray casting more accurate (even at the cost of efficiency) so it will detect the edges of the collision mesh more accurately? Anyone else experienced this problem and found a solution? I couldn't find any cases in this thread.

    Any help in this regard would be really appreciated :)

    Cheers
     
  13. cpasjuste

    cpasjuste

    Joined:
    Apr 2, 2012
    Posts:
    154
  14. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    I leave for 1 week and the thread explodes. No emails saying you guys are posting anything!

    @_Simmo: I am defiantly interested in this issue. It apparently happens when using 2DToolkit? I think it has something to do with Mesh Colliders, but we will see what we can find.

    @cpasjuste: Looks good! Thanks for showing off your work.

    Jake
     
  15. rsklnkv

    rsklnkv

    Joined:
    Sep 8, 2012
    Posts:
    62
    Hi,

    Changing those lines in Light2D.cs
    Code (csharp):
    1.  
    2. void LateUpdate()
    3.     {
    4. ...
    5.  
    to
    Code (csharp):
    1.  
    2. bool calculatedOnce = false;
    3.     void LateUpdate()
    4.     {
    5.         if (gameObject.isStatic  calculatedOnce)
    6.         {
    7.             return;
    8.         }
    9.        
    10.         if (gameObject.isStatic)
    11.         {
    12.             calculatedOnce = true;
    13.         }else
    14.         {
    15.             calculatedOnce = false;
    16.         }
    17.  
    removed 5.8k allocations and 1ms of processing for every frame (useful for static lights with static geometry only)
    otherwise performance is not OK
     
    Last edited: Nov 12, 2013
  16. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Thank you!

    I was curious about how many people even knew they could do static lights! The code was there but the new (3.x) code is still being optimized so please expect some issues in various situations.
     
  17. rsklnkv

    rsklnkv

    Joined:
    Sep 8, 2012
    Posts:
    62
    Is there any way how I can make a global sun with finite shadows? (right now beam light casts infinite shadows, that doesn't look correct)

    Thanks
     
  18. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    No not really. But this might be an awesome feature to add in the future!
     
  19. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,162
    have you tested it with unity 4.3 2d sprites?
     
  20. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    It does not work yet with the 2D colliders in 4.3 but I am currently working on getting that implemented.

    This will actually require more work than meets the eye so apologies if the release comes before the fix to 2D colliders.
     
  21. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,162
    it is released :) i sent PM to you.
     
  22. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Thanks atmuc! I replied to your PM.

    Okay guys, I did not realize 4.3 was being released today so I spent a few hour trying to put everything together. Here is a screenshot of the finished product. I will be passing this version out to anyone interested in testing it in the next day or 2 before I release the 4.3 patch.

    $2DCollidersx.PNG

    Jake
     
  23. rsklnkv

    rsklnkv

    Joined:
    Sep 8, 2012
    Posts:
    62
    In 4.3 I have another issue - when I select light and try to move it - mesh constantly regenerated (it's fine), but that gives a problem - light pivot always jumps around the screen and you can't position your light
     
  24. Kafar

    Kafar

    Joined:
    Nov 29, 2012
    Posts:
    220
    Hi,

    When will be released the 4.3 support version?
    Thanks
     
  25. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    I am working on 4.3 right now :). Not sure when exactly but I am off to visit family next Monday for a week so I would really like it to be done by Sunday night.

    Jake
     
  26. Lolko

    Lolko

    Joined:
    Oct 15, 2012
    Posts:
    5
    Hi
    Sorry for my newbie question. Is 2D Volumetric Lights asset works with FREE version of Unity 4.3 ? If yes what are the differences between Free and PRO version using Your asset ?
    Greetings
     
  27. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Yes this package will work with Unity 4.3 and there are no differences between the free and Pro versions. The only thing you wont be able to do are soft lights.

    As a note, right now the lights do not support 2D colliders introduced in unity 4.3 but I am working on the update. I tried to get the update out before last weekend but I had a few bugs that I could not figure out before I left to visit family. I wont be able to continue work on the project again until next week.

    Hope that helps!
    Jake
     
  28. Kafar

    Kafar

    Joined:
    Nov 29, 2012
    Posts:
    220
    Hi reveriejake,

    After installation I obtain the persist exception below, I have Unity 4.3 Pro.
    Thanks in advance.

    -Kafar


    - Assets/Light2D/Samples/Sample [Soft Shadows]/Pro Blur Shader/CreateAtClick_2DVLS_PRO.cs(36,32): error CS0117: `Light2D' does not contain a definition for `Create'

    - Assets/Light2D/Samples/Sample [Soft Shadows]/Pro Blur Shader/CreateAtClick_2DVLS_PRO.cs(92,96): error CS1061: Type `Light2D' does not contain a definition for `LightRadius' and no extension method `LightRadius' of type `Light2D' could be found (are you missing a using directive or an assembly reference?)

    - Assets/Light2D/Samples/Sample [Soft Shadows]/Pro Blur Shader/CreateAtClick_2DVLS_PRO.cs(92,66): error CS1502: The best overloaded method match for `UnityEngine.GUILayout.HorizontalSlider(float, float, float, params UnityEngine.GUILayoutOption[])' has some invalid arguments

    - Assets/Light2D/Samples/Sample [Soft Shadows]/Pro Blur Shader/CreateAtClick_2DVLS_PRO.cs(92,66): error CS1503: Argument `#1' cannot convert `object' expression to type `float'

    - Assets/Light2D/Samples/Sample [Soft Shadows]/Pro Blur Shader/CreateAtClick_2DVLS_PRO.cs(92,42): error CS1061: Type `Light2D' does not contain a definition for `LightRadius' and no extension method `LightRadius' of type `Light2D' could be found (are you missing a using directive or an assembly reference?)

    - Assets/Light2D/Samples/Sample [Soft Shadows]/Pro Blur Shader/CreateAtClick_2DVLS_PRO.cs(107,99): error CS1061: Type `Light2D' does not contain a definition for `LightConeAngle' and no extension method `LightConeAngle' of type `Light2D' could be found (are you missing a using directive or an assembly reference?)

    - Assets/Light2D/Samples/Sample [Soft Shadows]/Pro Blur Shader/CreateAtClick_2DVLS_PRO.cs(107,69): error CS1502: The best overloaded method match for `UnityEngine.GUILayout.HorizontalSlider(float, float, float, params UnityEngine.GUILayoutOption[])' has some invalid arguments

    - Assets/Light2D/Samples/Sample [Soft Shadows]/Pro Blur Shader/CreateAtClick_2DVLS_PRO.cs(107,69): error CS1503: Argument `#1' cannot convert `object' expression to type `float'

    - Assets/Light2D/Samples/Sample [Soft Shadows]/Pro Blur Shader/CreateAtClick_2DVLS_PRO.cs(107,42): error CS1061: Type `Light2D' does not contain a definition for `LightConeAngle' and no extension method `LightConeAngle' of type `Light2D' could be found (are you missing a using directive or an assembly reference?)

    - Assets/Light2D/Samples/Sample [Soft Shadows]/Pro Blur Shader/CreateAtClick_2DVLS_PRO.cs(118,99): error CS1061: Type `Light2D' does not contain a definition for `LightConeStart' and no extension method `LightConeStart' of type `Light2D' could be found (are you missing a using directive or an assembly reference?)

    - Assets/Light2D/Samples/Sample [Soft Shadows]/Pro Blur Shader/CreateAtClick_2DVLS_PRO.cs(118,69): error CS1502: The best overloaded method match for `UnityEngine.GUILayout.HorizontalSlider(float, float, float, params UnityEngine.GUILayoutOption[])' has some invalid arguments

    - Assets/Light2D/Samples/Sample [Soft Shadows]/Pro Blur Shader/CreateAtClick_2DVLS_PRO.cs(118,69): error CS1503: Argument `#1' cannot convert `object' expression to type `float'

    - Assets/Light2D/Samples/Sample [Soft Shadows]/Pro Blur Shader/CreateAtClick_2DVLS_PRO.cs(118,42): error CS1061: Type `Light2D' does not contain a definition for `LightConeStart' and no extension method `LightConeStart' of type `Light2D' could be found (are you missing a using directive or an assembly reference?)
     
  29. taylank

    taylank

    Joined:
    Nov 3, 2012
    Posts:
    182
    Hi, I have a small problem with the radial light in full screen mode. I have a small script attached to the light that changes the radius with a lerp when the user presses a key (trying to create the effect of a god ray hitting the player on cue). The script works just fine in the game window when testing with unity editor. If I maximize the game window, however, the light disappears. It comes back when I tick off maximize. If I then maximize the game window while it is still running, the light appears just fine. So it just doesn't play nice with modifying the radius value in full screen mode for some reason.

    The light also does not appear in the windows build, regardless of full screen or windowed mode.

    Sorry if this is a noob question. Am I missing something obvious?

    Edit: Just realized, this is only happening when the light's origin point is outside the camera's view. If I position the light inside the view, the lerp works just fine. Still not a solution, though, as I do need the light's origin point outside the camera view.

    Edit #2: In fact, the light won't appear in game mode (maximized or not) if it is not also visible in the scene edit window.
     
    Last edited: Nov 29, 2013
  30. Wild-Factor

    Wild-Factor

    Joined:
    Oct 11, 2010
    Posts:
    607
    I have the same problem than kafar.
    Is it possible to simulate the sun ? A directional light ?
     
  31. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @taylank and @Kafar I have finished work on my patch for 4.3 and will be submitting it to the Asset Store soon. All I have to do is update the sample scenes, do a few tests, and clean up some documentation.

    @Wild Factor: Yes there is something called a "Beam Light" it might fall under a different name in the next patch but the directional light will be there none the less.

    @Kafar: These errors happened after you unpacked the [Soft Light Sample]? I will take a look at making this a bit more intuitive on next release. For the time being you might want to just take a look at the soft light tutorial in the documentation to set it up manually. If you have any trouble please feel free to contact me via jake@reverieinteractive.com or via the contact form at my website (link below).
     
  32. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Demo of the lights working with both 2D and 3D colliders!

    http://reverieinteractive.com/2DVLS/CreateLight2D/

    Right Mouse = Drag lights around
    Left Mouse = Create lights


    Creating the Rocks
    I used the texture below to create the isometric rock effect.
    $Rock2.png

    The blue part of the texture is the collider that goes at the base of the rock. You import the texture as a 'sprite' and split them out. Place the rock texture then parent the blue collider texture onto the rock. Deactivate the renderer on the blue texture after adding a 'polygon collider 2D' to it. :)
     
    Last edited: Dec 2, 2013
  33. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Current and Future Beta

    If anyone who has purchased 2DVLS would like to join the beta you can sign up to the mailing list HERE.


    This will be the mailing list I will use for future early releases as well. You must provide a valid invoice number to register. Anyone who registers with an invalid or duplicated invoice number will be removed from the list.

    Thanks for the support!
    Jake
     
  34. MakinStuffLookGood

    MakinStuffLookGood

    Joined:
    Nov 20, 2012
    Posts:
    21
    The beta program is an awesome idea! Looking forward to the next release.
     
  35. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Thank you! I am actually getting ready to send out 3.1 beta 2 so if you have not already joined you should join now ;).
     
  36. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    I have a question about this asset.

    would it be possible to detect which pixels of given texture were being touched by a light and make them invisible. To be clearer...

    hide/reveal the part of an object that is being lit?

    This could be cool for stuff like secret messages that are revealed with light or things that disappear when you shine the light on them.
     
  37. Jon-Gao

    Jon-Gao

    Joined:
    Dec 9, 2012
    Posts:
    17
    Well... I've a little problem
    $Fullscreen capture 1272013 13238 AM.jpg
    I use sprite renderer, but 2d light doesn't "above" the sprite. normal 3d object is working though.
    but I saw your new demo for 4.3 it work fine. is something wrong?
    my version is 3.0.
     
  38. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    I am working on the update patch for 4.3. The version I posted above will be 2DVLS 3.1.

    If you were signed up for the beta you can expect a package very shortly.

    Jake
     
    Last edited: Dec 6, 2013
  39. Jon-Gao

    Jon-Gao

    Joined:
    Dec 9, 2012
    Posts:
    17
    Got ya! thank you :)
     
  40. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
  41. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,037
    I'm not having any luck combining this with an overhead 2D Toolkit tilemap.

    The Radial option doesn't light up if the light is over the tiles, whether Scene view or Game view. The tilemap just remains black.

    Shadow shows something that looks sort of correct in Scene view (first image), but is too bright in Game view (second image):
    $sceneview-20131215-032418.jpg $gameview-20131215-032548.jpg

    Nothing in the tilemap layers blocks the light to create shadows, but the editor window shows that it theoretically calculates the right things:

    I've tried all the supplied shaders on the objects, but I'm not 100% sure if it's the right place. The character in the
    middle has regular 2DTK shaders because it shouldn't be affected by light/dark, so that's fine.

    The light was centred above the character, which has a box collider slight larger than it. I moved the light to the side
    and got this:
    $repositioned-20131215-033142.jpg

    So I disabled the collider, and suddenly nothing in the tilemap was lit up anymore. Just the lone character on a
    black background. When I switched the light back to Radial I got the same results as the Shadow light above.

    I also tried adding a cube with the 2DVLS diffuse shader, and got this in the editor:
    $otherobjects-20131215-034209.jpg

    But the running scene just doesn't look right:
    $misfortune-20131215-034342.jpg

    If I could get something closer to that editor view with adjustable intensity, it would be perfect for my intended use.

    There's a combination of problems here. I can't find a good place to replace the tilemap's shader. That's definitely a 2DTK
    problem, and should be solvable with some digging, maybe. But it's strange there isn't a simple place to just drop an alternative
    in. But the other problem is with the volumetric lights and brightness. Opacity does nothing, and there isn't much left of the
    textures being lit. The area covered in the Scene view also looks much larger than the area actually being lit.

    The behaviour of Radial/Shadow lights doesn't make much sense to me either. I've tried different lighting models with no
    change.
     
  42. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Hmm I just imported TK2D into my project and started playing with it. It does not seem to work with their tile map system! I will have to look further into this so thanks for bringing it to my attention. I think this is a whole new issue separate from the previous problem with TK2D posted on this forum. As far as I know that first issue has been solved.

    Anyway, I will see what we can come up with.

    Jake
     
  43. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,037
    Thanks! So it wasn't just my sleep deprivation :)
     
  44. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Nope its not sleep deprivation but these shaders are killing me lol.

    Jake
     
  45. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,037
    Yeah, shaders are the bane of some people's existence.

    The tilemaps have a material applied to various chunks down in the hierarchy, so I suspect I might need to apply some code, perhaps modify the tilemap scripts themselves, to make the whole map use different shaders. I'm just too tired to dig deep myself at the moment, so I hope you can find something :)
     
  46. Chaosgod_Esper

    Chaosgod_Esper

    Joined:
    Oct 25, 2012
    Posts:
    295
    I´m getting over 900 errors after importing the package...

    These are the console messages (some appear multiple times):

    using Unity 4.2.2 Pro
     
  47. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Email me please. You must have 4.3+ to use the version that is currently on the asset store but I have just finished a version that will work with previous versions of Unity.

    Please give me your order number if you have it.

    Jake
    jake@reverieinteractive.com
     
  48. onemanhorde

    onemanhorde

    Joined:
    Mar 16, 2013
    Posts:
    2
    When I reload the scene, the lights don't show up?
     
  49. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    I have not seen this happen yet on my end. Is there any more information you can give me?

    Are you reloading the scene using Application.LoadLevel?

    Jake
     
    Last edited: Dec 16, 2013
  50. onemanhorde

    onemanhorde

    Joined:
    Mar 16, 2013
    Posts:
    2
    It was my bad, the lights toggled themselves off in my scene before hand, I have a question is there anyway to make the light more transparent?