Search Unity

[NOW FREE] Light2D - GPU Lighting System.

Discussion in 'Assets and Asset Store' started by SSS135, Mar 14, 2015.

  1. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    It may work, but I doubt you will get good results.

    Support for perspective camera is still limited. As I metnotined in F.A.Q., all light obstacles would need to be on same plane (distance from camera) and perpendicular to camera.
     
  2. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    285
    If you're able to work out a way to have this work in a 3D isometric style of game I think you'd have a very good plugin - It should not be too difficult given that all the work is there. You just need to change your shader math a little to overlay the screen at a different angle.
     
  3. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    Non perpendicular angles is supported from v1.1. Main problem is that lighting will be jerky with perspective camera and light obstacles at different distances from it.
     
  4. spryx

    spryx

    Joined:
    Jul 23, 2013
    Posts:
    360
    @SSS135 Changing the light pixel size does what? Smaller values look better to me, I am using 0.015 at the moment. The tooltip says "Controls resolution of lighting textures. Bigger value - better quality".

    In my experience, smaller values yield better shadow quality, but it also seems to increase the render time.
     
  5. Kirbychwan

    Kirbychwan

    Joined:
    Aug 14, 2012
    Posts:
    430
    Those are acceptable limitations! Most of any light ob
    Hmm, interesting. I don't think that'd cause a huge issue: do they literally need to all be at the same Z-depth? My tilemap layers are generally in a very small range.
     
  6. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    @spryx You're correct. This is a mistake in the documentation.

    @Kirbychwan Yeah, light obstacles need to be at exactly the same Z-depth.
     
  7. Kirbychwan

    Kirbychwan

    Joined:
    Aug 14, 2012
    Posts:
    430
    The shakiness for perspective is completely gone, which is perfect.

    I'm running into issues with the light obstacles, though: even though the light obstacles are the exact distance from the camera as in the camera settings, they fail to have any effect on the light source. No shadows appear!
    http://i.imgur.com/vT2Hlyr.jpg

    The two blocks on the left side are Unity Sprites with a Light Obstacle Generator script on them. The two Statue Sprites on the right are 2DTK Sprites set to the Light Obstacles Layer. As you can see, shadows are being generated, but they're not visible on my gameplay camera.

    Also, not sure if it's a problem or not, but when I follow the readme and Enable 2DTK support, I get two errors in the console:

    PlayerSettings Validation: Requested build target group (0) doesn't exist; #define symbols for scripting won't be added.
    UnityEditor.PlayerSettings:SetScriptingDefineSymbolsForGroup(BuildTargetGroup, String)
    Light2D.Light2DMenu:UndefineSymbol(String, BuildTargetGroup) (at Assets/Light2D/Editor/Light2DMenu.cs:92)
    Light2D.Light2DMenu: DefineSymbol(String, BuildTargetGroup) (at Assets/Light2D/Editor/Light2DMenu.cs:77)
    Light2D.Light2DMenu:Enable2DToolkitSupport() (at Assets/Light2D/Editor/Light2DMenu.cs:64)
     
  8. spryx

    spryx

    Joined:
    Jul 23, 2013
    Posts:
    360
    Having a couple issues here. Sometimes when I add ambient light sources to the ambient lighting layer, they do not seem to affect to ambient light. This only occurs during runtime, and most of the time (90%) adding a sprite to the ambient layer increases ambient lighting.
     
  9. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    interested on this but i'm using 2d tool kit , i have read most of the posts but not sure if there are still issues or they have been fixed all? , mostly worried about this issue -->2. LightObstacleGenerator script is not working with 2DTK sprites.
    does this mean tk2d sprites can't make shadows?
     
  10. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    Sorry for my late reply,

    Seems strange. Error you have posted is not quite an error actually, it should not affect anything. Could you please send me a project with that issue?

    That looks like expected behaviour. You should add ordinary sprites/meshes to ambient light layer, not light sources.

    It was fixed in version 1.2.
     
  11. spryx

    spryx

    Joined:
    Jul 23, 2013
    Posts:
    360
    I meant to say that I am adding sprites to the ambient layer - the problem is, they don't always affect ambient lighting. For example:


    s2.png s1.png

    In the above images, the first has an item on the floor. This is "correctly" illuminated. The item consists of a sprite on the default layer and an additional sprite in the ambient layer (for a glow effect). The item is moved around the screen at runtime. Most of the time, moving the item results in the item keeping its ambient lighting. Sometimes this is lost, despite the sprite still being in the ambient lighting layer. And yes..I have checked the obvious... both sprites have been moved and are correct z depth.
     
  12. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    Sprite on ambient light layer might be too small and somtimes lighting camera can not see it. Try to decrease LightPixelSize value in LightSystem or make sprite bigger.
     
    spryx likes this.
  13. spryx

    spryx

    Joined:
    Jul 23, 2013
    Posts:
    360
    Cheers, that seems to be the issue. Now the problem is optimization... I'd love to leave my light pixels at 0.015..but I get awful mobile performance. :)

    Thanks for the help!
     
  14. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    Why not to use light source? If you don't want it to cast shadows, set its shader to "Light 1 Point".
    If you still want to use ambient light, make sprite bigger, that won't affect performance. Or use sprite with form of circle. I think it will look similiar to what you have now.
     
  15. spryx

    spryx

    Joined:
    Jul 23, 2013
    Posts:
    360
    Because I want the "blur" effect of the ambient layer. I have tried using the light source layer, but it is too additive with the original sprite. This produces a really cool effect... the ambient lighting takes the color of the sprite. Simply scaling the sprites to 1.8 seems to have fixed the issue.
     
  16. Kirbychwan

    Kirbychwan

    Joined:
    Aug 14, 2012
    Posts:
    430
    @SSS135 Emailed you a test project showing the issue!

    @Doghelmer How the heck did you get Light2D light obstructors working properly with 2DTK tilemaps if you don't mind me asking? Although I'm guessing you use an Orthographic camera?
     
    Last edited: Apr 10, 2015
  17. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    Here is a fix if you are experiencing problems with perspective camera. Replace existing file with it.
     
  18. Kirbychwan

    Kirbychwan

    Joined:
    Aug 14, 2012
    Posts:
    430
    Many thanks, that did the trick! :D
     
    Last edited: Apr 13, 2015
  19. ErebosGames

    ErebosGames

    Joined:
    Aug 1, 2012
    Posts:
    6
    Thanks for adding better TK2D support, I purchased this today.

    I just got it working in my project and it's working very well, but I wanted to note something here. My tk2d tilemap is created at runtime, and giving each chunk a light obstacle generator didn't quite work as expected. I found that if I added a light obstacle generator via code at runtime to each chunk, and then I set the multiplicative color - the color didn't visually update. I checked the code of the light obstacle generator class and it looked like its logic was running when it became active, and not if/when the multiplicative color was updated. My quick fix for this was to set the parent of all the tk2d chunks to not active, then add the light obstacle generator and set the color, and then set the parent back to active. Code excerpt below:

    Summary: Line 10 does not take effect without lines 2 and 12.

    Code (CSharp):
    1.             GameObject mainLayer = tileMapRenderData.transform.FindChild("Layer 0").gameObject;
    2.             mainLayer.SetActive(false);
    3.  
    4.             int numChunks = mainLayer.transform.childCount;
    5.             for (int i = 0; i < numChunks; i++)
    6.             {
    7.                 GameObject chunk = mainLayer.transform.GetChild(i).gameObject;
    8.  
    9.                 LightObstacleGenerator lightObstacleGenerator = chunk.AddComponent<LightObstacleGenerator>();
    10.                 lightObstacleGenerator.MultiplicativeColor = new Color(0f, 0f, 0f, .25f);
    11.             }
    12.             mainLayer.SetActive(true);
    That said, now that it's working, it's a beautiful effect. Thank you for developing this!
     
  20. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    Thanks for reporting bug! Will fix in next update.
     
  21. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    I have made a tutorial video for new users.

     
  22. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    thanks for the tut!
     
  23. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    Version 1.2.1 is released. Changelog:
    Added LightObstacleScale property to LightObstacleGenerator.
    Fixed bug with perspective camera.
    64 bit color will be turned off if device is not supports it.
    In-game changes of camera's field of view is correctly handled.
    Removed "Light 8 Points" shader. It will fall back to light 20.
    More shaders documented.
     
    Kirbychwan and Doghelmer like this.
  24. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    867
    Hi,

    I'm looking forward to purchase your asset, and normal map support would *really* make the difference.
    I read they *may* be supported, sooner or later.

    1. How far is this on the roadmap. Is it sure you'll be implementing it?
    2. Getting the amount of light/shadow a certain point on the screen is receiving could be *very* interesting to create monsters that only react to light, or to make the player hide when the light is dimmed. Are you going to add such utility functions to the roadmap? Is it technically possible to create it? Would the function have local scope (ie: getting if a certain light is affecting a point on the screen/world) or global scope (ie: getting if any light is affecting a point on the screen/world)? Or maybe both? ;)

    Thanks for your time.
     
    Last edited: Apr 20, 2015
  25. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    Hi,
    These features will be implemented within 1-3 months, but they probably won't be supported on mobiles.
     
  26. OneShotGG

    OneShotGG

    Joined:
    Nov 16, 2012
    Posts:
    225
    Hi, we are working on a 2.5D game. The game uses 3d models. Will this system work with 3d models?
     
  27. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    Yes it will work, but you should use orthographic camera or all light obstacles should be at the same z-depth.
     
  28. AlexGK

    AlexGK

    Joined:
    Jul 31, 2013
    Posts:
    38
    Is there a way to exclude certain layers from lighting? "Player" layer, as an example.

    EDIT: Nevermind, I answered myself: adding another camera with a higher depth value does the trick.
     
    Last edited: Apr 22, 2015
  29. DomDomDom

    DomDomDom

    Joined:
    Jan 21, 2015
    Posts:
    43
    SSS135,

    On the assetstore page it says that it "Requires Unity Pro (for Unity < 5.0)" Does that mean I can or cannot use it for Unity 5 Personal Edition?

    Thanks for the clarification!
     
  30. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    7,889
    Since there is no Unity Pro in Unity 5, i suppose this is only for Unity 4.
     
  31. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    It will work with any edition of Unity 5.
     
  32. DomDomDom

    DomDomDom

    Joined:
    Jan 21, 2015
    Posts:
    43
    Perfect! Thank you!
     
  33. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    867
    Light2D is on 50% Level 11 sale from April 1 - April 30.

    Hi, I was going to catch the offer and it's April 29 here. Anyway the product appears at full price, yet it's in the Level 11 list. Is it intended?
     
  34. StevenWendel

    StevenWendel

    Joined:
    Jun 18, 2013
    Posts:
    105
    A few users (including myself) have reported this issue with Level 11 in this thread here.
     
  35. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    Hello, my game is for now using standard unity light, i am thinking to purchase your light system but before i would like to know if it would solve a problem i have , i am using a water 2D system that uses additive particles shader for the water, problem is it won't get affected by light, water is always totally bright, look at the pic ,the water on the right should get darker to black , i have tested other shaders but no luck ...

     
  36. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    867
    It was a problem of the store. Issue should be solved now :)
     
  37. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    purchased it yesterday , but i have problems, see picture...



    this could be cause my world map is a unique sprite of of 2048x4096 pixels and your code is trying to render a texture that big?
    or cause i am using a ratio of 1 meter = 1 pixel ?
     
  38. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    increased the pixelLightSize and now it runs, but my world map sprite still gets messed up , all pink

    the grey rock ground is not messed up cause it is another sprite that i didn't add light obstacle generator

    i am doing some tests and i think this is probably cause the world map is using another Asset called Destructible 2D that generates a separated alpha texture for the sprites , this new alpha tex is used to visually destroy parts of the sprite ... so your code is probably taking the texture from sprite renderer , but in this case, it should pick it from Destructible2D.AlphaTexture...

    would you please point me in the right direction so i can make this modifications to your code?

     
  39. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    One of the shaders is failed to compile. Could you please check shaders for errors in Light2D/Resources/Shaders? Also error in first screenshot means that LightPixelSize is too small which causes light textures to be larger than maximum texture size.
     
  40. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    i just checked the shaders and they dnon't show any errors at all, as i said this is probably cause the world map is using another Asset called Destructible 2D that generates a separated alpha texture for the sprites , this new alpha tex is used to visually destroy parts of the sprite ... so your code is probably taking the texture from sprite renderer , but in this case, it should pick it from Destructible2D.AlphaTexture...

    would you please point me in the right direction so i can make this modifications to your code?
     
  41. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    I see pink colors on your screenshots, which means fail in compilation of some shader. I doubt Destructible2D is causing that issue. Could you please send me your project, so I could find a problem?
     
  42. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    ok , i just started a private conversation
     
  43. SamTheBay

    SamTheBay

    Joined:
    Jan 11, 2014
    Posts:
    13
    Hey Guys,

    I just integrated this into my project and so far am really loving it. Thanks for the great asset! I am hitting one issue when using ambient light which is that when the scene starts out its is all blown out and then adjusts itself to the correct value over the course of about a second. Any ideas how to correct this so that it starts at the correct value instead of taking a second to get there? Below is an image of when the scene starts and then after a second or so as the light adjusts...

    BlownOutLight.png NormalLight.png

    Thanks!
     
  44. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    Hi! Call LightingSystem.LoopAmbientLight function with argument between 50-150. It should prewarm ambient light and it won't flash.
     
  45. SamTheBay

    SamTheBay

    Joined:
    Jan 11, 2014
    Posts:
    13
    That solved it. Thanks!
     
  46. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    hey SSS135 thanks for your help fixing my pink problem (lol) i would like to clarify here that the problem was not caused by Destructible2D as i thought , but for, as you discovered, the Light2D materials on my project got broken for unknown reason, after fixing them the problem was gone.

    but then it happens something that i thought it had to happen , if i destroy part of the sprite the shadows won't get updated, this is surely happening cause the light obstacle generator script its only generating shadows at start and it would be needed to re-generate them every time a sprite destruction happens and also minding that the destruction is only happening at the extra alpha texture that Destructible2D uses for each sprite ...

    i know this is not a fail of your software, just an incompatibility, but could you please point me in the right direction so i can make this possible ?
     
  47. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    wops! i already did that , was pretty simple , just to update the generated material wight the D2D Alpha Texture and voila!
    EDIT: damn ! it wasn't that simple, shadows are now updated but the sprite itself is transparent
    EDIT 2: finally i modified the shader DualColor to work with the extra alpha texture, and now everything works :)
     
    Last edited: May 10, 2015
  48. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    now i am trying to make some sprites not affected by light2D , is this possible? i need it mainly for the sky, im testing with another camera and layers/culling masks settings but i can't get it to work
     
  49. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    You may use another camera with higher depth.
     
  50. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    i did manage to get it work for sprites that are on top of the main layer, but it won't work for layers that are behind the mail layer, such as the sky, or at least i don't know how to do it , if i create a new camera just for the sky layer , when all camaras are mixed in the final camera the sky will also get affected by light.