Search Unity

Question 2D lights and particle systems.

Discussion in '2D' started by Chris-Trueman, Nov 20, 2022.

  1. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    I'm trying to get a particle system to respond to 2D lights.

    I have a top down game with a particle cloud overlay. I am using 2D lights for night and day.

    I need transparency for the clouds to fade in and out. Using the URP default unlit particle shader I get that. Once it goes to night time the areas the clouds are over become lighter. I want the opposite, or at least the clouds to become darker.

    If I use a lit particle shader I loose my fading, and the light does nothing to the clouds.

    I can do this by changing the start color of the cloud particles, and I would have to loop through all the other clouds to darken the ones that are already active. I would need to do this for every particle system I want affected by the light. This is not scalable in any performant way and I know I will want other particles to be affected by light.

    I'm thinking it has to do with the renderer and I might need to create a second camera using a different renderer or maybe a render feature.

    Is there any way to get the particles to be affected by a 2D light?
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    I've added the tag "particles" because the 2D team don't work on the particle system. With a bit of luck a particle dev will see it and respond to you.
     
    Chris-Trueman likes this.
  3. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    You need a 2d-lit material. Here's how particle Shader Graph was done in the Lost Crypt demo, using a ShaderGraph starting from the Sprite Lit template.
    The HDR Tint Intensity could be left out. Or you could rename it "Day Night" so you'd have a variable you could change fro script to help with coloring the clouds at different times of day. The VertexColor node might be optional too... I think Sprite Lit shader graphs receive VertexColor automatically.
     
  4. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    Thanks Lo-renzo. I will give it a try.
     
  5. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    @Lo-renzo unfortunately this makes my particles black. Very strange, I need it to have color. It should darken when there is less light, but not black the whole time.

    Edit: The material icon shows color for the particle texture, so it shouldn't turn black.
     
  6. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    Do you have a Global Light? Have you set the HDR Intensity (or replacement) to non-zero? I've used this exact thing just fine.
     
  7. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    Yes I have a global light. I have set the HDR intensity to white, still comes out black. It doesn't make any sense at this point the material shows it's working but the particle system will not add color.
     
  8. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    If I make the graph Sprite Custom Lit, I get color back but it isn't affected by the global light and it doesn't fade.
     
  9. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    Well I feel stupid now. It would help if the light was targeting the cloud layer. No light and it goes black, which now makes total sense. Also the HDR intensity is not needed at all, I took it out of the graph.

    Fixed2DLitParticleGraph.png
    Thank you for the graph Lo-renzo.