Search Unity

[RELEASED] SpriteLights

Discussion in 'Assets and Asset Store' started by Elecman, Oct 10, 2015.

  1. ghtx1138

    ghtx1138

    Joined:
    Dec 11, 2017
    Posts:
    114
    @Elecman sorry for the late reply. I can't send a repo unfortunately. I'll try again. Thanks
     
  2. b1gry4n

    b1gry4n

    Joined:
    Sep 11, 2013
    Posts:
    146
    What would be the best way to implement the lights turning off at a close distance?

    My use case would be similar to the way LODs work. I want these pixel lights to turn on at a certain distance from the camera and when the camera gets closer it would turn off/less bright. I imagine it would be the opposite of the Attenuation, i am just not experienced enough with shaders to implement this myself. Any help is appreciated.

    Thanks
     
  3. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    The easiest way to turn off the lights is to turn off the mesh renderer (or just disable the game object). To reduce popping you can first slowly dim the lights. You can dim the lights with the shader variables like brightness offset. I didn't try attenuation but I guess that would work also.
     
  4. Ttravi

    Ttravi

    Joined:
    Jan 22, 2018
    Posts:
    32
    Good afternoon.
    I have 3 problemas at the moment:

    1- Distance based. Even using a scene were I somehow managed to generate the lights correctly, trying to create a light at runtime or bringing a light that was saved as prefab result in it not rendering well at distance:


    2- Lights I generated on other scene are "rotated", instead of always facing camera.

    3- Generating just one light at point zero of a GameObject has a little offset. The lighpoint is not perfectly centered.
     
  5. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Try calling the init function again after generating a light at runtime. Make sure the correct init variables are set (mainly camera FOV and screen height). This might be the cause of the flickering problem.

    Is the rotated light problem also present in the video?

    Light locations are relative to a game object so if the game object is offset, the light will be too.

    If you can't fix it, send me a small repo and I will have a look.
     
    Ttravi likes this.
  6. Ttravi

    Ttravi

    Joined:
    Jan 22, 2018
    Posts:
    32
    Sadly it still not working.

    I've put the SpriteLights.Init(); method call on Update and even so the behaviour didn't change:

    https://git.technolabs.com.br/ttravi/runtime-sprite-lights
     
  7. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Thanks for the repo. Unfortunately it does not contain step by step instructions how to reproduce the problem. The repo does not match the video (colreglightsmanager game object missing in scene).

    Things I need (but kind of found out poking around a bit):

    -Which scene and where this scene is located (lots of scenes present. Maybe I am using the wrong one?)
    -How to make the single light which is flickering (something to do with colreglightsmanager I guess but it doesn't create the light you show in the video).
    -Which source files contain the code which creates the light, and which line nr.
    -Some screenshots, which "other scene" and line of code for: 2- Lights I generated on other scene are "rotated", instead of always facing camera. I don't really understand what you mean.

    In general with these things it is better to remove all fluff from the project (using a copy of course), make real simple code which demonstrates the problem, so no fancy editor stuff etc, and provide clear step by step instructions how to reproduce the problem. I understand that this takes (possibly a lot of) time, but it also takes time for me trying to figure out what you did in your project and code.

    Anyway, here are some things I found, digging around a bit:
    -lightData.position = l.transform.position; is not zero. That is why the light is a bit offset.
    -You can fix the flickering light by giving it a bigger size (try 1.0) and setting the brightness lower, like 0.2f. If you don't want to use a smaller light size (it really isn't that big unless you put your face in it), set a smaller scale but increase the minimum screen size on the material a bit.

    Side notes:
    -You can change the fly speed by using the 1 and 2 keys (single fire, so press a few times).
    -I noticed some payware in your project so you probably don't want to make the link public and send it to me privately instead.
     
    Last edited: Jun 28, 2019
    Ttravi likes this.
  8. Ttravi

    Ttravi

    Joined:
    Jan 22, 2018
    Posts:
    32
    I'll do these adjustments ASAP! Thanks for your feedback, I'll keep in touch.
     
  9. onedot-jt

    onedot-jt

    Joined:
    Jul 26, 2019
    Posts:
    3
    hi, I'm new to unity.
    I want to show 20K moving points with spritelights, is there a way to make it faster?
    how can I modify the mesh without create a new mesh?

    thanks
     
  10. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    This was bug report explanation was helpful for me :
     
  11. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    You can do that using this reference:
    https://docs.unity3d.com/ScriptReference/Mesh.html

    You probably want to look into Unity Jobs, ECS, DOTS, etc to make this faster.

    Another option would be a skinned mesh, but I have never tried that.
     
  12. onedot-jt

    onedot-jt

    Joined:
    Jul 26, 2019
    Posts:
    3

    Thanks for the advice.
    I'm also thinking create 20k cubes, and move them around. would it be more expensive? It would be an easier way for me if it works.
     
  13. onedot-jt

    onedot-jt

    Joined:
    Jul 26, 2019
    Posts:
    3
    btw, the things I'm trying to do is to show a point cloud with 20k+ points. and the points are generated by a 3d camera, so it is refreshing every often.

    now I'm using your spritelight to create new meshes repeatedly. it turns out every slow(it needs 3 seconds to update once). I need at least 3-5 updates in one second.
    the output I need can be formed by points, cubes, or surface. since you are an expert on points, could you give me some general advice. is there an easy way to do it?

    Thank you very much.
     
  14. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    20k cubes would definitely be more expensive to render because they have 12 triangles each instead of only 3 and they are also separate objects, so 20k draw calls instead of only 1.

    But the definite way to know for sure is to try and benchmark it.
     
  15. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    It shouldn't take 3 seconds to create 20k points so you probably have redundant code in your loop. Calling the SprightLights api isn't going to be fast because it creates a new mesh every time. Instead, modify an existing mesh and cache as much data as possible and don't put so much code in your loop.

    I think there is a point cloud package somewhere on the asset store too.
     
  16. Ttravi

    Ttravi

    Joined:
    Jan 22, 2018
    Posts:
    32
    Uhhh, thanks, I guess.
     
    AlanMattano likes this.
  17. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    I found an easy tweak to get even faster performance. Set the light texture to point sampling with a max size of 32. It gives the same quality in my experience.

    On fast video cards this only makes a difference if a lot of lights (millions) are in view and slow video cards it gives you 10+ FPS even if not that many lights are in view.
     
    Last edited: Aug 21, 2019
    HenryChinaski and AlanMattano like this.
  18. ncho

    ncho

    Joined:
    Feb 1, 2014
    Posts:
    99
    Is there any way to actually force the "shimmer" effect when the camera is not in motion?
    I got a little bit of that "shimmer" by ever so slightly shifting the mesh position through a looping animation but I can't really get it to be more obvious without the shifting getting noticeable. Can the attenuation of the lights actually be individually and randomly changed in some way?

    IMO the effect is actually a feature not a bug since distant lights at night also have that going on...some games also implement it really well eg GTA 5.

    Great asset by the way.
     
    Last edited: Dec 7, 2019
  19. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    I love how passionate and dedicated is @Elecman
     
    hopeful likes this.
  20. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Not sure about the (heat?) shimmer. I never tried that. I think a post effect would probably be better because other things should shimmer too. Is there a video from this in GTA5?

    The attenuation cannot be individually changed unless you modify the shader. The brightness can be individually changed but this will be hardcoded into the mesh and cannot be animated.
     
  21. HenryChinaski

    HenryChinaski

    Joined:
    Jul 9, 2013
    Posts:
    108
    Hi!

    I just wanted to thank you for your awesome asset and that you decided to make it freely available.
    Moreover, you even offer support for it that is not available in that quality for some hundred € assets I bought...

    The sprite lights look incredibly awesome in our game, even though it has nothing to do with flight simulation.
    We use it to visualize a faraway city from the players perspective. I can't wait to show you some screenshots in a few months!

    Thanks again and I hope you have a happy holiday season.

    Best regards from Germany,
    Daniel
     
  22. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Thank you for your kind words.

    Can't wait to see what you build with it :)
     
    HenryChinaski and AlanMattano like this.
  23. Undertaker-Infinity

    Undertaker-Infinity

    Joined:
    May 2, 2014
    Posts:
    112
    Wow thanks for releasing this.
    I haven't tried it yet, but looking through the asset store comments, I found someone with this issue: "FormatException: Input string was not in a correct format", and mentions it could be due to using a period as a decimal separator.
    I was bit by this in another asset, so I may know what causes it.
    When I migrated a project from .Net 3.5 to .Net 4, one asset that parsed strings started crashing. Turns out it was .Net 4 using the locale to convert numbers (it didn't use it before), and in spanish we use comma as a decimal separator, thus the parser finds a period and it dies.
    The solution, which I believe is compatible with .Net 3.5 too, is to pass the locale while converting.

    Converting numbers to string:
    Before: in USA locale it would yield "1.1234", but in spanish locales it would yield "1,1234"
    value.ToString("#.####")
    After: in all locales yields "1.1234"
    value.ToString("#.####",CultureInfo.InvariantCulture)

    Converting strings to numbers:
    Before: would expect strings in the form "1.1234" in USA locale, but in spanish expects "1,1234"
    float.Parse(value)
    After: expects strings in the form "1.1234" in all locales
    float.Parse(value, CultureInfo.InvariantCulture)

    Doing it like this also avoid changing the culture of the whole thread, which may interfere with the host application.

    Hope this helps :)
     
  24. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Ok, thanks. I will look into it.
     
  25. LeonaWest

    LeonaWest

    Joined:
    Mar 7, 2017
    Posts:
    8
    Hello,
    How can I avoid applying Billboard with OmniSimple shader?
    I want each light to point in a different direction.

    Thanks
     
  26. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    That is not how the shader works. Each light has to be a billboard, otherwise it will start to flicker when the viewing angle becomes too big. OmniSimple lights are designed so that they are always visible, no matter the viewing angle or distance.

    If you want each light to point to a different direction, you have to use one of the other light shaders, not the OmniSimple shader. These lights are also billboards but the light intensity changes with the viewing angle, which is done in the shader. The other light shaders are a bit more expensive to render but you probably won't notice a difference in frame rate because all shaders are extremely fast anyway.

    Edit:
    To clarify, there is a difference between the appearance of a light lens and and lens flare caused by the light. SpriteLights simulates the tiny lens flare caused by a distant light. As you get closer to a light in real life, you start to be able to see the light's lens. The light lens does look like a regular object and should not be a billboard. If you want to display a light lens, you still need an entirely different shader. In that case you will need to two objects at the same time. One with the light lens shader and one with the sprite lights shader.
     
    Last edited: Apr 28, 2020
  27. cultureulterior

    cultureulterior

    Joined:
    Mar 15, 2015
    Posts:
    68
    Love the asset! FYI, LWRP has been renamed to URP in the 9.0-previews, so the shader includes look in the wrong directory.
     
  28. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Ok, thanks. Will fix that.
     
    cultureulterior likes this.
  29. Justin-Wasilenko

    Justin-Wasilenko

    Joined:
    Mar 10, 2015
    Posts:
    104
    Thanks for this asset, just slight issue when using the default rendering pipeline (maybe the others too) that Single Pass rendering mode is not supported. When using SinglePass mode, the sprites render only in the Left eye.
     
  30. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Unfortunately I couldn't get Single Pass Rendering to work. It seems there is a bug in the Unity rendering engine which doesn't like vertices being offset in the shader, or at least at the time when I was looking into this.
     
    PNC_SW and AlanMattano like this.
  31. bbjones

    bbjones

    Joined:
    Feb 1, 2016
    Posts:
    85
    First, huge thank you for sharing this asset and your knowledge and research. It is rare to find this much information about how and why an asset like this was put together.

    In my case I go from flying (using your typical implementation for runway lights etc) to landing and going on foot in first person.

    I'm working through that transition from sprite lights to normal unity lights/emission/LOD etc, but was wondering about buildings and interiors, and if you gave it any thought while working on this asset? Mainly about how interiors appear as rectangles, or perhaps a plane/cube but inside a room so the only visible portions are through windows.
    Or if you're close enough to make out a rectangular window shape you should just be using an emission map anyway?

    For example, in this image the distant lights can simply be normal sprite lights, but in the medium distance range you can see the rectangular light through office floor windows.
    https://upload.wikimedia.org/wikipedia/commons/f/f6/Ho_Chi_Minh_City_Skyline_(night).jpg

    Each room (or entire floor or entire building) could be turned on or off at runtime.

    And about the transition to FPS/normal lights and emission, thinking about when you land the plane. The lights closest to the plane could still be sprite lights, but they should be smaller/less bright perhaps than lights at the end of the runway which are still 2-3km away. Would you do something like a lerp method to adjust the lights from close to far as you land and taxi down the runway or simply switch to Unity lights sooner and not mess with trying to animate the sprite light behaviour?

    Cheers
     
  32. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Hi, sorry for the late reply. Watch thread was off.

    I didn't consider buildings and interiors but that is indeed a good use case. I imagine that the LOD transition has to be at a big distance though, due to the size of the objects.

    I did think about doing LOD transitions for runway lights, but the issue with that is (and also with building interiors) that the light mesh is one single mesh object and modifying individual lights is not performance efficient.

    I think it is better just to leave the light mesh alone (always on) and instead, switch the high res objects on and off on an individual basis. But this has little to do with SpriteLights itself.

    I am not actively working on this asset anymore, just fixing if something breaks. Let us know here if you come up with something which works.
     
    AlanMattano likes this.
  33. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,687
    Maybe have your distant LOD with spritelights on one layer and up close environment on another layer, and render different layers with different cameras?
     
  34. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Yes, that could possibly work.
     
  35. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Important update

    I decided to make SpriteLights paid asset. This whole covid situation has caused a significant loss of income from my regular day job so I need to generate some additional income.

    I will continue to update SpriteLights and provide support in return. The latest version has these changes:

    -Made the HDRP shaders compatible with latest pipeline change.
    -Added an Editor Script which converts GameObjects positions or vertices to SpriteLights. No coding required.
    -Updated deprecated code in the Build-In pipeline package.
    -Updated the SimpleLights example with added brightness parameter.

    If you previously downloaded the asset, free updates should still be available. If you would like to donate and support the project, don't hesitate to buy it anyway :D

    Thank you for your support.
     
    TerraUnity likes this.
  36. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    The asset is worth it! Is there a way to convert particle positions to sprite-lights?
    Maybe by using mesh particles?
     
  37. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    If there is a way to get the particle positions in C# then they can be converted to SpriteLights. Personally I never worked with particle systems before so from the top of my head I don't know if it is possible to get individual positions. I will have a look at it.

    Edit: it is possible using the particle system.
    https://docs.unity3d.com/ScriptReference/ParticleSystem.GetParticles.html
    Example:
    https://forum.unity.com/threads/par...not-get-individual-particle-positions.710954/

    With the vfx graph it is not possible yet, but the feature is under consideration:
    https://portal.productboard.com/8uf...tribute-buffer-read-access-from-outside-graph
     
    Last edited: Aug 26, 2021
    Lars-Steenhoff likes this.
  38. TerraUnity

    TerraUnity

    Joined:
    Aug 3, 2012
    Posts:
    1,255
    I always loved SpriteLights, even though never had a chance to try it out. Hope it covers some expenses for you and wish you great success, it really worth it ;)
     
    Elecman likes this.
  39. inkostyakov

    inkostyakov

    Joined:
    Nov 14, 2016
    Posts:
    48
    Hello! Thanks for awesome asset!

    I'm trying to modify PAPI shader, to create light which is visible only on certain vertical angles (example on linked image. 24 degrees for example).

    angleLight.png .

    Could you give me some advice how to do it? I'm not very familiar with shaders

    Thanks!
     
  40. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Are you sure you want to have a sharp sudden falloff like that? Real light have lenses which give them a bell shape falloff, not sudden.

    The PAPI shader is designed to change color depending on the up/down viewing angle. Do you need that too or does it need to be a single color light?
     
  41. inkostyakov

    inkostyakov

    Joined:
    Nov 14, 2016
    Posts:
    48
    Yes, I need color depending on the up/down viewing angle. But I want to set angle for Color1 (inside 24 degree), and Color2 if I above OR bellow this angle.
     
  42. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    In that case it is much easier to just set the rotation angle of the light in the mesh. If you have a look at the light mesh struct, you will see that it has a quaternion variable. You can use this to set the orientation of each individual PAPI light, so you want to set that at 24 degrees. The light colors can be set in the shader inspector.

    EDIT:
    Actually, it looks like it will need a different shader for that behavior because the current PAPI shader only supports 2 angles, up or down, not up, middle, down. Let me have a look and see if I can make it work.
     
    Last edited: Jan 14, 2022
  43. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    I had a look at it and it actually requires quite a bit of code change due to the maths involved. How many lights like this do you need? If it is only a couple it will be easier to do in C# instead of the shader and won't make much difference in performance.
     
  44. inkostyakov

    inkostyakov

    Joined:
    Nov 14, 2016
    Posts:
    48
    Not to many. About 10-20.
     
  45. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    In that case it is probably easier to code the logic in C#.
     
  46. inkostyakov

    inkostyakov

    Joined:
    Nov 14, 2016
    Posts:
    48
    You mean, I need to check angle between camera and light in Update, and change light color depending on angle size?
     
  47. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Yes, exactly.
     
  48. JacksparrowPhillip

    JacksparrowPhillip

    Joined:
    May 22, 2019
    Posts:
    14
    hi mate, im wondering how to achieve the effects that the lights can move along the given paths/roads with spriteLights, like the ones in GTAV ,but not costing too much CPU performance or just using GPU. some hints would be awesome
     
    Last edited: Jan 22, 2022
  49. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    I thought about that too. Unfortunately, this is not that easy to do with SpriteLights. Every light in SpriteLights is a vertex on a static mesh. This is what makes it so incredibly fast. But if you want to move individual lights around, it means you have to animate the entire mesh, which tends to be less performant. Using a skinned mesh comes to mind, or just having individual straight strips of lights move in a straight line.

    Either way, it is only going to look good from a very large distance.
     
  50. jensklein1

    jensklein1

    Joined:
    Jan 11, 2022
    Posts:
    12
    Hi there - I just bought your sprite light asset - it looks great! I use it for a flight simulator and have two questions: How do I position the runaway lights, as they are created at runtime and its hard to place them in position - or maybe I miss something? Also, I noticed that after take-off the city lights become very fuzzy and loose all the structure of being city lights - I end up getting flickering random dots. It's not culling, but looses all details the further away I get with the camera. Would you have ideas how to go about this?
     
    Last edited: Feb 17, 2022