Volumetric Clouds


Asset store link

// Description
This is a fullscreen shader which uses raymarching through a texture to render clouds on screen.

// Contains
-A bunch of shaders and duplicates of Unity’s cginc for compatibility’s sake
-A c# script to attach to a camera
-Two materials, acting as presets for low and high quality
-A manual
-Four texture variant
-A bunch of editor scripts for the material inspector

// Requires
-GPU supporting Shader Model 3.0 (most GPU made after 2005)
-Unity 4.0+ (Older versions won’t compile).

// Limitations
-Performances: this can be a fairly heavy shader, performance hit is comparable to an ambient occlusion postFX but there are a ton of controls provided to reduce it.

Here’s the online Guide.

// Media
1815171--353452--ezgif.com-optimize.gif



Change log

// Version 3.5
Shape

  • Cloud Flatness, controls the curve of the cloud to puff them out.
  • Old ‘alpha’ from 2.x is back as Local Scale, scales cloud vertically within their boundary.

Shading

  • Direct and Indirect lighting computation can now be entirely disabled to help performances.
  • Base color is now effectively an albedo and Shading color now caps the minimum color.
  • Changed normal intensity to shading intensity.
  • Slightly changed how normals are calculated to retain more details.
  • Scaled direct lighting and point light contribution by density to more accurately represent real lighting model.
  • New silver lining feature and controls.
  • Sky Occlusion Normalized to manipulate the size of the occlusion gradient.
  • Occlusion Tint which, has its name implies, tint the occlusion.

UI

  • Tons of property names have been changed to more accurately represent what they do.
  • Minor UI presentation changes.

Raymarcher

  • Changed how each samples are blended together, it now uses a proper front to back blending.
  • Changed Step Size to min step size.
  • New ‘Step Parallel Mult’ control, this scales the length of each steps when the camera ‘looks’ towards the horizon, helps with rendering distant clouds.

Breaking changes can be opted out of by clicking on the ‘New Shading’ toggle.

// Version 3.0

  • Rewrote the raymarcher entirely resulting in lower amount of steps required to render in the same or at a higher quality.

  • “Step Skip” and “Step near surface” have been replaced by a single different “Step Skip” property which adapts far better to cloud volumes.

  • Most of the lighting as been re-written as well and as such properties related to those have all changed how they influence rendering, affects the following properties: base color, shading color, normal map, normalized and normals intensity.

  • “Depth intensity” has been changed to “Sky Light Attenuation” and expanded into a color property.

  • Indirect lighting is now independent of the normal-map switch since it is no longer influenced by it.

  • New property : “Post Blend”, Controls how Distance Blend is computed, refer to the manual for more information.

  • New property for Screen Space Shadows : “Blend out of shadowmap”, toggle to filter screen space shadows out of the shadowmap.

  • New property for Screen Space Shadows: “Volumetric”, toggling it on makes shadows behave like previous versions, off will just use a projection instead which is far cheaper and slightly worse looking.

  • Renamed Density to coverage, it more accurately represent what the property controls.

  • Renamed alpha to density, same as above.

// Version 2.4b
Fix :

  • Screen-space shadows

// Version 2.4
Additions/Modifications :

  • Implemented spherical coordinate mapping as a secondary sphere mapping technique.
  • Axis of alignment selector, you can now define which axis you want the cloud plane to align to.
  • Clouds self-shadowing.
  • Basic scene-view controls.

Fix :

  • Normals are now more accurate at high density as well as under grazing light.
  • A lot of minor shader and editor code refactoring.
  • Shadows casting onto the far plane.

// Version 2.3
Added/Modified :

  • Lighting computations are at least twice as fast now at the cost of an almost un-noticeable visual degradation.
  • Slight improvement of some raymarching functions leading to a very small overall performance improvement.
  • Variable to control clouds’s bases flatness.

Fixed :

  • “Holes” in Single Pass VR.
  • Compatibility with Unity 5.6.

Removed :

  • Skip pixels controls ; was degrading most GPUs performance instead of helping because of how GPUs are architectured.

// Version 2.2a
Fix :

  • MainLight error, support for Unity 5.5 standard shader.

// Version 2.2
Added/Modified :

  • Support for spherical mapping, perfect for atmosphere and planet rendering.

  • Support for point lights for unity 5.4 and above.

  • Supports unity 5.0 and above properly.

  • Rendering shadows only is now possible.

  • Rewrote access to Unity’s GI, should need no to minimal support for upcoming unity releases.

  • Created a new script called “CloudsEvent”, fires user defined events when entering and exiting clouds.

  • Changed material display to Plane instead of sphere.

  • Added multiple fields to give more controls over clouds :

  • “Normals Intensity” under normal map.

  • Spherical mapping controls : position and stretch horizon.

  • Orthographic Perspective, fakes perspective when rendering in orthographic.

  • Render plane offset from camera’s clipping plane.

// Version 2.1
Fix :

  • Issues with draw distance being capped at one thousand.
  • Toggle drawer drawing incorrectly on first inspector draw.
  • Lighting issues caused by very high cloud density.

Added/Modified :

  • File replacement for Unity 5.4+
  • Texture based density.
  • Modified light attenuation inside clouds and exposed controls for it.
  • Further cleaned up the code.
  • Slightly reduced branching as well as operations on shadow sampling.

// Version 2.0b
Fix :

  • Mac and OpenGL platforms compilation.

  • <5.0 Shader Model compatibility.

// Version 2.0
Fix :

  • Texcoord not written by vertex shader.
  • Random compile errors related to GI.

