Overview:
I was in need for some fog for a mountain scene and tried to fiddle with the fog settings of the Unity camera, but to no avail. The next best thing would be a bunch of spheres with a transparent fog texture around the camera, so that is how this Asset/Plugin combo came into being.It turns a CustomUnityAsset into a configurable cluster of fog spheres that can change their density, colour, amount, movement speed, etc.
Here is a birds-eye view of the resulting sphere "onion", and one with a checkerboard texture:
Usage:
- Create a CustomUnityAsset
- Add the FogSphere.assetbundle of the plugin and load and activate it. That should already show you a basic 3-layer fog sphere (50-100m radius)
- Add the plugin to get more configuration options:
Parameters:
- Density: Self-explanatory. -1 is off, 0 is neutral, +1 is total whiteout ;-)
- Vertical Density: Increases density in the vertical direction (initially a solution to a UV sphere cap texturing issue, now useful to have either more "horizontal" fog (0) or "everywhere" fog (1).
- Fog Speed: Rotates the spheres around the local Y axis in degrees per second.
- Fog Speed Variability: Rotates each sphere with a slightly varying speed to create a more 3-dimensional effect.
- Fog Colour: Really? I need to explain that?
- Fog Texture: Choose your own greyscale texture. Two are included in the plugin (Custom/Images/HAL9001/Plugins/FogSphere), Fog1.jpg is the default, Fog2.jpg is a more "horizontally smeared" version for less definition/smoke-iness.
- Inner/Outer Sphere Radius: Where does the first fog layer start, where does the last one end.
- Sphere Count: How may spheres to generate. Hardcoded limit at 100, but please, don't do that... It's 770 triangles (the standard Unity Sphere) per layer. I accidentally dialed the slider to 1000 once, my GTX3070 wasn't happy...
If you only select 1 sphere, it will have the inner radius.
Known Issues:
So far, weird stuff only happens if you load/unload the asset or do other unusual things. That asynchronous loading of things in VaM can be a pain to manage in a script. I've tried my worst to make the thing crash and am currently quite happy how it works.Due to the basic principle, the spheres can be obvious when rendered close by and intersecting with stuff. At some point, I will try to create a forest scene to find settings that work well in such a more close-up scenario.
Initially, I used UV spheres which always poses problems on the poles where all the polygons converge and the UV mapping is impossible. That issue is now solved by a custom shader that calculates UV coordinates on the fly and does some "fudging" on the poles by merging some other parts of the texture (you can see some of that in the example picture). So, in principle, you can create your own custom fog textures and as long as they are 2:1 aspect ratio, they should show up fine.