Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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
    This question has come up a couple times this week. Seems to be a new question?

    If you make your light color closer to black then it will be more transparent So say your light is at red (255, 0, 0) and you wanted it to be 50% transparent you would set the light at 50% red (128, 0, 0)..

    Let me know if this helps?

    Jake
     
  2. HarryAtomic

    HarryAtomic

    Joined:
    Aug 24, 2012
    Posts:
    2
    Hi,

    I was looking into buying this but unfortunately I'm stuck with Unity 4.2 at the moment. I see you mentioned a backwards compatible version of the package. Is that available anywhere or do I have to PM you an order number?

    Thanks :)
     
  3. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    I have not submitted the latest update which includes the backwards compatibility so if you do purchase it please PM me or email me with your invoice number :)

    Jake
     
  4. DigiScot

    DigiScot

    Joined:
    Aug 23, 2013
    Posts:
    27
    Jake,

    Just bought this plugin and it's transformed my project instantly, very happy with what you have provided here, but I have one issue in that if I use a 2D sprite as a background, this does not render above it, so you can't see it.

    Also would there be a way to implement so it does not interact with triggers, as well as the current Shadow Layer, I use layers quite extensively for different interactions, so can't easily move all triggers into their own layer!

    Thanks
    Geordie
     
  5. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Last edited: Dec 24, 2013
  6. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Okay I have finally come up with a shader solution for PRO users that will work on any of the default unity shaders including 2D toolkit shaders. I have attached 2 images showing off this new shader.

    The first image is of the 'Create a Light' scene. The background plane is using the default 'Diffuse' shader. As you might know up until this point you had to use a special set of shaders I had in 2DVLS for the lights to work limiting you to cutout shaders. But now you can even use semi-transparent shaders.

    $NewPixelShader_01.PNG

    This second image is of one of the example scenes included in 2D toolkit. I have not changed any of the shaders in the demo. All I did was add my shader to the main camera and the results are below.

    $NewPixelShader_05.PNG

    And finally here is the inspector view. You can set the Ambient color using the setting seen here instead of having to fiddle around with the cameras background color!

    $NewPixelShader_03.PNG

    If you are interested in getting this new shader and you have Unity Pro please contact me and I will send it over to you with some instructions on how to setup the shader.

    I hope to have this in one of the next releases of 2DVLS along with a new video tutorial on how to set it up.

    Merry Christmas!
    Jake
     

    Attached Files:

    Last edited: Dec 24, 2013
  7. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    938
    I just updated to the latest version and it seems definitely better.

    However, it's a bit strange to me that lots of warnings were left laying around (in demo scenes code and the core itself). They're harmful as they're basically about unused variables but would be good if you got rid of them in the next update.
     
  8. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Thanks it has been done for next update :)

    PS: I tried to make the code available for Unity 3.x so it might be some things I forgot to remove while doing that.

    Jake
     
    Last edited: Dec 27, 2013
  9. cc0919

    cc0919

    Joined:
    Apr 5, 2013
    Posts:
    17
    Quick question for you; I'm playing with the events, and can't seem to get them to not fire off when the light is being blocked by another object. Any ideas?
     
  10. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Make sure you are using the built-in events in the Light2D.cs script and not the extra events script I included. If you are only using the Light2D.cs script then let me know and I will see if we can find a solution for you.

    Jake
     
  11. cc0919

    cc0919

    Joined:
    Apr 5, 2013
    Posts:
    17
    Looks like I'm using the Light2D.cs script. Registering events like this:
    Light2D.RegisterEventListener(LightEventListenerType.OnEnter, PerformDeath);

    Not sure why it adds a space in "Type" when I post but...yea.
     
    Last edited: Jan 3, 2014
  12. kauaiBlake

    kauaiBlake

    Joined:
    Feb 28, 2013
    Posts:
    36
    Hi our team is very interested in your asset, but we use Smooth Moves for our main character. I had noticed that previously your asset had issues working correctly with Smooth Moves. My question is this, does your asset, with the new shader you created recently, now work correctly with Smooth moves? I hope so, would really love to use your great work.
     
  13. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Yes it should but unfortunately we have recently come across a bug that needs to be worked out. What we are seeing is that the shader will work as expected in the Editor but fail to render in builds. Once these issues are worked out the new shader will be released to the asset store with the 2DVLS update and it should work with SmoothMoves shaders.

    Jake
     
  14. kauaiBlake

    kauaiBlake

    Joined:
    Feb 28, 2013
    Posts:
    36
    Awesome news Jake! Will be watching this thread for announcements for the bug fix, then will likely make the purchase of 2DVLS. Thanks for all your hard work.
     
  15. cc0919

    cc0919

    Joined:
    Apr 5, 2013
    Posts:
    17
    Hey Jake, any ideas about the events? Am I maybe just doing something wrong?
     
  16. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    So just to be clear you have NOT used the script called "Light2D_EventEmitter" correct? If you use that script it will cause the issue you are mentioning. Other than this I have not really seen this issue.

    Jake
     
  17. cc0919

    cc0919

    Joined:
    Apr 5, 2013
    Posts:
    17
    That's correct, using Light2D.RegisterEventListener
     
  18. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Well I mean you would need to use the Light2D.RegeisterEventListener either way. So I just wanted to make sure you didnt drop that emitter script on anything.

    I will see what I can find.
     
  19. cc0919

    cc0919

    Joined:
    Apr 5, 2013
    Posts:
    17
    Ah...nope. If it is just me though...I must just be doing something wrong.
     
  20. AccidentalCube

    AccidentalCube

    Joined:
    Nov 1, 2013
    Posts:
    14
    Is there/will there be a way to choose what objects are affected by the actual light and what objects cast shadows? For example, I want my player to have a flashlight that will light up certain objects (ie. boxes or items in the game), but cast shadows on other objects (ie. walls or buildings). I've been at this for a long time and haven't figured out how to have it work like this..
     
  21. Wriggler

    Wriggler

    Joined:
    Jun 7, 2013
    Posts:
    133
    I'm seeing this again on Android - it's super bright. Unfortunately I've already ticked "Use 32-bit Display Buffer". Do you happen to have any other hints on how to get this working as expected on Android? I've tried a bunch of things but unfortunately I haven't been able to fix it yet.

    Thanks for your help,

    Ben
     
  22. brainchest

    brainchest

    Joined:
    Jan 14, 2014
    Posts:
    3
    Hi Jake, is this plugin platform independent? I'm especially interested in WP8 and W8. Regards, Stephan
     
  23. dual_good_health

    dual_good_health

    Joined:
    May 13, 2011
    Posts:
    15
    I had the same problem in Android. I fixed it by amending the shader code and changing the line:
    Blend DstColor DstAlpha
    to
    Blend DstColor Zero

    Worth a go, it might fix it for you too.
     
  24. Wriggler

    Wriggler

    Joined:
    Jun 7, 2013
    Posts:
    133
    Hey Stephan, I've tested by game on WP8 and the 2DVLS components seem to work fine. I haven't shipped on the platform yet (or even done a massive amount of testing) so I can't confirm 100% functionality, but so far it seems all good.

    Hey PolityAl, thanks for your comment. Making this change works for me too, although the colour balance of the lighting is changed (as you'd expect). Still, it's good enough for my purposes. Thanks very much for your help!

    Ben
     
  25. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    I have been working on a pixel shader that will do this. It has had a few bugs so it is far from being ready to ship. Development has been a bit slow in the past few weeks due to me starting college again but I will get these loose ends tied up as soon as possible.

    As far as the rest of the questions, it seems like Wriggler has answered them yet again. Thanks again for your help Wriggler! Your a life saver.

    Jake
     
  26. Shubius

    Shubius

    Joined:
    Jan 20, 2013
    Posts:
    14
    Hellow Jake,

    We recently purchased this product and it is amazing. However I have run into an issue I cannot seem to work around. As you can see from the screenshot below the shaders (specifically 2DVLS/Cutout and 2DVLS/Sprites/Cutout) make any sprite or texture I use them on transparent. The scene below used sprites. The sprite on the right and the sprite on the top are using Unity's Sprite-Default shader and the sprite on the bottom and the left are using the 2DVLS/Sprites/Cutout shader. The sprites on the top and bottom are on the same z plane (-1) and the left and right sprites are on the same z place (0) and all are on the default sorting layer.
    Here is what I have tried so far:
    I reopened the sprites in an image editor and made sure there was no transparency and reimported them into Unity.
    I reimported the entire 2DVLS Unity Package.
    Checked the color of the sprite and the tint of the material, both have alpha = 255.

    Using Unity 4.3 Sprites:
    Imported the textures as Sprites, created a material that uses 2DVLS/Sprites/Cutout.

    Using 2DToolkit:
    Imported the sprites as Advanced texture types, applied them to the 2DToolkit atlas, and set the atlas material to use 2DVLS/Cutout.

    In all the above cases the result is identical, my sprites are semi transparent. This is the case regardless of the lights I put in the scene, in fact the below scene has no 2DVLS lights at all, simply these sprites and a default camera in a completely new project with only 2DVLS imported and not 2D Toolkit (in case of a conflict). The results were the same before and after importing the Unity 4.3 patch provided in your files named "Unity 4-3-ONLY_Sprites".

    Any suggestions?
    Thanks in advance.

    $TransparencyProblem.png
     
  27. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Possibly the destination alpha channel of the screen/camera has some data in it. Does your camera's `color` perhaps have an Alpha value greater than 0?
     
  28. Shubius

    Shubius

    Joined:
    Jan 20, 2013
    Posts:
    14
    imaginaryhuman,

    Thanks for your response. I think I solved the issue however. I am not sure exactly why this behavior occurs or if it is a bug but here is what I have found...

    Using two sprites (at least one must have 2dvls shaders on their material, but the issue occurs if both do as well) you can create the same issue like so:

    Place two sprites into the gameworld at 0, 0, 0. Make one of them use the unity 4.3 sprites-default shader and one use the 2dvls/Sprites/Cutout shader.

    Place both of them on the same layer, sorting layer, and same order in layer (just use Default Layer, Default Sorting Layer, and 0 for order in layer).

    From this point the transparency occurs if the 2dvls shaded sprite is moved in front of (negative on the z axis OR more positive in the sorting layer) the sprite-default shaded sprite.

    It also occurs if the sprite-default shaded sprite is moved behind (positive on the z axis OR more negative on the sorting layer) the 2dvls shaded sprite.

    Of course if you place them on separate sorting layers and rearrange those layers you will notice the same pattern.

    Basically you should normally not design your level like this anyway because its counter intuitive to place something further away from your camera in the game world but then tell the system to draw it in front of an object closer to the camera. However, this behavior does not occur with Unity's built in shaders (that I have tried). I am left to assume that this is a bug but it is an avoidable one (unless of coarse you don't catch it when creating sprites procedurally).

    In any case this tool is still amazing, it works, and worth the money.
     
  29. johnny12345

    johnny12345

    Joined:
    Oct 8, 2012
    Posts:
    45
    im after a 2d lighting solution,my scenario is this,if i have a scene say a dungeon the asmosphere will be dark blue in certain areas as my character runs through that scene i would like that area light to influence my characters color and also any sprites i place within the area would your asset achieve this

    thanks
     
  30. liszto

    liszto

    Joined:
    Dec 22, 2011
    Posts:
    135
    Just a simple and fast question about this awesome 2D Light Volumetric, someone test it on mobile and is it worked fine ?
    I don't find any information about that :(.
    I mean there is allocation at runtime that could create spike and nasty lag or freeze issues on mobile phone or tablet ?
     
  31. stulleman

    stulleman

    Joined:
    Jun 5, 2013
    Posts:
    44
    Hello Jake,

    I have a couple of questions if you don't mind.
    My current project is a 2D Top-Down Game entirely existing of SpriteRenderers.
    Simple lighting tests worked just fine, but some things I couldn't figure out myself.

    Do you have any idea on how to make a dynamic sun? (Day/Night-Cycle)
    I don't even know how to make the whole Scene dark, except where lights are.
    If there are simple tutorials about that, I didn't find them :p

    Thanks in advance!
     
  32. empika

    empika

    Joined:
    Jul 12, 2012
    Posts:
    31
    stulleman you can change the ambient light of the scene using the camera background colour.

    ...which leads me to my question. Is i possible to use the scene's ambient light colour render setting for this? I need the background colour of the camera to be black which is way to dark for the ambient light of the rest of the scene. Someone else asked this a few pages back but I couldn't find an answer.

    Thanks, great work other than that!
     
  33. Unnumeric

    Unnumeric

    Joined:
    Jun 3, 2013
    Posts:
    9
    Hi I was wondering how to get 2D lights working with sprites, I have a background that is composed of 2d sprites and the lights do not seem to cast onto them, nor do they create shadows.
     
  34. Chaosgod_Esper

    Chaosgod_Esper

    Joined:
    Oct 25, 2012
    Posts:
    295
    I´ve some problem to get the soft shadow to work...

    when i try to open the sample scene for the soft shadows.. i get:
    so i can´t see the example..


    Soo.. i set my MainCamera, the second Cmarea..etc to the same as the example ones.. and used the Docs..
    Now i only see the Light.. but not the rest of the map anymore..

    ._.
     
  35. empika

    empika

    Joined:
    Jul 12, 2012
    Posts:
    31
    Here's my 2D cutout shader that uses the render settings ambient light instead of the camera background colour

    Code (csharp):
    1.  
    2. Shader "2DVLS/Sprites/Cutout"
    3. {
    4.     Properties
    5.     {
    6.         [PerRendererData] _MainTex ("Base (RGB) Trans. (Alpha)", 2D) = "white" {}
    7.         _Color ("Tint", Color) = (1,1,1,1)
    8.         [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
    9.         _Cutoff ("Alpha cutoff", Range (0,1)) = 1
    10.     }
    11.  
    12.     SubShader
    13.     {
    14.         Tags
    15.         {
    16.             "Queue"="Transparent"
    17.             "IgnoreProjector"="True"
    18.             "RenderType"="Transparent"
    19.             "PreviewType"="Plane"
    20.             "CanUseSpriteAtlas"="True"
    21.         }
    22.  
    23.         Cull Back
    24.         Lighting Off
    25.         ZWrite On
    26.         Fog { Mode Off }
    27.         Blend One One//DstColor DstAlpha
    28.        
    29.         Pass
    30.         {
    31.             AlphaTest GEqual [_Cutoff]
    32.            
    33.             CGPROGRAM
    34.                 #pragma vertex vert
    35.                 #pragma fragment frag
    36.                 #pragma multi_compile DUMMY PIXELSNAP_ON
    37.                 #include "UnityCG.cginc"
    38.                
    39.                 struct appdata_t
    40.                 {
    41.                     float4 vertex   : POSITION;
    42.                     float4 color    : COLOR;
    43.                     float2 texcoord : TEXCOORD0;
    44.                 };
    45.  
    46.                 struct v2f
    47.                 {
    48.                     float4 vertex   : SV_POSITION;
    49.                     fixed4 color    : COLOR;
    50.                     half2 texcoord  : TEXCOORD0;
    51.                 };
    52.                
    53.                 fixed4 _Color;
    54.  
    55.                 v2f vert(appdata_t IN)
    56.                 {
    57.                     v2f OUT;
    58.                    
    59.                     OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
    60.                     OUT.texcoord = IN.texcoord;
    61.                     OUT.color = IN.color * _Color;
    62.                     #ifdef PIXELSNAP_ON
    63.                     OUT.vertex = UnityPixelSnap (OUT.vertex);
    64.                     #endif
    65.  
    66.                     return OUT;
    67.                 }
    68.  
    69.                 sampler2D _MainTex;
    70.                
    71.                 fixed4 frag(v2f IN) : COLOR
    72.                 {
    73.                     float4 c = tex2D(_MainTex, IN.texcoord) * IN.color;
    74.                     float3 lightColor = UNITY_LIGHTMODEL_AMBIENT.xyz;
    75.                     c.rgb = lightColor * c.rgb * 2;
    76.                     return c;
    77.                 }
    78.                
    79.             ENDCG
    80.         }
    81.        
    82.        
    83.     }
    84. }
    85.  
    86.  
     
  36. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    298
    This shader definitely helped, in terms of being able to see my texture and a 2DVL, however the object this is on doesn't respond to other lights, only ambient. Is there a way to have geometry behave exactly as normal (If I point a spot light at it, it will light up), but still have 2DVL show up over it? Or are the two mutually exclusive?

    Basically I'm using 2DVL as vision cones for my AI, now as actual lights/shadow casters. So I want all lighting in the scene to behave as normal, and just have the 2DVL sticking out on front of my AI (Which it's doing now.)

    Any and all help appreciated!
     
  37. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Sorry guys, I have been a bit burnt out on this recently. I have been having a very difficult time getting a good solution together for the shader problems and it has pretty much wore me down. I was excited about the shader I mentioned a few months ago but it turned out to have the fatal flaw of not working in 'builds'. It appears to only work in the editor. So after that I pretty much called it quits and stepped away for a much needed break.

    I have been reading all of your questions. I know it is not the right way to conduct business but if I did not respond to your question it means I either missed it or I just don't know the answer to it. I was tired of giving the same response over again and making false promises that I was not sure I could keep. It is hard to balance support with development!

    I know some of you guys have studios and really cool projects that rely heavily on a trust in the Asset Store developer (me). So I would like to start fresh and hopefully give you guys what you have been asking for. Please understand where I am coming from and I hope you accept my apology. Hope to see you guys soon and I hope you guys will enjoy my next update.

    Thanks,
    Jake
     
  38. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @gumboots: If I understand you correctly you would like to see the 2DVLS mesh (Self-Illum) even if the default Unity lighting is not lighting it up?

    Sorry if I do not understand your question correctly. Please let me know in PM (I know you sent me one already).

    Jake
     
  39. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @Everyone

    Okay with some help and suggestions of various community member I have been able to get the PRO shaders working. Anyone who is interested please give me a shout by using the contact for on my site or senting me an email to jake@reverieinteractive.com

    Screenshot of results:
    Result1 - Darker Ambient Color
    $Result.PNG
    Result2 - Lighter Ambient Color
    $Result2.PNG
    Script Settings
    $Script.PNG

    Thanks guys!
    Jake
     
  40. taylank

    taylank

    Joined:
    Nov 3, 2012
    Posts:
    182
    Hi everyone,

    This is a general technique question: I'm working on a game where I want to have an expanding ring of light effect using 2DVLS. The obvious way to go about that is to change the UV map to a texture of a white ring on a black background, and to keep increasing the light radius to have it expand. It works well to a degree, but the side effect is that the thickness of the ring also increases along with the radius (as the image is stretched across the area), whereas I want to keep the thickness of the ring to a constant value. How would I go about achieving that? Any ideas would be welcome!
     
  41. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    I am honestly uncertain of how this could be accomplished. I don't think its possible with simple UV manipulation but maybe if you were to write a script on top of 2DVLS which will draw a thick line around the light?

    Sorry for my lack of help,
    Jake
     
  42. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    And if anyone is interested... Here is a preview screenshot of what I am cooking up in reference to the comment I made about you guys being happy with what will be coming soon!

    Keep in mind that this will be possible with PRO ONLY. So do not expect these results if you are using Unity Free/Basic. The reason being that the shaders use render textures to achieve these effects.

    Also, this latest version will support ONLY 2D perspectives. This way I can keep the overhead down and bring the best possible product. For that reason I am considering releasing this as a separate pro only package. That decision will be based heavily on whether I can get free promo codes for existing customers (if/when Asset Store adds that ability).

    WIP - Textures are from Sphax BDCraft Minecraft HERE
    $WallBleeding3.PNG

    Jake
     
    Last edited: Feb 16, 2014
  43. kauaiBlake

    kauaiBlake

    Joined:
    Feb 28, 2013
    Posts:
    36
    Great news about the new fixes for the pro lighting shader.
     
  44. Bramlet

    Bramlet

    Joined:
    Nov 8, 2013
    Posts:
    20
    hey, guys, what's the easiest way to make a flickering 2D light?
     
  45. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Thanks Blake, and if I am not mistaken it was you who made the suggestions that helped to get this working so if that is the case an even bigger thanks to you :).

    @Bramlet I think your asking for a script to be written ;). If so you will have to wait for me to get back home to write you a flicker script. But it should be as simple as changing the size and brightness of the light using some random value at some random points in time. But keep in mind that changing the radius will effect performance since the light will have to do an update to see if any new objects are in the lights radius.

    I will see what I can do for you as it will be helpful to the community as well..
    Jake
     
  46. WrongTarget

    WrongTarget

    Joined:
    Nov 18, 2013
    Posts:
    43
    Question,

    I want an object to be lit by 2DVLS light sources. I assume I need to use the 2DVLS diffuse shader on it.
    Now please observe the box. It responds to the 2DVLS light and cast shadow, but, why does the shadow appears over the box itself? Is there some way to control this?

     
    Last edited: Feb 17, 2014
  47. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    You can reduce this by adjusting the blur spread and blur iterations on the camera blur shader (Assuming your using the older method).

    Or you could render the objects you want to appear on top of the lights with a second camera which has a clear mask of depth and a depth setting to overlay the rendered data on top of the lights.

    Jake
     
  48. kauaiBlake

    kauaiBlake

    Joined:
    Feb 28, 2013
    Posts:
    36
    Yeah it was me, glad I could be helpful in tracking that down. Plus now I hopefully can use your lighting tech in our game, so its a win for everyone. :)
     
  49. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Well hopefully it works well for you Blake. Let me know if you have any issues!

    @Bramlet I unfortunately did not get around to writing you that script today but I will definatly get to it tomorrow :).

    Jake
     
  50. space_droid

    space_droid

    Joined:
    Feb 18, 2014
    Posts:
    8
    Hello. I am new to Unity and learning the ropes. I installed this plugin and it works great! One question though. If I am putting a spotlight in my game is there a way to sort of diffuse the edges of the cone so they don't look like a solid straight line? I am looking to do something similar to the spotlights in this video:

    http://www.youtube.com/watch?v=mZZbzp26lss

    I wasn't sure if this was something that can be done in 2dvls or unity in general. Any thoughts or information is appreciated.