Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Clouds and rain

Discussion in 'Editor & General Support' started by agentcooper, Apr 5, 2008.

  1. agentcooper

    agentcooper

    Joined:
    Jan 19, 2008
    Posts:
    98
    Hi, I have looked all through these forums and can find a few discussions on rain etc but must admit I am a little unfamiliar with particles etc.

    What is the best way to create rain in Unity? and also moving clouds? Is it wise to use particles for clouds or are textures the way to go?

    Sorry if these are dumb questions but its only easy if you know how :D

    Thanks
     
  2. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,042
    Particles would be the way to go for rain. You could attach a particle system to the camera to keep the particle count down.

    For clouds theres an excellent project right here: http://forum.unity3d.com/viewtopic.php?t=8881
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,236
    This thingie I did a while ago has rain and moving clouds. The rain is a particle system that follows the player around; it's pretty simple. It's worth playing around with particles for a while to get an idea how they work; the docs describe (almost) all the various parameters. An overcast sky is usually pretty flat-looking anyway, so a texture is OK, and a lot faster than the huge number of particles you'd need to simulate lots of clouds would be. I have it move here just by scrolling the X component of the texture offset:

    Code (csharp):
    1. var scrollspeed : float = .02;
    2. private var offset : Vector2;
    3.  
    4. function Update () {
    5.     offset.x += scrollspeed * Time.deltaTime;
    6.     renderer.material.SetTextureOffset ("_MainTex", offset);
    7. }
    --Eric
     
  4. agentcooper

    agentcooper

    Joined:
    Jan 19, 2008
    Posts:
    98
    Yeah I had thought of the particle system it was just the way of doing it that was bugging me. I have played with the cloud system from Alpha-Loup already but couldn't get on with it, but funnily enough have just figured it out!

    Do you know of any decent rain type textures? I will try playing with attaching it to the camera - not something I had thought of before but it makes sense! Thats what a coursework deadline does to you I guess - you forget the simple things!
     
  5. agentcooper

    agentcooper

    Joined:
    Jan 19, 2008
    Posts:
    98
    Also Eric - I have seen your Storm City Demo a few times (Very Nice), but how have you achieved the reflections, you mention flipping objects? What do you mean by this? I kinda understand what it means but how to go about doing it confuses me! :oops:

    I have read in on the unify Wiki and various other posts about creating cameras and rendering their output to a texture, is this a sensible path to follow or can it be expensive in memory terms?
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,236
    In Blender, I duplicated the models and changed the Y scale for the duplicate so it was negative, and applied the change. This makes a duplicate that's mirrored on the Y axis. So then this shows through the transparent puddles to give the illusion of a reflection.

    It would use a little more VRAM depending on the resolution of the render texture, but on the other hand you wouldn't need duplicate models. Also requires less effort obviously. After I got Pro, I used the mirror reflection script on the wiki to update that project so it uses "real" reflections, which is largely the same thing as the script for reflective water, and got rid of the duplicate mesh stuff. (I didn't bother uploading this; it was just for the heck of it and mostly looks the same.)

    Although one thing about the duplicate model technique is that the "reflections" are the same resolution as everything else. With a render texture, it's, well, a texture, so there's some discrepancy, unless you use an excessively high res texture. Pretty trivial though. ;)

    --Eric
     
  7. agentcooper

    agentcooper

    Joined:
    Jan 19, 2008
    Posts:
    98
    Ok, i have played with parenting the particle system to the character and camera, but I get the effect of the particles trailing behind when the character moves - i can live with it if worst comes to worst but I would ideally like to have an effect similar to storm city... was this created using an animated texture or something?

    Also, thanks eric for the tips on reflections, as this is web based I may go with rendering to a low res texture, as its going to be used as a puddle anyway the resolution isn't really an issue.
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,236
    Nope, I just have the particles being emitted over a large enough area that the "trailing behind camera" thing isn't an issue. The rain emitter is a filled circle that I made in Blender with a diameter of about 400 meters, with "interpolate triangles" on for the particle emitter. It would still be an issue, though, if the movement speed was fast enough. In that case I'd turn off "simulate in world space" for the particles. The rain wouldn't be quite correct anymore since all the drops would move with the player instead of just the particle emitter, but I suspect most games actually do that.

    --Eric
     
  9. Alec

    Alec

    Joined:
    Mar 11, 2008
    Posts:
    1,331
    Oooo thanks for that link angryant
     
  10. bluindigo

    bluindigo

    Joined:
    Jun 5, 2008
    Posts:
    14
    I'm very new to unity. I guess I've crossed over from Torque. Anyway I don't really like messing around with scripts. So I have attempted to create rain from particles with splashes, bouncing off everything.

    Its important to remember that water will need a box collider with "is trigger On."

    I think its Ok, but then again I'm new.

    its a tight coverage so group to camera.
     

    Attached Files:

  11. bluindigo

    bluindigo

    Joined:
    Jun 5, 2008
    Posts:
    14
    I thought I'd post a quick demo, took 2 minutes to create.
    I'd like to add some mist effects and some lightning flashes as in Storm City.
    Anyone?

    Enjoy.
     

    Attached Files:

  12. bluindigo

    bluindigo

    Joined:
    Jun 5, 2008
    Posts:
    14
    Added mist and some sound. No Lightning flashes though or moving clouds. Can I animate a skyboxcubed texture?
    I know I can do it with Geom using Offsettexture. I suppose using Geom, I can then flash a Light on it as in Stormcity.

    Anyway I'm done. Basically its the same stuff I used in my unitypackage. Just changed the settings and instantiated some of the prefabs. Don't increase the splashes though as this kills the FPS. Keep them low and tight to the camera. Increase the downward rain in a prefab and remove OnColission for density.

    Best

    Blu
     

    Attached Files:

  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,236
    Technically yes, but it's kind of hard. There are 6 textures in a skybox, so animating the texture offset doesn't get you anything useful. Fading from one skybox to another is the easiest kind of animation you can do.

    Yes, that's what I did.

    --Eric
     
  14. bluindigo

    bluindigo

    Joined:
    Jun 5, 2008
    Posts:
    14
    Doesn't Skybox Cubed have only the one texture though? Though I don't see how to add a script to it.

    Also Eric how did you write the script for your flashes? I'm trying to incorporate Random.value into a Light.intensity script with no luck.

    I'd hoped to get a quick flash of light at random intensity at random intervals with a fixed minimum . Its a bit beyond me.

    Blu
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,236
    No, all skyboxes are 6 textures. You can turn a single texture into a skybox, but Unity still converts it to 6 textures.

    I didn't actually use a random value for the intensity, but I did have a random number of flickers:

    Code (csharp):
    1.     var flickers = Random.Range(1, 8);
    2.     var fadeSpeed : float = 15.0;
    3.    
    4.     for (i = flickers; i >= 1; i--) {
    5.         if (i == 1) {fadeSpeed /= 15.0;}
    6.         for (j = 0.5; j < 1.5; j += Time.deltaTime*fadeSpeed) {
    7.             if (i != 1) {var lightColor = Mathf.PingPong(j, .5)+.5;}
    8.             else {lightColor = 1.5-j;}
    9.             light.intensity = lightningLight.intensity = lightColor;
    10.             yield;
    11.         }
    12.     }
    For the first flickers, it animates from 1.0 down to 0.5 and back up to 1.0 using Mathf.PingPong, and then for the last flicker it goes from 1.0 down to 0.0.

    I used a point light, plus a spotlight with a cookie pointed upward at the clouds for the localized cloud lighting effect (that's what lightningLight is).

    --Eric
     
  16. bluindigo

    bluindigo

    Joined:
    Jun 5, 2008
    Posts:
    14
    Eric

    Thanks for that.

    Yeah, I did exactly that with my SkyboxCube, but by converting a single image to generatedCubeMap, I'd hoped it would have been still linked in someway to the source image. Which would have been cool. Guess not.

    Cheers
     
  17. bluindigo

    bluindigo

    Joined:
    Jun 5, 2008
    Posts:
    14
    Sorry to be a pain in the sack. The flicker is great, but plays only once. Ermm..... how do I get it to repeat every says 10 seconds+random interger?

    Cheers
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,236
    Something like:

    Code (csharp):
    1. function Start () {
    2.    while (true) {
    3.       yield WaitForSeconds(10+Random.Range(0.0, 10.0));
    4.       // Previous code here  
    5.    }
    6. }
    7.  
    --Eric
     
  19. bluindigo

    bluindigo

    Joined:
    Jun 5, 2008
    Posts:
    14
    Thanks for that.

    Unfortunately it doesn't work at all, but it is fun to play around with. Especially when learning. :D

    Cheers
     
  20. bluindigo

    bluindigo

    Joined:
    Jun 5, 2008
    Posts:
    14
    Sorry, I'm just being an ass. That works great. I just needed to make sure I started with the intensity of the light at . Off in other words. D'OH.

    I love/hate this scripting malarky. Just when you thing you're out it pulls you back in.

    Godfather of Idiocy.

    Cheers
     
  21. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    713
    Really great rain effect bluindigo!
     
  22. insomnia3d

    insomnia3d

    Joined:
    Mar 19, 2009
    Posts:
    2
    thanks for sample :wink: but scane file?
     
  23. Zante

    Zante

    Joined:
    Mar 29, 2008
    Posts:
    377
    This is very promising, but it runs very slowly. :[
     
  24. livemixlove

    livemixlove

    Joined:
    Sep 16, 2009
    Posts:
    17
    The example also runs Very slow for me. I think it could easily be optimized.

    Example:

    - Reduce the number of particles on the splash. I think you could make something with just 2-4 quads that would look more realistic.
    - Have more one drop of rain in the texture for each rain particle. So each particle would have 2-3 widely spaced streaks. Though I guess this complicates the collision detection.

    OR

    (not sure how to do this exactly in Unity but I think it would be possible)
    Draw the rain particles as GL lines. This would run MUCH faster and honestly there would be little to no loss of realism IMHO.
     
  25. Danko86

    Danko86

    Joined:
    Jan 31, 2011
    Posts:
    4
    how to collide rain particle with water surface. i cant get it. it is colliding with terrain, but pass thrue water :(
     
    Last edited: Feb 2, 2011
  26. ScienceFiction

    ScienceFiction

    Joined:
    May 28, 2008
    Posts:
    392
  27. blackhol3_sun

    blackhol3_sun

    Joined:
    Oct 8, 2012
    Posts:
    2
    Hi,

    I attached this rain effect prefab to the camera which follows my player/car. The problem is if the camera moves it is obvious that these rain particles are moving alongwith it. Is it possible that once those particles leave the system's base or something, they go into the world space and not follow its own start position?

    Also if someone could explain why is Auto destruct off in this because whenever I create any effects particle system, I turn it on. How do those particles get deleted/destroyed if auto-destruct is set to off? :-o
     
  28. HardKore Gaming

    HardKore Gaming

    Joined:
    Mar 18, 2013
    Posts:
    1
    where do i apply this script
     
  29. Voltran

    Voltran

    Joined:
    Aug 23, 2014
    Posts:
    2
    Guys really, these explanations did not helped to me. can you just say where i'm making mistake ? I mean i use a water fall which is built in in unity. And i place it on the top of my building. I use stretch ext but it does not look like rain ? Can somebody please share a very easy how to for a rainy weather ?
     

    Attached Files:

unityunity