This Tutorial is we’re going to be creating a fog effect in VR as well. How the same effect can be used in VR will be explained as well. To get started we first need to set-up our environment for VR – Gear VR in this case. You can follow these tutorials on how to do that if you’re not familiar. Now that we’re all set up let’s get started.
Fog Effect in Unity
Basically we can use two types of Rendering methods for creation of our Fog Effect.
- Unity Global Fog : The Global Fog is an image effect which creates camera-based exponential fog. All calculations are done in world space which makes it possible to have height-based fog modes that can be used for sophisticated effects. But this rendering mode requires graphic resources which we don’t have a lot of if using Mobile or Mobile VR Specifically.
- Particle System : Particles are small, simple images or meshes that are displayed and moved in great numbers by a particle system. Each particle represents a small portion of a fluid or amorphous entity and the effect of all the particles together creates the impression of the complete entity. Using a smoke cloud as an example, each particle would have a small smoke texture resembling a tiny cloud in its own right. When many of these mini-clouds are arranged together in an area of the scene, the overall effect is of a larger, volume-filling cloud. Particle System is much more efficient because we use a single texture and a material to draw our Fog in this Case. More over Particle System is dynamic with a plethora of parameters to play around with. It also has a Scripting API.
Now we can get our scene ready.
- We’re going to use a demo scene containing Low poly Rocks and a surface as our base. You can find the free Asset here.
- We remove the main camera and add our Oculus related Prefabs and Cameras for Interaction in VR. Tutorials Here.
- Download Standard Assets here. Import the Particle System, Utilities and CrossPlatformInput Categories from the package. We will be using Textures and Materials from the Standard Assets Package as they are free to use and provide a base on which we can get our desired effect.
Creating the Fog Effect
- Create a Particle System in the Hierarchy window. Create > Particle System.
- In the Renderer component of the Particle System change the Material to “ParticleSmokeWhite” which should be at /Assets/Standard Assets/Particle Systems/Materials. .
- Change Cast Shadows and Receive Shadows to on.
- In the Shape Component change the Shape to “Cone”, Angle to “73” , Radius to “10” & Emit from to “Volume”.
- In the Emission Component change Rate over Time to “6.3”.
- And in the main window properties :
- Duration : 1000
- Looping : true
- Prewarm : true
- Start Lifetime : 32
- Start Speed : 0.26
- Start Size : 5
- Start Rotation : -0.28
- Simulation Space : local
- Max Particles : 1000.
- That’s it! the Fog Particle System is Ready. You can create multiple instances for a broader use. Hit Play and you can see the Effect in the Editor Window. You can also build it to the Gear VR device to see it in action in VR! You can customize the particle system to your will to suit your needs and requirements.
Fog effect in VR with Unity
The final result of our fog effect in vr after building to Gear VR and Deploying. Frame rate is stable and no dropped frames. The Fog can be localised or set universally just by adjusting the position and scale of the particle system.