Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

[RELEASED] SpriteLights

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

  1. ghtx1138

    ghtx1138

    Joined:
    Dec 11, 2017
    Posts:
    113
    @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:
    51
    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,332
    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,332
    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,332
    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,079
    This was bug report explanation was helpful for me :
     
  11. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,332
    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,332
    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,332
    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.
     
  17. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,332
    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.