You copied the Doc URL to your clipboard.

Volumetric fog using particles

You can simulate volumetric fog with particles. This can provide high quality results.

Keep the number of particles to minimum. Particles increase overdraw because more shaders are executed per fragment. Try using larger particles instead of creating more particles.

In the Ice Cave demo, a maximum of 15 particles are used at a time.

Geometry instead of billboard rendering

Set the Render Mode of your particle system to Mesh instead of Billboard. This is because, to achieve the volumetric effect, the individual particles must have random rotations.

The following figure shows the particle geometry without textures:

Figure 6-57 Particles without texture

The following figure shows the particle geometry with textures:

Figure 6-58 Particles with texture

The following figure shows the texture that is applied to each particle:

Figure 6-59 Texture of an individual particle

Angle fade effect

Fade in and out the individual particles according to their orientation compared to the camera position. If you do not fade the particles in and out, the sharp edges of the particles are visible.

The following example code shows a vertex shader that performs the fading:

      half4 vertexInWorld = mul(_Object2World, input.vertex);
	 half3 normalInWorld = (mul(half4(input.normal, 0.0), _World2Object).xyz);
	 const half3 viewDirInWorld = normalize(vertexInWorld - _WorldSpaceCameraPos);
	 output.visibility = abs(dot(-normalInWorld, viewDirInWorld));
	 output.visibility *= output.visibility;  // instead of power of 2

The varying parameter output.visibility is interpolated across the particle polygon. Read this value in a fragment shader and apply an amount of transparency.

The following code shows how to do this:

      half4 diffuseTex = _Color * tex2D(_MainTex, half2(input.texCoord));
      diffuseTex *= input.visibility;
      return diffuseTex;

Rendering particles

To render for particles use the following procedure:

  1. Render particles as the last primitives within the frame.

    Tags { "Queue" = "Transparent+10" }

    The +10 is present in this example because the Ice Cave demo renders 9 other transparent objects before the particles.

  2. Set the appropriate blending mode.

    At the beginning of a shader pass add the following line:

    Blend SrcAlpha One

  3. Disable writing to z-buffer.

    Add the following line:

    ZWrite Off

Particle system settings

The following figure shows the settings used in the Ice Cave demo for the particle system:

Figure 6-60 Particle system parameters from the Ice Cave demo

The following figure shows the area where the particles are spawned. This is indicated by the box in the image. The box is defined by the built-in option Shape in the Unity Particle System:

Figure 6-61 The particles box definition where the particles are spawned

Was this page helpful? Yes No