Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Why particle lights over my Sprite with shader "Sprite/Diffuse"

Discussion in '2D' started by IgorUnity3D, Jul 1, 2017.

  1. IgorUnity3D

    IgorUnity3D

    Joined:
    Aug 28, 2014
    Posts:
    66
    I am facing a problem when my character is close to a particle system with dynamic lights. The lights go beyond the sprite set with the shader (Sprite / Diffuse):






    I have tried to adjust the z-axis of the objects, but if I put the character away from the light the image does not receive light effects. (POINT LIGHT)

    Here's a video to better illustrate the scenario:



    I'm new to the particles and lights, what am I doing wrong?

    Thanks in advanced!
     
  2. Egil

    Egil

    Joined:
    Jul 29, 2012
    Posts:
    215
    Maybe you would have better control over the light if you didn't use the particles to control intensity and position.
    If you can make it work with a single light instead, make a simple range and intensity script that controls the fire flaring.
    This will probably be better for performance as well, as particles can make multiple lights per system.
     
  3. IgorUnity3D

    IgorUnity3D

    Joined:
    Aug 28, 2014
    Posts:
    66
    Hi @Egil

    Thanks for the answer.


    "particles can make multiple lights per system." Does the particle system create a light for each particle?
     
  4. Egil

    Egil

    Joined:
    Jul 29, 2012
    Posts:
    215
    It can, you can limit the amount of lights used in the "Maximum Lights". Might be hard to notice, since in the quality setting the pixel light count is set low by default.

    Testing it with many particle lights and a high pixel light count, batches(draw calls) increases.
     
  5. Egil

    Egil

    Joined:
    Jul 29, 2012
    Posts:
    215
    Made a little script for fun, maybe it could be a useful starting point for you.

    Code (CSharp):
    1. using UnityEngine;
    2. public class LightController : MonoBehaviour {
    3.     public AnimationCurve lightIntensity;
    4.     public float lightIntensityMultiplier = 1;
    5.     public float lightIntensitySpeed = 1;
    6.     public AnimationCurve lightRange;
    7.     public float lightRangeMultiplier = 1;
    8.     public float lightRangeSpeed = 1;
    9.     public Gradient lightColor;
    10.     public float lightColorSpeed = 1;
    11.     Light aLight;
    12.  
    13.     void Start () {
    14.         aLight = GetComponent<Light>();
    15.         lightIntensity.postWrapMode = WrapMode.Loop;
    16.         lightRange.postWrapMode = WrapMode.Loop;
    17.     }
    18.  
    19.     void Update () {
    20.         AnimateLight();
    21.     }
    22.  
    23.     void AnimateLight() {
    24.         aLight.intensity = lightIntensity.Evaluate(Time.time * lightIntensitySpeed) * lightIntensityMultiplier;
    25.         aLight.range = lightRange.Evaluate(Time.time * lightRangeSpeed) * lightRangeMultiplier;
    26.         aLight.color = lightColor.Evaluate((Time.time * lightColorSpeed)%1);
    27.     }
    28. }
     
    IgorUnity3D likes this.
  6. IgorUnity3D

    IgorUnity3D

    Joined:
    Aug 28, 2014
    Posts:
    66

    This is great! I'll try to implement this!