Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Rain/Snow Shader Tutorial

Discussion in 'Shaders' started by tiredamage42, Jul 24, 2020.

  1. tiredamage42

    tiredamage42

    Joined:
    Oct 26, 2016
    Posts:
    19
    Hi Everyone!
    I wrote a tutorial on medium detailing how to use geometry shaders to render large amounts of performance friendly rain / snow, complete with wind and random movement. It's a bit long, but it's also meant so that Unity beginners can follow along.

    Lemme know what you think! (or if you have any requests for tutorials on other subjects)



    Enjoy:
    https://medium.com/@andresgomezjr89/rain-snow-with-geometry-shaders-in-unity-83a757b767c1

    Source Code:
    https://github.com/tiredamage42/RainSnowGeometryShader
     
    lilacsky824 and pm007 like this.
  2. douaakh

    douaakh

    Joined:
    Feb 26, 2020
    Posts:
    2
    Hello, I am actually following your tutorial and I find it helpful, so thank you. Can you please explain why do we need two quads for the rain? Does 'maxvertexcount' of 8 mean that the 'geom' function is called twice for each vertex since each time we are only appending 4 vertices (one quad) into the stream? Thanks.
     
  3. tiredamage42

    tiredamage42

    Joined:
    Oct 26, 2016
    Posts:
    19
    there are 2 quads used for the rain since that effect isn't billboarded (i couldnt figure out how to billboard it and have it look correct with the wind rotation as well). so to approximate billboarding we just "fill it out" with that extra perpendicular quad, that way if one quad is looked at from too steep an angle, the other one can be seen.

    as for the geom function, it's only called once per vertex regardless of wether it's rain or snow, the max verts is specifying how many vertices are pushed into the stream.
     
  4. douaakh

    douaakh

    Joined:
    Feb 26, 2020
    Posts:
    2
    Great work!

    I had to multiply 'unity_CameraToWorld' with float3(0,0,-1) (instead of float3(0,0,1)) to get the camera forward vector though, because the camera couldn't "see" the rain/snow.
    From Unity docs:,
    "Note that camera space matches OpenGL convention: camera's forward is the negative Z axis. This is different from Unity's convention, where forward is the positive Z axis."

    I don't know if it is related to my problem, but it didn't work out for me otherwise.
    Thanks again.
     
    tiredamage42 likes this.
  5. Pourya-MDP

    Pourya-MDP

    Joined:
    May 18, 2017
    Posts:
    145
    hey , many thanks for this great effect , one simple question btw , is it even possible to add light reaction to those particles?
    something like this in 56:59
     
  6. Deleted User

    Deleted User

    Guest

    Great! Thank you!