Search Unity

2D Mesh Based Volumetric Lights

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

  1. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Thats why I was asking if anyone had a problem. I just feel like it is much easier for you guys. But if you guys find it easier to use events then no problem leaving it at that.

    I believe Events are in fact faster than the SendMessage function which is why I opted for it the first time around but it makes the code cluttered to have to write the following (pseudo code):

    Code (csharp):
    1.  
    2. // Assign Events
    3. void Start()
    4. {
    5.    Light2D.RegisterEvent(OnLightEnter);  // Not real code, just example
    6. }
    7. void OnDestroy()
    8. {
    9.    Light2D.UnregisterEvent(OnLightEnter);
    10. }
    11.  
    12. void OnLightEnter(GameObject obj, Light2D l2D)
    13. {
    14.    if(obj.GetInstanceID() == gameObject.GetInstanceID())
    15.    {
    16.       // Yeah this is the same object... Call some code here
    17.       l2D.DoSomething();
    18.    }
    19. }
    20.  
    With SendMessage it would look like this (pseudo code):

    Code (csharp):
    1.  
    2. // No register necessary
    3. // No unregister necessary.
    4.  
    5. void OnLightEnter(Light2D l2D)
    6. {
    7.    // We already know were inside the object so no messy code here
    8.    l2D.DoSomething();
    9. }
    10.  
    11.  
    If I used "SendMessage" the message would be called on the hit object since the script containing the function that was called by "SendMessage" would be attached to the object already.

    Maybe I can leave both options open so advanced users can use the events and beginners can just plug and play.

    If anyone has a better way of dealing with events so they match the way SendMessage works let me know but I have no clue how that would be possible.

    Jake
     
    Last edited: May 6, 2013
  2. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    I can see why you did it and it makes sense for beginners but I think you should leave the events for more advanced users as well.
     
  3. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Will do. I might just cutout the "SendMessages" method in the end but feedback is important!
     
  4. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    192
    Events seem more flexible, because I can often just do everything in a single script. If you send a message you have to also have a receiver to do something at the other end.

    Also, I tend to have issues with SendMessage where the receiver gets triggered by other events. Perhaps I'm not using them correctly? Not sure.

    Anyway, I do already have my game scripted to use Events though, so I guess I am biased. ;)
     
  5. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    I prefer events myself but I just remember the day when I had no clue about delegates and events so I was thinking about that. But I decided today to go ahead and just use the events instead of SendMessage. A lot of positive feedback has come about the event system alone so why change what isn't broken :).

    If you include the "DontRequireReciever" parameter in your SendMessage call then you wont need to have a receiver.

    SendMessage is usually called on a gameobject for example gameObject.SendMessage("Foo", param, SendMessageOptions.DontRequireReciever). In that example the 'gameObject' is the object your calling on. So any script with your specified method and parameters inside of that 'gameObject' will be invoked. So if you have 10 scripts with the method Foo(object ob) then all 10 of those scripts will have their "Foo" method invoked.

    Thanks guys for the input!
    Jake
     
    Last edited: May 7, 2013
  6. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    Hi Jake,

    Have you considered the option of putting a parameter to define the number of updates per second that the mesh does? Since this is a very heavy script I'd prefer it to only run a X amount of times per second rather than every frame.

    My game runs at 60fps and it would be unnoticeable if the light mesh only updated like 10 times per second (or even less).
     
  7. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    Well, I just tried this myself and it looks a lot worse than I expected, even when updating the mesh every other frame. So please disregard my suggestion as I don't think it's very useful. :)
     
  8. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    The new code I wrote updates in the FixedUpdate loop. It uses raycast so I think it can be considered a physics object. Im not sure what this will do to performance but at least it does not run every frame.You can try to change the "LateUpdate" loop in your code to the "FixedUpdate" loop.

    Otherwise if I skip frames, the mesh will tear.

    Jake
     
  9. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    I've been trying my 2DVLS project in an iOS device (iPad 3) and I'm getting weird GC calls that are not triggered on the desktop. Here's a screenshot.

    Do you know how to solve this?
     
  10. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Whew... I have not been able to get on here to give a reply all day... The forums were down most of the day for me and I had a major tooth ache that knocked me out for half the day.

    Anyway, I have not seen that on the desktop yet but it is part of C# garbage collection. It is probably a good thing it does it on mobile platforms!

    The only thing I can think of that would cause that would be the mesh leaks when the lights are updated. That issue is taken care of in the next version since I recycle the meshes.

    If anyone knows better please correct me. I am always open to learning things.
    Jake
     
  11. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    Apparently, it happens on my desktop as well. Would be awesome to fix this if possible reveriejake.
     
  12. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Hey there!

    So I am really interested in buying this neat plugin, but before I would like to make some questions, if you don't mind :)

    - does that plugin work on all Plattforms, also mobile Plattforms (iOS/ Android)?
    - does that plugin work with 2D Frameworks like Uni2D or 2DToolkit?
    - is there a documentation, a PDF or some SampleScenes included?
    - can i turn lights/shadows simply on/off in the Inspector or only via code?

    Thanks in Advance! :)
     
  13. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    192
    I can confirm that it works great with 2D Toolkit. Check out my game Luminesca if you'd like to see how it looks!

    The lighting system relies on colliders to create shadows so as long as you have colliders you'll be fine (2D Toolkit can generate them for you, or you can create your own with primitives or meshes).
     
  14. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Thanks CrobarSka!

    The plugin works for Mobile as far as I know. I have not done any benchmarking on iOS yet so I cannot tell you the performance.

    There is SOME documentation and a few sample scenes. More documentation is on my TODO list but if you ever have any questions I am not too far away from an answer. You can email me at jake@reverieinteractive.com, post your question on the forums, or PM me here.

    You can enable/disable your lights in the inspector and via code.

    Jake
     
  15. meta87

    meta87

    Joined:
    Dec 31, 2012
    Posts:
    254
    Your game looks gorgeous! It's sold me on this asset for sure. Good to know about 2d toolkit too, thanks.
     
  16. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Okay guys, so apparently there was a pretty bad leak in the current version (2.6.4) but I have worked out the bugs and the next iteration (2.7.0) will be coming soon!

    I wrote a script that ran test cases on the memory vs FPS. It outputs the data to a google chart webpage. Here are the results!

    V 2.6.4
    $2DVLS_2-6-4_MemLeakTest.PNG

    V 2.7.0
    $2DVLS_2-7-0_MemLeakTest.PNG

    Keep in mind this is after creating/deleting roughly 15,000 light2D objects over a period of 60 seconds. So these results are VERY exaggerated.

    PS: The 'PASS' result is based on FPS from start to finish so disregard that.

    Jake
     
    Last edited: May 13, 2013
  17. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Okay so everyone is updated. I have finished update 2.7.1 after tracking down what might be a couple of memory leaks. The one I had mentioned above was caused by Mesh leaks when destroying and reproducing new mesh objects. The other was the GC.Collect that imteractive had mentioned.

    For the GC.Collect leak it was due to leaked arrays in the heap. I had been calling "myarray = new Vector3[##]" for all of my verts, uvs, normals, and colors. This causes of course a leaked arrays in the heap which is then cleaned up by the garbage collector. I mean what is the GC supposed to do with an array that has no references pointing to it :eek:. Since the mesh updates every Fixed frame, the GC was being called a lot more than it should have been!

    The new shaders are not ready yet. The last I heard from the programmer was that the system might be rewritten. I would really like to see smooth edges on the lights but dont expect that until the next update.

    Anyway, I am waiting for some response from the guys who are beta testing the pack and then I will release the update to the Asset Store.

    Thanks for your support guys!
    Jake
     
  18. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Allright, so I grabbed this Plugin right now. It works really good and is easy to setup, but I can't manage to "light" my Sprites (2D Toolkit Sprites) up or dark them (applying a shadow).

    I uploaded a Picture:



    So, how can I apply the light to the sprite so it will be brighter?

    In the SampleScene here:



    you have that spinning Texture and there it works that when the Character/Lightsource is in front of that spinning Object it becomes brighter, otherwise it is darker again. I would like the same effect on some of my sprites :)
     
  19. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    You will need to use the "2DVLS/Diffuse" or the "2DVLS/Cutout" shader on the objects you want the light to be visible against. I am hoping to get the Simi-Transparent shader in the next major update. These shaders will work with the 2DToolkit however the LIght2D shaders do not support simi-transparent textures as of yet!

    How that helps!
    Jake
     
  20. Trentish

    Trentish

    Joined:
    Sep 9, 2012
    Posts:
    4
    Great plugin so far!

    Unfortunately I hit one snag that's preventing me from using this plugin. It seems the 2D lights are not compatible with the Smooth Moves plugin. Smooth Moves animations use a skinned mesh and seem to require shaders that support alpha blending.

    So add me to the list of people anxiously awaiting the new transparent shader. ;)
     
  21. nia1701

    nia1701

    Joined:
    Jun 8, 2012
    Posts:
    74
    Agreed, I'll be able to use this awesome plugin once it has the semi-transparent shader!
     
  22. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    I am willing to work with anyone who can write good shader code. If you can produce good code that solves these issues then I will gladly pay you for your time. Please email me a jake@reverieinteractive.com!

    Jake
     
  23. OceanBlue

    OceanBlue

    Joined:
    May 2, 2013
    Posts:
    251
    I'm assuming that this won't work wtih SpriteManager2 either? (if it doesn't with smooth moves), as it too requires a transparent shader. I'll be buying as well once a solution is found for this....!
     
  24. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    The test I did with 2D Toolkit seemed to work fine but I did not test the batched meshes. I think Sprite Manager 2 is the same but I cannot say that with certainty.

    I think the issue with Smooth Moves is that the meshes are combined (Skinned) so they do not get the correct depth values which causes strange artifacts.

    I will keep you guys posted on the shaders once I get more information. For now I am releasing the next update tomorrow (2.7.3) as it is finally finished. This one will not include any updates to shaders but includes some performance updates.

    Thanks for the patience!
    Jake
     
  25. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Last edited: May 27, 2013
  26. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Don't know why it is taking so long for the package to be approved guys. My apologies! Hopefully it will be approved by the end of the week though.

    A couple of updates for future development though:
    • I am in touch with a shader programmer and I am working out details for new shaders. I hope we can work out a way to get simi-transparency working, diffuse shaders that dont blend for use with Smooth Moves, and possibly a Post-Processing shader for Pro users though I have not worked out detail on this yet.
    • I am currently working to reduce vertex count on the lights using a new mesh generation method for mobile developers
    • I will be re-implementing directional volumetric lighting once I work out optimization methods.

    Luminesca is using 2DVLS and it is looking amazing! Check it out if you get a chance!
    http://www.luminesca.com/

    Keep in touch! And be sure you also check out the latest example scenes at:
    http://reverieinteractive.com/2DVLS/Documentation/sample_scenes.html
     
  27. CrowbarSka

    CrowbarSka

    Joined:
    Dec 15, 2009
    Posts:
    192
    Thanks for the plug, and the plugin! :D
     
  28. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    No problem! Your game looks amazing so it deserves as much plug as it can get.

    2DVLS 2.7.5 was just approved so update the package if you have not already done so!

    Jake
     
  29. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    I just updated to the latest version and while it seems better performance-wise and with less GC calls, it still has some issues:

    1) There's no way to set the cone direction. The sweep start option seems to have disappeared.
    $Screen Shot 2013-06-03 at 12.31.33 AM.png

    2) There are still quite a few intensive GC calls that give huge performance drops, especially noticeable on mobile.
    $Screen Shot 2013-06-03 at 12.29.43 AM.png

    3) The "mesh leaked" message from the previous versions disappeared (which is awesome!!), but the scene still gets changed as soon as it opens, even if no changes at all are made. This makes it very hard to know if/when to save. It's not a deal breaker but still kinda annoying.

    Hope these issues are easily fixable (especially the first two) because currently it's not usable for me. Thanks!
     
  30. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Hello Imteractive

    1) Having the sweep start was redundant. Please use transform.rotation, transform.Rotate(), or Light2D's LookAt function to aim your light

    2) The CG calls are nearly impossible to avoid as I have said before. I have reduced the calls to a more expected value.

    3) Why do you need to know if the scene has been saved anyway? You should always make it a practice to save the scene whenever you make a change anyway. [I am sorry to hear that you think this minor issue is a deal breaker.] Edit: Question was misunderstood, Sorry about that

    I have tried to accommodate your issues so I am sorry to hear your dis-satisfied. [Edit: This sounded a bit harsh. I meant that for update 2.7.5 I spent a lot of time working the issues you brought up.]
    Jake

    PS: Sorry to sound so short but there are other issues such as shader and improved vertex count that need more attention. I will touch on a couple of your issues in the next few updates, but for now they will not be the main focus.
     
    Last edited: Jun 3, 2013
  31. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    Hi reveriejake,

    Sorry if I sounded harsh, but that wasn't definitely my goal! I'm VERY HAPPY with this plugin and it totally worth the money!!

    Regarding the points I gave:

    1) On my game is not redundant. I need to be able to direct the light manually (in the editor) and currently it's not possible. If I put the Light2D script in a separate GameObject and then rotate it, the target detection goes crazy for some reason.

    2) The GC calls are definitely a lot better than before, but being a perfectionist I wish they'd be completely gone. Unfortunately the hiccups they give to my game are noticeable on mobile.

    3) I said it's NOT a deal breaker, but still annoying on my specific case.
     
  32. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Well as I said, I have a few other issues that I would like to take care of. Last update was mostly an attempt at fixing the issues you brought up.

    1) If you look in the folder called "Helpful Scripts" there is a script called "Light2D_LookAt". If your light is not on the X_Y plane the let me know and I will try to accommodate that. I don't think I will be bringing back the sweepStart variable as it produces a bit more overhead that generally is not needed (with exception to your case). Anyway, if the script I provided does not work let me know and I will take care of that issue.

    2) I spent a lot of time tracking down GC calls and eliminating them. They will occur more often if you use the Events system and there really is no way of eliminating that. I use Physics.OverlapSphere to detect objects and that returns a new array on each update call. That array generation will produce GC calls when the old one no longer has a reference.

    3) Sorry for the misunderstanding but right now I am not too worried about this issue. I made an attempt to fix it but in the end it broke more than it fixed. I wont be spending much time troubleshooting this but if an idea pops into my head while I am working on other issues then I will certainly try and fix that issue.

    Jake
     
  33. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    Thanks for the replies Jake.

    Unfortunately since my game uses built-in navmesh navigation I'm limited to the XZ plane. Also, I'm using the light as a vision cone, and I need to be able to animate it's direction (using built-in animations). Can you please bring back the sweep start setting or any other alternative?
     
  34. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Okay well I guess I can bring back the sweep start. I thought you could animate the rotation value of the lights gameobject. Also did you know that you could create a light without dropping the script on an object. Go to GameObject >> Create Other >> 2DLights >> Radial Light.

    FAQ: "Does this work with 2D Toolkit?"
    Answer: yes and no.

    YES: 2DVLS will work on any collider type that is built into Unity. 2DToolkit also uses these collider types to create colliders! So that means that shadows will correctly be formed off of 2D Toolkit objects with colliders. See my example Bellow!

    NO: The shaders in 2D Toolkit are different from the shaders in 2DVLS so in order to use 2D Toolkit you would have to change the default shader to the 2DVLS shader. The 2DVLS shader currently has a few issues of its own though which I have hired a shader programmer to take care of hopefully by the end of the week.

    FAQ: "Do you have to use primitive shapes for colliders?"
    Answer: No

    You can use any convex or concave shaped collider. You can even have mesh colliders with holes in them. As long as the collider has depth, it should work with 2DVLS. Again, see the image below. The leaf has concave colliders on them.

    Jake

    $2DToolKit_NonPrimitiveCollider.png
     
  35. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    Hi Jake,

    Is there any difference in using the menu to create the light rather than dropping the script into a gameobject?

    Please bring back the sweep start because for some reason, with the latest version, if I apply a rotation to the light gameobject the event detection goes crazy.
     
  36. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Not really other than its easier to setup in my opinion.

    I will bring back the "Sweep Start" variable. But what do you mean by "event detection goes crazy". Please explain. It might be an undetected bug unrelated to the sweep start issue.

    FYI: "Sweep Start" really is not gone, its actually still there except it is automatically adjusted when you set the "Light Cone Angle" variable. so I am worried about what you just said about events.

    Jake
     
  37. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    I'll try to make you a demo to show what I mean.

    However, if you see the screenshot I uploaded in the previous page, I can't see any "Light Cone Angle" variable... I can see it's there on the code but for some reason it doesn't show up on the editor.

    [EDIT] I'm using the latest Unity version - 4.1.3f3
     
  38. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Something is not right then. Have you upgraded to 2DVLS 2.7.5? Try to download it again from the asset store.

    When I get home I will check this out in Unity 4. I did not notice any issues in Unity 4 before I submitted the asset but I could have overlooked it.

    Jake
     
    Last edited: Jun 5, 2013
  39. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    Yes, I'm using the latest version from the Asset Store. Just redownloaded it and still no Light Cone Angle variable available on the editor.
     
  40. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Okay then that is an issue. I will check it out.

    Jake
     
  41. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Okay a couple of issues. The events system had an error where it was registering multiple "OnBeamEnter" events. And I added a new variable called "Light Cone Start"... And I fixed the issue with the editor. Apparently I forgot to add a label to that property so it stayed as "Sweep Start" by default.

    I am submitting a new package to the asset store now.

    Jake
     
  42. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    Great! Glad you found the problems!
     
  43. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Okay new version is up.. (2.7.6)

    Jake
     
  44. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    945
    I just updated and it solved the light angle and event system. Thanks!
     
  45. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Good to hear. Might even reduce GC calls a little as well but I dont know.

    Jake
     
  46. jayhatmaker

    jayhatmaker

    Joined:
    May 14, 2013
    Posts:
    7
    Finally purchased the plugin!
    Is there anyway possible to make certain object trans-lucent?

    For example, I want to cast shadow behind the wall, but I don't want my enemy character to cast shadow.
     
    Last edited: Jun 7, 2013
  47. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    You can choose layers with the "Shadow Layer" setting.

    Block on Right layer = Default
    Block on Left layer = "Ignore Shadows"
    $LayersExample_01.png

    See the option called: Shadow Layer
    This option is set to everything except a layer I named "Ignore Shadows"

    $LayersExample_02.png
     
  48. Wriggler

    Wriggler

    Joined:
    Jun 7, 2013
    Posts:
    133
    Hey Jake,

    Thanks so much for your work on this plugin. I just downloaded it this morning and I'm very happy with it. My game now looks friggin' awesome on the desktop; the new lighting makes such a difference.

    I've just thrown a build onto the iPad, and it seems that the lights are extremely bright and opaque. Everything seems to work well and the framerate is good, but the lights are too bright and dominate the scene. I think the transparency isn't working properly. I noticed that you mentioned you are working on a new semi-transparent shader. Is this for mobile, or something else? Can I expect this new shader to fix the issue I'm having, or is this another thing?

    If you need somebody to test out new mobile shaders then feel free to give me a shout.

    Thanks again Jake!

    Ben
     
  49. jayhatmaker

    jayhatmaker

    Joined:
    May 14, 2013
    Posts:
    7
    Thanks for your response!!
    I'll try to implement that on my project!
     
  50. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Hey Ben, I am going to have new shaders soon. Hopefully they will be good on iPad. I have not heard about the issues you are having yet so thanks for letting me know!

    Jake