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. Dismiss Notice

Particles are emissive in darkness

Discussion in 'General Graphics' started by Inferi, Aug 27, 2016.

  1. Inferi

    Inferi

    Joined:
    Sep 28, 2015
    Posts:
    145
    Hi all. I am currently having a sandstorm in my game using 2 of the standard asset Particlesystem prefabs "DustStorm". It looks great at "daytime" but when I rotate the light to night, the dust is emissive or sort of lit up.

    I have searched the web and nothing seem to work. I have changed Shaders and fiddle with all the different sliders and numbers, no luck.

    I have added a plane and a box under the terrain to add shadows that someone said but no luck.

    Is there anyone here that know how to fix this? Do I have to make the Dust Storm in another way?

    I have just started with Unity so NOOB warning here :)
     
  2. Inferi

    Inferi

    Joined:
    Sep 28, 2015
    Posts:
    145
    I ended up with a colorchange on the startcolor of the "DustStorm" Particle system. It works and I will keep it untill I find another way.
     
  3. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,620
    Possibly it is using an unlit shader, which means it won't respect your lighting. You'd have to use a lit shader for that. (It takes extra processing for a shader to interpret where light is and isn't.)
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,209
    It's not just possibly using an unlit shader, unlit particle shaders are all Unity ships with. And for dynamic shadow receiving on transparent objects it's actually impossible without making changes to the rendering systems.

    The short version is along the lines of what hopeful mentioned, you need custom particle shaders that into account lighting, but these are going to make your particles significantly more expensive to render so be prepared for that. That said it's not too hard to have particles that at least respect ambient and directional lighting, if not shadows.

    With Unity 5.4 you can use light probe volumes for scenes with baked lighting to get something pretty close to something that looks like it's respecting shadows, but that doesn't help you for dynamic lighting.

    Unity has shown off shadows and lighting working on particles, like in the Adam short, but that's using custom shadows that haven't been released publicly.

    So your options are write some shaders yourself, I posted a basic normal mapped particle shader someplace on the forum that's a good starting point for that.

    Or you can get this asset which offers more control over how particles are lit, but still doesn't support shadow recieving:
    https://www.assetstore.unity3d.com/en/#!/content/60561

    Or you can get this asset which doesn't have quite as much control for particle lighting, but does support shadow casting on particles (via custom shadow map rendering):
    https://www.assetstore.unity3d.com/en/#!/content/67665
     
  5. Inferi

    Inferi

    Joined:
    Sep 28, 2015
    Posts:
    145

    I will try to build my own shaders at a later point I think.
    Right now I am a total noob with Unity and somewhat new to C#, so I will stick to easy fixes so I dont get bored and quit :)

    I dont think I need the dust to cast shadow or recive shadow, only change the color according to the time of day in a realistic fashion. The volume of the "sand" is still the same and should be.
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,209
    The "easy" C# only solution is just change the color of the particle system dynamically.

    https://docs.unity3d.com/ScriptReference/ParticleSystem-startColor.html

    Make a script that changes that color based on the time of day. You could use a Gradient in your script and use something like:

    myParticleSystem.startColor = dustTimeOfDayColorGradient.Evaluate(timeOfDayPercentage);
     
    richardkettlewell and Inferi like this.
  7. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,620
    Inferi likes this.
  8. Inferi

    Inferi

    Joined:
    Sep 28, 2015
    Posts:
    145
    Yes, I have made a small array with the colors that I want the dust to be and then checks the suns location on the sky with "transform.eulerAngles". I then use:
    GameObject.Find("DustStorm").GetComponent<ParticleSystem>().startColor = GradienDustColors[#];
    # is the color that I want when the sun is on current degree on the sky.
     
  9. Inferi

    Inferi

    Joined:
    Sep 28, 2015
    Posts:
    145
    Those looks to be what I am looking for. I will look into that. Thanks
     
  10. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,459
    Sorry to resurrect this old(ish) thread, I would like to ask if you could give some sample code how to get the sky colour and assign to a particle start color, I'm just going through a similar issue and have no idea how to fix/approach this. Thanks for any help you could give.
     
  11. ifurkend

    ifurkend

    Joined:
    Sep 4, 2012
    Posts:
    350
    https://forum.unity3d.com/threads/_worldspacelightpos0-how-it-works.435673/
     
  12. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,459
  13. ifurkend

    ifurkend

    Joined:
    Sep 4, 2012
    Posts:
    350
    You create a skybox with your desired gradient or just set the color to the ambient light. The shader in #12 reply receives ambient light and directional light.