Features dropped :

  • Object space Mapping
    With the new rendering system, object space is actually local to your camera which is not very useful, you still have access to x/z position offset under Cloud Transform z/w values

  • Normals Direction inverting
    It caused confusion and was never used anyway.

  • Shader Forge Nodes
    Instead of giving you the nodes I’ll actually write a tutorial on raymarching with shaderforge on the wiki in a couple of days, this means that you’ll have access to it without the need to buy my asset.

  • Curved rendering
    Most of the optimizations I took to render the clouds at a decent framerate don’t work as well if I render it curved, performance hit is more than 4 times the planar one.
    I still have a second way to curve them to try out but that’s for another update since I don’t really have much time left.

New Features :

  • Slice based volume rendering dropped in favor of raymarching, this change comes with :

  • Better performances

  • Higher overall quality

  • Ability to render clouds from any angle

  • A whole bunch of variables to get an higher control over performances and quality

  • Ability to skip heavy calculations of 1/2 or 1/4 of the screen in a grid to help performances

  • Screenspace shadows

Post below from page 1 through half of page 5 don’t reflect the current state of this asset. Version 1.x had a geometry based rendering whereas 2.x uses ray marching, a ton of design issues encountered by the first are resolved by the later.

5 Likes

looks interesting, can we get web demo??

The slight blur is emulating motion blur as clouds move ? Can it be disabled ?

Also do the clouds receive lighting from the sun as it rotates ?

Thanks

The system looks very cool

Oh that’s a good point, i post my question too soon without even let the gif finished loading.
+1 for disabling the motion blur…

I suppose having it as option would be cool, but i agree it should be possible to disable for sure.

@nasos_333 and @Reanimate_L
The clouds aren’t actual 3D geometry, it’s a bunch of quads stacked on top of each other with a space between them depending on the volume size and the number of slices.
The “motion blur” is actually the space between two slices, the more slice you give the shader, the less this effect will be visible.

@nasos_333 Yes the clouds are lit using a normal map, the light color and intensity affects the clouds as well.

Great, thanks.

What will be the price of the asset ?

@nasos_333 I am not quite sure yet, what price would you give for this asset ?

That depends on a lot of factors and the performance/looks of a playable demo, preferably showing the lighting as well, so is rather early to tell.

This package is now officially released and the main post has been updated.

Purchased it and I am working with it now! Looks like EXACTLY what I needed!

@garyhaus Thanks a lot for the kind words ! If you have any issues dont hesitate to report them in this thread, i’ll do what i can to assist you.

is this package on the unity store

@paulojsam My bad, I forgot to had that to the 1st message, thanks.

Ok so first test with system in place. This is a ‘test arena’ I have for my project. Not much is optimized and there are a few random weird props in the scene. That being said… for my skies this ROCKS!!! This is coupled with Skyshop and Time Of Day for atmosphere.
Image followed by a build(OS X and Windows versions). Standard FPS controls.

CAN’T SAY THIS ENOUGH! THANK YOU!

OS X build!
Win64 build!

Gary

What’s in the package? Download size is really 470.5 MB?

Edit - And I should say they look great. If you found a way to do cloud shadows that would be amazing.

@MIK3K Yup, that’s the real size. The reason behind that is because there are four 4096^2 RGB+A channels raw PNG texture, it was that or giving you compressed texture.
I added the source of those textures has well, two heightmaps which are in the Alpha channel of those four textures and two normals which are in the RGB channels, just to give you an idea of how you are supposed to make a custom texture for this shader.
Of course, you could just compress them yourself after you download them or delete what you dont want, the “Sources” folder will be useless if you dont need any custom texture.

I might try to use a projector to cast those shadows, it still won’t be able to receive shadows though.

@garyhaus Wow, your scene looks really nice, I love the setting and lighting, well done !

This looks great, i suppose i have a couple of questions if you don’t mind too much

Firstly, i own several cloud assets but they’re mainly intended for powerful gpus and directx11, i’m looking for something that’s much lighter for webgl, so do you have any information on how they behave under ogles 2.0?

Secondly, is the shader uncompiled source available? I’d love to have a tinker with it especially as i’d like to have the clouds move and be lit in other ways, most particularly being able to rotate rather that move in a single direction (eye of the storm) or maybe this is scriptable along with using cloud textures i create myself? Would it be possible to add textures to tint or modify density at particular locations?

Great looking thing anyways! I’ll prob grab it quite soon

You have to forgive my noobishness - I saw the 4096 textures at 130 mb each. About the shadows - just meant like you said about the projecters letting the clouds cast a shadow on meshes or terrain. I can’t find anything that does that and I’m too dumb to figure it out myself. :face_with_spiral_eyes:

Anyway, thanks for the great clouds. They looked funny at first and then I realized my directional light was set to a yellowish color. Now they are big fluffy white clouds just like your vid.

@lazygunn The shader is in itself quite lightweight, i got a low end graphics card and i dont see any significant impact on the perfs with the shader alone, the impact comes from the number of slices you generate with the c# script included and the number of pixels of clouds you have on screen.
This asset could probably run on a phone if it supports SM3, has a low slice count and a somewhat decent texture size, didn’t test it though since i dont have any devices atm.
I didn’t compile the shader, nor the c# script so you can modify them has much as you want. There isn’t a lot of complex math involved, if you need any help figuring out what does what, send me a pm and i’ll assist you.

If you know a little bit about shader programming then you could probably do it yourself quite easily for the tint and density part but the eye of the strom part will be a little lot harder, this post should give you an idea of where you should start :
http://forum.unity3d.com/threads/shader-forge-a-visual-node-based-shader-editor.222049/page-49#post-1868263

Love your stuff by the way !