Search Unity

2D Mesh Based Volumetric Lights

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

  1. 2dchaos

    2dchaos

    Joined:
    Sep 11, 2013
    Posts:
    63
    Hello, any chance of having a height parameter for shadow casters so we can have different height shadows? This is the only thing I'm really missing in this asset.
     
  2. fidelsoto

    fidelsoto

    Joined:
    Aug 7, 2012
    Posts:
    87
    Will there be a way to render the lights on different sorting layers (Unity free)?
     
    Last edited: Oct 1, 2014
  3. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @2dchaos - When you say "Shadows" you mean for the object type of 'shadow caster' right? This is the kind of thing I like to know before releasing a Beta so I can add them in ;). I can see how this would be possible with the new method of generating shadows and lights.

    @fidelsoto - Absolutely. There is already a way to change the sorting layer in the Beta version of 2DVLS I had canceled. If you want to add this to your own copy then you just have to set the sortOrder of the lights renderer in the code. If you would like to get a copy of the canceled beta then shoot me an email and let me know.

    @Beinscheibe - I think I found you in my email and I just sent you a message :)

    Thanks guys! I look forward to seeing what you guys think about the new update. Its been a long time coming and I really hope it lives up to expectations.
    Jake
     
  4. 2dchaos

    2dchaos

    Joined:
    Sep 11, 2013
    Posts:
    63
    @reverjake For example, in the image posted by @Chazede we have a daylight scene with a directional light So the shadow casters have simulated heights, so objects with great heighs have a longer shadow, allowing for topdown objects to have more volume. ;]
     
  5. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I forget if your system generates meshes for the shadow or for the light. If it were to create meshes for the shadows, then you could set the z coordinates of the further edge of the shadow mesh to be further in the distance, but the nearer edge a bit closer than the main imagery, so that eventually the shadow `intersects` the 2d x-y plane and cuts off, if you get what I mean.
     
  6. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @imaginaryhuman - Yes it does generate meshes but that might not be the best solution. To achieve what 2dchaos needs I will have to make a shadow caster rather than a 2D light. I can detect edges with the normal facing the inverse direction of the shadow casters direction normal. Then cast rays from those points back in the direction of the caster at the length of the shadow height. If the rays hit something place a point at the collision else place a point at the end of the ray and connect them together. (Plus a bunch of other steps I omitted from above to save from you having to read that boring stuff ;)).

    @2dchaos - Yes this is actually something that I have been asked to create in the past and is something very very feasible. Like I was saying to imaginaryhuman, I can actually allow you to set varying heights for each of your objects and just extend the offset by the height of each of the objects in your scene so you can have multiple heights.

    Jake
     
  7. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Small Update:
    I ran into a bottleneck today by the way with my system. With very complex shapes (many verts) the line-casting seems to bog down performance but I already have an idea on how to fix that. I also want to try unity's built in raycasting again to see if the performance boosts under the hood will actually work in my favor. I will try to keep you guys posted :)

    Jake
     
  8. Deleted User

    Deleted User

    Guest

    :( Unfortunately Jake, I do not have the pro version.
     
  9. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Well hang in the Evorlor, I think I stumbled onto a solution for basic users but I need to develop it a bit further as there are some issues with blending. But it might be possible.

    Jake
     
  10. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Do you have static lights which don't need to update their mesh at all if they don't move and there are no moving objects inside their trigger box?
     
  11. 2dchaos

    2dchaos

    Joined:
    Sep 11, 2013
    Posts:
    63
    @reveriejake thanks dude, I'm very glad I bought your plugin ;D gonna make a nice review
     
  12. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @imaginaryhuman - The current lights should do that with exception for a bug in the directional lights when they are marked as static. If you own a copy did you notice any issues with that?

    @2dchaos - Hey no problem. As I have said before though, it has been a tough issue to solve so I don't want to make any guarantees that my method will end up working.
     
  13. Guacamolay

    Guacamolay

    Joined:
    Jun 24, 2013
    Posts:
    63
    Thanks for the reply! Looking forward to the new update, will also implement some of your suggestions
     
    Last edited: Oct 7, 2014
  14. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @Guacamolay - Looking forward to finishing it ;). Had to take a bit of a break this week but work will resume Friday! My goal is to get the directional lights implemented (yes with height) and I would really like to get the new shaders started if I have time this weekend.
     
  15. 2dchaos

    2dchaos

    Joined:
    Sep 11, 2013
    Posts:
    63
  16. SullyTheStrange

    SullyTheStrange

    Joined:
    May 17, 2013
    Posts:
    147
    Hey @reveriejake, quick question about events. Guessing by the fact that the OnEnter callback passes a Light2D parameter, every single Light2D object will receive these events? And it's up to them to check if they're the one the object has actually entered? If that's correct, is there a reason it operates this way instead of the way Unity's OnTriggerEnter works, where the function is only called on the object being entered?

    Not that it's a huge annoyance to include an "if (_light == light2Dscript)" condition, but I'm worried about possible performance issues if there are a ton of Light2D objects running around with a ton of function calls. I haven't experienced any problems yet but I get a nagging feeling about it.
     
  17. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @Everyone - I spent a good deal of time trying to work out a solution to the Unity Basic shaders but I still haven't quite got an answer yet. I will keep working on it but for now its looking like you might need to use Unity Pro for a "true" lighting effect with Pixel Shaders.

    @2dchaos - Yep, I just finished optimizing the way I was calculating the VLSObstructors. They should take up a lot less memory and hopefully run a lot better but I have not gotten back to the performance testing yet ;). I just need to update the raycasting code to accept the new VLSObstructor vertices. I have been working at my day job like mad to catch up on some financial things but I am able to catch a couple hours every other day or so to work on this. I will have next weekend off and my significant other will be away on a trip so I hope to finally get things to an acceptable level.

    @SullyTheStrange - Yeah the code in the old 2DVLS event system is not very optimal and the code was sort of stuffed into there last minute when I made it during the R&D phase. I never got around to fixing any of that code because so many people started using and even liking how it worked so I decided to just leave it how it is. I haven't gotten around to reimplementing the event system for 2DVLS 4 but if it benefits everyone I could just use SendMessage or something instead of events and delegates. Im not really sure what the best way to do this is so if you have any suggestions feel free to email me and let me know ;).
     
    2dchaos likes this.
  18. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    I would really like to continue working on my own game project soon so hopefully this doesn't take too much longer ;).
     
    Guacamolay and 2dchaos like this.
  19. ShinKazuo

    ShinKazuo

    Joined:
    Oct 28, 2014
    Posts:
    12
    Hey Jake, I've been using your plugin on my game design thesis project, so far it's been helping me save a BUNCH of time!

    Right now I have a top-down pitch black room full of square walls with some lights around to illuminate some areas a little. I made it so the walls' sprite alpha changes from 0 to 1 depending on the distance from the light. You can see on the picture below that walls a little far away from the light source are gray and they get darker as it goes away from the light source.

    The question that I have is: If I have multiple light sources hitting the same wall, how can I determine which one is the closest to set the alpha to the highest value between the possible values? The event listener right now only returns a single light source and not an array of all the lights that hit the object.

    Is there a way for me to go around this? I'm pretty sure there is a simple solution that I'm just not seeing...

    lightscene.png
     
    Last edited: Oct 28, 2014
  20. Guacamolay

    Guacamolay

    Joined:
    Jun 24, 2013
    Posts:
    63
    Any update on the new version?
     
  21. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @Guacamolay Yeah I was working a bit on the Shaders today so I could go ahead and at least get that out to the current 2DVLS users.

    As for the main code, I have been working on getting the system to cache the stuff it doesn't need to update to improve performance. I have also been slowly improving some of the math code. I know they say not to worry about performance until it is really an issue but in the case of creating an Asset for the Asset Store its of major importance due to the unknowns ;)..

    Anyway, its taking longer than anticipated but I still haven't given up on it.
     
  22. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Its always nice to squeeze some extra speed out, especially when it could mean the difference between being able to include some other special effect or something elsewhere.
     
  23. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @imaginaryhuman (or anyone who knows): Do you know of any way of tagging shaders to not render without relying on the gameObject layering system?

    Right now I am adding a tag of "RenderEffect"="VLSLight" to render just the lights into a RenderTexture by calling Camera.RenderWithShader(lightShader, "RenderEffect") which works great but the camera still renders the 2D light meshes normally which I don't want it to do in the normal prelit pass.

    Maybe I should just stick with layers, and maybe I will end up having to, but its kind of a pain in the butt to use for the end user.

    Thanks for any hep!
    Jake
     
    Chaosgod_Esper likes this.
  24. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Artsy image of 2DVLS 4.0. Just so you guys know it is in fact nearing completion ;)

     
    2dchaos likes this.
  25. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I don't know that you can deal with layers, which are external from shaders, within the shader.
     
  26. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    I'm am just wondering if there is a trick to get it so that the main camera doesn't actually render the shader unless its told to without dealing with Layers. Like culling the light meshes only.

    I assume that isn't possible but thought I would ask ;).

    Now that I think about it, I think I understand what your saying.
     
  27. AMO_Noot

    AMO_Noot

    Joined:
    Aug 14, 2012
    Posts:
    433
    Excited to see the progress!

    Just to clarify, since I haven't been able to experiment with 2DTK tilemaps yet;
    it is possible to set a scene's ambient color as completely black and then light it up solely using static and dynamic 2DVLS lights, yes?

    Edit: Disregard! I took a look at some of your devblog posts on 4.0; and the extra light types/features look amazing. Can't wait to implement it into our project.

    VLSArea / VLSAreaCS in particular looks like the perfect solution for lighting outdoor areas.
     
    Last edited: Nov 19, 2014
  28. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Probably not, but I guess as a fudge you could SetFloat to the shader and then the shader, based on that, may simply output `nothing`, or rather, alphablend with 0 alpha, or something, so it's really outputting but it's not?
     
  29. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @Kirbychwan I was just about to respond to your message ;). Glad you saw the blog. I should probably update it again with some more info.

    I have a 3 day weekend this weekend, a 4 day weekend next weekend, and a 10 days off at the end of next month so look for some more progress soon!

    Jake
     
    Guacamolay and 2dchaos like this.
  30. SullyTheStrange

    SullyTheStrange

    Joined:
    May 17, 2013
    Posts:
    147
    Can't wait to see more, good luck finishing up 4.0 Jake! :)

    I'm especially happy to hear about the LOOM multi-threading support, my game has performance issues as it is so hopefully that will let lower-end computers enjoy lighting too instead of having to disable it.
     
  31. Chaosgod_Esper

    Chaosgod_Esper

    Joined:
    Oct 25, 2012
    Posts:
    295
    Any chance to get a normalmapping support?
    Cause i want my Sprites to be normalmapped (like in Ethanon Engine) :D

    And perhaps a Alpha Shader, that allows smooth alpha blending..
    Cause my Sprites can have smooth outlines.. and the cutout looks weird with that ._.

    Edit:
    And a way to use 2DVL lights and Unity standard lights at the same time to light the areas.. Cause when i set a 2DVL Shader on my Sprite, it doesn´t react to the normal lights anymore..

    Edit 2:
    Found an annoying "Feature/Bug".
    I created some more Textures for my Lights, so my Maps can have multiple Lighttypes , caustics and dust effects.
    Changing the texture of one light, changes the texture of all others.. Bad!
    So i created a material for each new texture.
    Now i add the material to my lights, but the light material gets changed back to "RadialLight" immediately!
    The Problem: Your Light Script checks for Radial Light enum, and changes the light material to the hardcoded one...
    Please fix this :(
     
    Last edited: Nov 28, 2014
  32. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Okay guys, I have finished the ProShader 4.0 (not including the new lights). So for those of you who have Unity Pro and would like to try out the new ProShader 4.0 with their existing 3.x lights then let me know via email and I will send you the package.

    The new packages as mentioned are under their own namespaces so there should not be any conflict with the current version of 2DVLS.

    My email: reveriejake87@gmail.com
    Please make the subject "ProShader 4.0" so I know immediately what is needed.

    @SullyTheStrange Glad your excited but I might have to dash your excitement as I'm not sure if LOOM support is going to make it into the final version. When multi-threading you have to break out to do anything with the main thread. This presents some issues that I had not foreseen. I coded a whole terrain engine with LOOM and it worked wonders but this lighting is a completely different beast. :(

    @Chaosgod_Espér
    -
    Right now there are no plans to support normal mapping. With the VLS2D 4.0 source update you might be able to use custom shaders to support normal maps but you will also need to use Unity Pro.

    Semi-Alpha shaders are no longer going to be fully supported in the non-pro version of 2DVLS. There are unfortunately limitations with Unity Basic that I cannot overcome so this is a decision that had to be made from circumstances out of my control.

    @Chaosgod_Espér (Edit 1) Again with the new ProShader 4.0 you will be able to do this as 4.0 supports default shaders on your sprites. If you have Unity Pro send me an email and I will send you the ProShader 4.0 package as mentioned above.

    @Chaosgod_Espér (Edit2) - If you are using multiple textures for lights you need to use multiple materials for each texture. Create a new material, set its shader to the light2D shader, and assign the texture you want. Then assign that material to the light you want to have the texture on. I will check out the bug you mentioned where the material is forced
     
  33. SullyTheStrange

    SullyTheStrange

    Joined:
    May 17, 2013
    Posts:
    147
    Aww, my poor heart. :( I understand though, from my limited use of multi-threading I know how much of a pain it can be.
     
  34. Zilk

    Zilk

    Joined:
    May 10, 2014
    Posts:
    333
    Awesome, when will the new version be live on Asset Store?
     
  35. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @Zilk I promised it would be out months ago ;).... I would love to get it done sooner than later but there are still some minor issues I need to work out.

    Almost had another set back today by the way. I was testing out the new Pro-Shader before zipping it up (It's available now if anyone needs it email me). But anyway, I noticed the source code was in the wrong project folder so I deleted the folder so that it wouldn't cause conflicts with the DLL. Well shortly after deleting the folder I realized that I had actually deleted the true source code to VLS2D 4.0 :mad:.... I think I nearly died... I checked the recycle bin and found nothing! Luckily, I still had Visual Studio open with all of the critical scripts open. I had to be careful and click "Ignore All" when it asked me to refresh though... I was able to save the scripts I had open back into Unity and only lost 3 very minor editor scripts :)

    Anyway, this weekend I will be participating in the Ludum Dare 31 so I wont be working on the code this weekend. I will be streaming the desktop, maybe some music, and maybe occasionally some talk via my twitch channel though @ http://www.twitch.tv/reveriejake If anybody is interested. I might be coding a lot more this week leading up to the dare as well as through the next few weeks up to my Christmas holiday. Then I will have 10 days of holiday starting December 24th so that might be the best time for me to wrap up the VLS2D 4.0 code and then continue working on Quick Ropes 3.0.

    Jake
     
  36. Zilk

    Zilk

    Joined:
    May 10, 2014
    Posts:
    333
    @reveriejake take a look at BitBucket, I always store my private projects on it and commit when finishing up something. Then you always have a backup and can discard changes etc.

    PS. It's free and real easy to use ;)
    https://bitbucket.org/

    Also, looking forward to the 4.0 version! :)
     
  37. bererton

    bererton

    Joined:
    Jun 20, 2014
    Posts:
    34
    Hey Jake/Other 2DVLS users,

    I recently tried 2DVLS 3.3.9 Pro with the latest Unity 4.6.0 release and I'm getting new warning messages of the form:
    Tiled GPU perf. warning: RenderTexture color surface (787x848) was not cleared/discarded, doing <run with profiler for info>
    UnityEngine.Graphics:Blit(Texture, RenderTexture, Material)
    ProShader:OnRenderImage(RenderTexture, RenderTexture) (at Assets/2DVLS/Core/ProShader.cs:132)

    I looked at the code, and it looks like Jake is indeed clearing those textures with a ReleaseTemporary call. Has anyone else looked into getting rid of the warning? It's only a minor annoyance, but would be nice to get rid of as it seems to be inaccurate. This post makes it sound like a DiscardContents call might be needed, possibly in addition to the fact that the editor is using a Mobile Open GL ES 2.0 simulation.

    Anyone else run into this/solve this? I'll report back a fix if I find one.
     
  38. bererton

    bererton

    Joined:
    Jun 20, 2014
    Posts:
    34
    OK, for anyone who runs into the same thing, my solution was indeed to call DiscardContents on the RenderTexture right before it gets copied over in ProShader.cs. Seems to have cleared up the warning messages (which were killing my frame rate). Incidentally this post had some good info about what DiscardContents actually does.
     
  39. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @bererton - Thanks for the heads up. I have been testing the new pro shader in Unity 4.6 b14 but I have not updated to the production release of 4.6 yet. I will do that today and see what I get with the new shader script. If I run into this issue I will look into DiscardContents :)

    Thanks again!
     
  40. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Originally posted on PicoGames.com, for more up-to-date information you can check out PicoGames.com or follow me on Facebook @ facebook.com/picogamesstudio

    I just wanted to throw a quick update out there on what has happened with VLS2D over the past week and what I expect to accomplish in the next 2-3 weeks. I also want to apologize to those who have not had a response from me via the Unity forums and my contact form.

    December 5th - December 9th
    As you might already know, I have been participating in a 72 hour game jam and I was for the most part unable to take time out to read, process, and respond to many questions and issues people had. Yesterday I had to take a day to catch up with family and rest for the crunch that is coming up in the next couple of weeks!

    December 10th - December 24th
    My plans for these dates mostly consist of working at my day-job but in my spare time I will be focusing on wrapping up those long overdue updates for VLS2D 4.0. I am nearly finished with the core mesh generation code but there are still some performance improvements that I need to do.

    December 26th - January 4th
    This will be the big crunch week because I will be totally free to spend the entire day working on VLS2D 4.0 and Quick-Ropes 3.0 updates. I truly expect to finish VLS2D and push it to the Asset Store during this week regardless of any performance issues. If there are any issues with the update from that point on I will just amend them in future updates.

    Quick-Ropes 3.0 update has also been long over-due so once I finish VLS4.0 I will continue on with the Quick-Ropes 3.0 update. It would be optimistic to say that I could finish this update before 2015 and it will most likely be finished sometime in January.

    Contact Note: If you sent me a message via my Contact form and do not receive a response by December 11th at 8am PST, please feel free to contact me again. I will do my best to get back to everyone who sent me an email in the past 4 days.


    Don't forget that the Pro-Shaders update is ready to ship. Please contact me via EMAIL to request the new shader code for Unity Pro.

    - Jake
     
  41. bererton

    bererton

    Joined:
    Jun 20, 2014
    Posts:
    34
    Hi @reveriejake ,

    I just tried the new proshaders in UNity4.6.0. Definitely looking awesome! My one problem since I'm developing for mobile is that the new library does not compile for mobile right now, seems like it's just this one error:
    ArgumentException: The Assembly UnityEditor is referenced by VLS2D. But the dll is not allowed to be included or could not be found.
    UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List`1 alreadyFoundAssemblies, System.String[] allAssemblyPaths, System.String[] foldersToSearch, System.Collections.Generic.Dictionary`2 cache, BuildTarget target)
    UnityEditor.AssemblyHelper.FindAssembliesReferencedBy (System.String[] paths, System.String[] foldersToSearch, BuildTarget target)
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()


    Seems that if you removed the references to UnityEditor in the library for a mobile build that would do the trick. I'd try it, but don't have the source.

    Figured that since 3.3.9 works on mobile it might be good to keep that... especially since you'll be greatly improving the performance with the new lights. Alternatively, I can take a crack at getting it up and running on mobile after you're done with the PC version...
     
  42. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @bererton - Please contact me via my email so I can get you some source code. I need a mobile developer to help test it out anyways. Let me know who you are in your email so I know.

    reveriejake87@gmail.com

    Jake
     
  43. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
  44. EnkiBye

    EnkiBye

    Joined:
    Dec 5, 2014
    Posts:
    1
    Hey Jake

    First thank you for your work, it'll help me a lot on my game design project.

    The only issue I have is that I can't create a pitch black environement with some lights that allow to see the texture on the floor. When I reduce the ambiant light, the texture below the light become invisible.

    Thank you if you can help me.
     
  45. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @EnkiBye - Send me an email please and I will send you over the new ProShaders (if you have Unity Pro) to try out. Otherwise we might have an issue helping you out. Either way send me an email and let me know.

    Jake
     
  46. SullyTheStrange

    SullyTheStrange

    Joined:
    May 17, 2013
    Posts:
    147
    @reveriejake - Is there any way to tell a light to ignore an object so that it doesn't block the light, without changing the object's layer to one the light doesn't interact with?

    Specifically, I'm using it for enemy vision, which uses events to detect the player and items in front of it. If it sees an item, it registers that it sees it with an event, but then the item can block its vision of the player. I can't just change the item's layer because other enemies need to be able to see it too. It would be perfect if I could tell that specific enemy's Light2D to ignore that object after registering it, so it doesn't block its vision anymore, similar to Physics.IgnoreCollision.
     
  47. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @SullyTheStrange - Actually with the current version there is not any way to do this. People have typically added a second invisible light to the first one in order to achieve this.

    I am thinking that I might need to add a FOV class to 4.0 to cover everyone who is using 2DVLS as a FOV system. Or maybe offer a new package on the Asset Store with more FOV type options?

    Jake
     
  48. SullyTheStrange

    SullyTheStrange

    Joined:
    May 17, 2013
    Posts:
    147
    @reveriejake - The second light system will work for now, but we would definitely appreciate or even pay extra for an additional FOV system like that one. :)
     
  49. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @SullyTheStrange - Yeah I was just talking to someone else about going ahead with the standalone FOV system early next year.

    Here is a screenshot of VLS2D 4.0! Its getting very close, I really hope to get this submitted to the asset store next week!

     
    AMO_Noot likes this.
  50. AMO_Noot

    AMO_Noot

    Joined:
    Aug 14, 2012
    Posts:
    433
    Exciting! The beta shaders were working nicely, so I can't wait to implement the whole package into the project.
     
    Last edited: Dec 28, 2014
    reveriejake likes this.