Search Unity

[NOW FREE] Light2D - GPU Lighting System.

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

  1. kuchaku

    kuchaku

    Joined:
    Oct 14, 2014
    Posts:
    37
    Thank you for the response. This does indeed sound like a great solution and would give a game a cutting edge appearnce to set it apart from others.

    I have one more question. Is the source code or concept documented well enough it might be possible to implement a low resolution implementation (say navigating a low resolution array) on the CPU while using the beautiful version for the GPU?

    I already have a simple Terraria style flood fill algorithm which is drastically less pretty than your system (monochrome, pure block, no penumbra, etc), but there is a single advantage, which is the game is aware of how much visibility is occurring so things like line of sight can be implemented. Even a low resolution version would likely suffice for game play purposes, but if I implement a completely different algorithm it would have a huge disconnect.

    Regardless, I'm looking to pick this up in a bit when money is a bit less tight.
     
  2. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    I think it's easier to write another system than move that one to CPU, because all lighting computations are done in shaders. And I don't quite understand what you want to achieve by porting it to CPU. Do you want to make your liquid system to be affected by Light2D?
     
  3. kuchaku

    kuchaku

    Joined:
    Oct 14, 2014
    Posts:
    37
    Basically it's very possible I'd want the enemies to have access to what the lighting is currently doing (visibility) in their AI programming. Say there is a large black area in between the player and the enemy, I might make it so the enemy cannot see the player and so forth, or allow the player to hide in the shadows from some kinds of enemies.

    As far as I've understood so far, because it is Shader/GPU based I wouldn't have CPU access to the game lighting due to the limited access in communication, right? If I'm incorrect, I wouldn't need to reproduce this at all as I could simply directly access the lighting on the CPU and use it to compute situations like that.

    If needed, I wouldn't intend to adapt the system 'as is' precisely to the CPU (as you said it's shader based), but an algorithm close enough to approximate it would be logical, right, as if the player is hiding in the shadows, and the enemy sees them, or vice versa it would be much worse than not implementing features such as that.

    I'm not fully confident I want or need this feature (stealth and line of sight might end up making the game play worse), but it is possible these features could come in handy for making the game mechanics more interesting so I like to cover as many bases as I can.

    Edit:

    Come to think of it, it might be possible to to use a low resolution render texture and check overall color brightness on the screen without any additional simulation?
     
    Last edited: Jun 15, 2015
    DrKucho likes this.
  4. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    Getting data from lighting texture is planned in future updates. It is not too hard to implement, just need to read pixels from render texture. But that feature will not work on most of mobiles due to poor performance.
     
    DrKucho likes this.
  5. kuchaku

    kuchaku

    Joined:
    Oct 14, 2014
    Posts:
    37
    I see. I'm not spefically intending a mobile game, but this is good to know in the event I intend to branch that direction. Getting Pixels is very a slow method. I managed to get 32 bit version Set Pixels working at a tolerable rate for low resolution simulations, but even adding a Get Pixels command was very noticeable on an i7.
     
    DrKucho likes this.
  6. Gelo_Man

    Gelo_Man

    Joined:
    Jun 6, 2015
    Posts:
    9
    Hey SSS135,

    I was just about to write you asking if it would be easy to add the exact feature kuchaku just mentioned - the ability to know how much in the light/shadow a player avatar is (i.e. getting data from the lighting texture). If there was any way to get that feature into the next update, it would be *REALLY* appreciated!
     
    DrKucho likes this.
  7. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    yeah i also asked for the possibility of reading the amount of light on screen , that would be awesome indeed.
     
  8. alecie

    alecie

    Joined:
    Sep 2, 2013
    Posts:
    73
    How can I make this work with normal maps for sprites?

    For now I have attached normal unitys point light, is it the proper way?
     
    Last edited: Jun 20, 2015
  9. alecie

    alecie

    Joined:
    Sep 2, 2013
    Posts:
    73
    Also, after playing a while I decided to integrate it into my project, I have setup ambient light like in tutorial, but all objects that I place into LightObstacle layer are black. What could cause this?
     
  10. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    Placing objects to LightObstacle layer manually is not needed is most of cases. You may attach LightObstacleGenerator script to object with SpriteRenderer or MeshRenderer and it will generate light obstacles for you. See "Block" objects in SimpeExamples scene, they was made that way.

    Light2D is not designed to be used with Unity lights. Only LightSprite should be used.

    There is two ways to use normal mapping:

    1) Creating material and assigning it to LightObstacleGenerator. You should make a material with "Light2D/Transparent Normal Mapped" or "Light2D/Transparent Dual Color Normal Mapped" shader and set Base and Normalmap textures. Then you neeed to assign that material to "Material" field in "LightObstacleGenerator" script.

    2) Creating material and assigning it to MeshRenderer. Requires a small shader modification or usage of special shaders ("Light2D/Transparent Normal Mapped" or "Light2D/Transparent Dual Color Normal Mapped").
    If you want to add normal mapping to your own shaders add a line to Properties block
    _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    and another line to SubShader/Tags block
    "LightObstacle"="True"

    Height of light source is LightSprite.LightOrigin.z. Bigger height will cause smaller effect of normals.

    Normal mapping is much more expensive compared to standard lighting. Not supported on mobiles or with perspective camera. Normal texture should not be stored in atlas.
     
  11. jprocha101

    jprocha101

    Joined:
    Apr 8, 2015
    Posts:
    134
    @SSS135
    This is probably a silly question, but what about lower end mobile devices that do not have a dedicated GPU or do they all have a GPU of sorts even if its not very powerful? Would this asset still work?

    Thanks!
     
    Last edited: Jun 21, 2015
  12. alecie

    alecie

    Joined:
    Sep 2, 2013
    Posts:
    73
    Thanks for the reply!
    I'm having another issue, I'm getting:
    NullReferenceException: Object reference not set to an instance of an object
    Light2D.CustomSprite.OnEnable () (at Assets/Light2D/Scripts/CustomSprite.cs:85)
    Light2D.LightObstacleSprite.OnEnable () (at Assets/Light2D/Scripts/LightObstacleSprite.cs:42)

    I also had to put UnityEditor into # preprocessor directives in one of your scripts because the game didnt want to build because of that.

    I'm also having an issue that objects are completly black even though I have changed the color and set ambient lightning as in tutorial. And removed normal maps from it in case if that could be a reason.
     
  13. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    All mobiles have some sort of GPU. But Light2D will have poor performance on devices weaker than Samsung Galaxy S 2 or iPhone 4s.

    You could send me your project and I'll see what is wrong with it.
     
  14. alecie

    alecie

    Joined:
    Sep 2, 2013
    Posts:
    73
    I have sent you a message.
     
  15. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    These errors is occuring because LightObstacleMesh and LightObstacleSprite scripts are not meant to be attached to normal objects. They are used in generated light obstacle objects. You could use LightObstacleGenerator script to generate these objects. Just attach it to game object with mesh or sprite renderer.
    Also sprites with mip maps and tight pacing mode could cause some visual issues for shadows. For example on alien spider you need to turn off mip maps and attach LightObstacleGenerator to AlienPng game object.
     
    Last edited: Jun 23, 2015
  16. kuchaku

    kuchaku

    Joined:
    Oct 14, 2014
    Posts:
    37
    Has anyone gotten an indoor/outdoor transition scene proof of concept functioning? A good example is about 10:00 minutes here where the stars fall down from the sky and light up the cave shaft:



    It is effective both for day/night, etc. If this lighting solution could be used to achieve this effect (both indoor and outdoor), there is a high demand for this kind of lighting. I could see it being used in virtually any platformer, but especially sandbox 'seamless' world kinds of projects where the world is dynamic and you can't 'manually' place a transition.

    It would be a make it or break it feature for me being able to use this solution in my game. I'd help with some art assets for a showcase if art is is an issue.

    A full on showcase of the flexibility of this thing would be best if the flexibility exists. If it isn't here yet, and it's possible to get it there, I'd seriously consider looking into your options. Imo, there is a high demand for an efficient lighting solution for 2D games. I'd make sure to showcase platformer, and a top down rogue-like, both of which are heavily in demand (as much as I like Lunar Lander, it's probably the last thing on a lot of developer's minds when working on a Unity Project).

    Most 3D developers are used to taking it for granted that had programmed the graphics pipeline to handle lighting and shadowing. 2D developers have been without efficient/flexible lighting for so long, they probably don't even know what they are missing.
     
  17. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    Hi there!

    I'm making a game with dynamic splitscreen (like the Lego games), so sometimes there are two cameras rendering the level. Would this lighting system work with multiple cameras?
     
  18. Gelo_Man

    Gelo_Man

    Joined:
    Jun 6, 2015
    Posts:
    9
    Hey SSS135,

    Just checking in to see what the status is of the next update.

    Thanks!
     
  19. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    im trying to create a custom light sptire bigger than 128x128 as all included point lights are 128x128 , but no matter the size i create my point light sprite in photoshop , when i use it on a light source it is always the same size than the other lights using the included 128x128 light sprites... ?!?!?

    i know i can just scale the light sprite to make it bigger but i am working in a pixelated game with 1:1 ratio for unity units and pixles and i need a huge point light , if i scale it i get low resolution lighting effect, i can see the pixels of the light sprite super sized inside the illuminated area
     
  20. pan-xiaohai

    pan-xiaohai

    Joined:
    Nov 30, 2014
    Posts:
    6
    Did it support x/z plane, I am writting a top-down shooter game using x/z plane.
     
  21. SSS135

    SSS135

    Joined:
    Nov 26, 2012
    Posts:
    62
    It is working with multiple cameras right now (without normalmapping). Note that you need to attach LightingSystem script to both cameras.

    Hi, Gelo_Man. Next update should be within 2-3 weeks. I'm quite busy right now.

    Try to turn off mip maps in sprite settings. Hope it helps.
     
  22. Velcrohead

    Velcrohead

    Joined:
    Apr 26, 2014
    Posts:
    72
    Hi there, loving the look of this so far.

    Can this be used for rendering dynamic shadows from a animated spritesheet?

    Thank you.
     
  23. xiaohai_pan

    xiaohai_pan

    Joined:
    May 21, 2014
    Posts:
    4
    I am looking forward to your support for XZ plane too , thanks.
     
  24. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,081
    I used this asset once, but it didn't fullfill my needs back then. As of now we've got a tutorial and some more features.
    It also works with 2DToolkit which is exactly what I need.

    Does it also work with Ferr2D: https://www.assetstore.unity3d.com/en/#!/content/11653 ?
    That would be awesome and I'd buy the asset again.

    I've got some problems with Unity Lights on our target device (PS Vita), the FPS drops down from 60 to something between 40 and 50 with only some lights in the scene, Back then when I used this plugin my FPS dropped down from 60 to 30, would like to know if that's still the case.
     
  25. DugelStudios

    DugelStudios

    Joined:
    Feb 21, 2015
    Posts:
    92
    I do not own the asset yet, but I would like to know the following before I purchase:

    1) (MOST IMPORTANT) Is it easy to achieve Terraria/Starbound lighting with this? I want something similar to the picture.
    2) Does this run well on PC, Mobile, and Console?
     

    Attached Files:

  26. danbrani

    danbrani

    Joined:
    Nov 22, 2012
    Posts:
    45
    I'm trying to get this to work with a platformer too, so far the results are pleasing but I have a problem. Where there are many lights in a small area they add up to a white color, I'm not sure how do I go about making the light max out at certain brightness. I've tried playing with the camera/material parameters but to no avail. Any ideas?
    light2d_many_lights.png
     
  27. Gottn

    Gottn

    Joined:
    May 1, 2013
    Posts:
    2
    Lighting System generates obstacles offsetted from sprite, which the left Sprite1 illustrates. This does not happen to the symmetric sprite to the right. Posted a picture on my problem below.

     
    Last edited: Aug 9, 2015
  28. danbrani

    danbrani

    Joined:
    Nov 22, 2012
    Posts:
    45
    I added a BlendOp Max to the light shader and that solved a problem, altough now the blending isn't so smooth. I think that's the best I can do.
     
  29. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    Not sure if the dev still checks this or not. Has anyone had any luck with not blurring ambient lights? I'm trying to block out sections with ambient lights, but even with 'Blur Ambient Light' unchecked, the ambience seems to blur outside the sprite and goes through my walls.

    Edit: I managed to fix this by playing around with the AmbientLightComputer Material properties. Seemed to be something in the way the ambient lighting was calculated that expanded it outside of the sprite.
     
    Last edited: Aug 17, 2015
  30. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    One thing I have noticed with this system is that it doesn't seem to render to a RenderTexture. I'd like to store the result as a RenderTexture rather than having to hook into OnRenderImage again in a subsequent script. Any ideas on how to make it compatible with Camera.targetTexture?
     
  31. Kirbychwan

    Kirbychwan

    Joined:
    Aug 14, 2012
    Posts:
    430
    @danbrani My scripting ability is abysmal, could you please explain how you did so? I'm still having the trouble with the overblown lights, and even less smooth blending would (probably) be preferable to everything getting blown the heck out.
     
  32. danbrani

    danbrani

    Joined:
    Nov 22, 2012
    Posts:
    45
    You need to add "BlendOp Max" in the light shader you're using. In my case it was Light20.shader. You can add it right after the "Blend OneMinusDstColor One" line. This will change the light from additive to Max, which means that only the strongest light will affect a particular point on a screen, instead of all the lights overlapping each other.

    Blend OneMinusDstColor One
    BlendOp Max //Add this line

    One other method I used was changing the brightness of the lights output by converting the color to HSB and then back:

    //this code is right before calculating light in the LightOverlay.shader
    half3 lightSourcesHSV = RGBtoHSV(lightSources.rgb);
    lightSourcesHSV.z = min(lightSourcesHSV.z, 0.5); //instead of 0.5 you can do whatever brightness you want here
    lightSources.rgb = HSVtoRGB(lightSourcesHSV);

    The conversion code is from here: http://ploobs.com.br/?p=1499
     
    Last edited: Aug 22, 2015
  33. arkhament

    arkhament

    Joined:
    Jan 24, 2015
    Posts:
    114
    Hi @SSS135 with Light2D asset it's posible to made or reproduce Scenes/Levels shiny like this? if this can be done so it will be compatible with Mobile(IOS/Android)?:


    Regards,
     
    Last edited: Aug 28, 2015
  34. Phuzz

    Phuzz

    Joined:
    Mar 31, 2014
    Posts:
    47
    This is an amazing asset, Now i got 2D shadows, Pathfinding and 2Dtoolkit all working in my project, it was very painful but great success to myself :)
     
  35. arkhament

    arkhament

    Joined:
    Jan 24, 2015
    Posts:
    114
    DrKucho likes this.
  36. Phuzz

    Phuzz

    Joined:
    Mar 31, 2014
    Posts:
    47
    Hello,

    Im working on a top down project using XZ Axis, all my shadows are pointing upwards in the screen regardless of the shadow position, any help ? :) Moving on Z Axis changes nothing, I saw a similar post here but didnt notice a solution.

    Thank you
     
  37. arkhament

    arkhament

    Joined:
    Jan 24, 2015
    Posts:
    114
    And I want to know if with Light2D asset it's posible to made or reproduce Scenes/Levels shiny like this video in youtube? And if this can be done so it will be compatible with Mobile(IOS/Android)?
    VIDEO:


    Regards,
     
  38. alecie

    alecie

    Joined:
    Sep 2, 2013
    Posts:
    73
    Any idea why I get

    NullReferenceException: Object reference not set to an instance of an object
    Light2D.CustomSprite.OnRenderObject () (at Assets/Light2D/Scripts/CustomSprite.cs:133)
    ?

    It was all working before, I don't know what happened that caused this.
     
  39. Phuzz

    Phuzz

    Joined:
    Mar 31, 2014
    Posts:
    47
    Hello,

    Is there going to be an update? a part of my project is on hold right now that depends on upcoming update, its been a while for an update to fix mentioned topics and i bought this asset only 2 weeks ago. Please update us even if the update is not anytime soon just so I can properly plan my next move,

    Thank you for the great asset.
     
  40. arkhament

    arkhament

    Joined:
    Jan 24, 2015
    Posts:
    114
    no answers? :/
     
  41. maltakereuz

    maltakereuz

    Joined:
    Mar 29, 2015
    Posts:
    38
    In asset description stays:
    >* Supports Unity 5.
    But in commetns stays:
    >Just purchased this, doesn't run in unity 5.1 3 months ago
    It's confusing... So does it works in unity 5 or not?
     
  42. Phuzz

    Phuzz

    Joined:
    Mar 31, 2014
    Posts:
    47
    It works perfect on Unity 5 for me except the XZ axis, all lights are always pointing upwards regardless of where the light source is, if only this was fixed this would be the only good 2D light system in the Asset Store in my opinion
     
  43. binaryprogrammer

    binaryprogrammer

    Joined:
    Jul 17, 2014
    Posts:
    5
    Hi,

    This asset looks amazing! My only question is: Can I use the 2d light sources in custom shaders? I know I could create a 3D Unity light over each of the 2d lights and use that as my light data for a shader, but that seems unduly performance heavy.

    Thanks in advance for you response!
     
  44. Kirbychwan

    Kirbychwan

    Joined:
    Aug 14, 2012
    Posts:
    430
    @SSS135 Any chance of layer implementation or another similar solution? Really need a solution where lights don't affect the sky/specific background layers etc, especially for Platformer style games. Here's an example from my game:



    The enemy emits a small, faint aura of light, but as you can see, the light affects even the background which looks pretty terrible. I imagine most 2D side-view projects are going to be running into this problem.
     
    Last edited: Sep 21, 2015
  45. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    271
    You should actually be able to do this by just using different cameras. Have your background camera render anything behind the lighting affected camera, and a foreground camera render anything in front of it. That's what I'm doing and it works fine. Have you tried this?
     
  46. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    is the developer of this still alive?, seems that he vanished...
     
  47. Mr.Stein

    Mr.Stein

    Joined:
    Dec 4, 2013
    Posts:
    169
    It looks like he got the curse of the "2d light asset" :(
     
  48. Kirbychwan

    Kirbychwan

    Joined:
    Aug 14, 2012
    Posts:
    430
    @gumboots Even with a different camera rendering the background, the result is 100% the same as my example: you still see the circle of light appear over the background. I'm assuming this is because the light is drawn in front of everything. You say it works on your project, though?

    I'm still using 1.2, but judging by the changelogs I didn't think that 1.3 has added this functionality. Could you explain how you set your scene/cameras up so I can compare, if you can? I'd love to get around this issue!

    @DrKucho I seem to remember you asking for camera exclusion for the lights as well, was this actually implemented?
     
    Last edited: Sep 22, 2015
  49. DrKucho

    DrKucho

    Joined:
    Oct 14, 2013
    Posts:
    140
    @Kirbychwan it was never implemented but it works if you use two cameras, i remember i had a really bad time till had the right camera setting, all these unity camera things are so confusing to me but it works, i have a camera that takes the foreground with light2d , this one renders to texture and then a this render texture is displayed in a plane with another camera, here is where i also put all parallax and sky images behind , and in front of it all the game menus, text and other stuff that wont take light.
     
  50. Kirbychwan

    Kirbychwan

    Joined:
    Aug 14, 2012
    Posts:
    430
    So render textures are the way? Interesting, although that sounds like it might run into some problems with different screen ratios. How is performance using that method? Not sure if I can use it that way as my project is using a perspective camera instead of orthographic. Thanks for explaining, though!
     
    Last edited: Sep 23, 2015