Вы находитесь на странице: 1из 116

F O G V O L U M E 3.

4
VOLUMETRIC FOG FOR UNITY 5
WHAT’S
FOG VOLUME?
Fog Volume is a volumetric fog solution
for Unity 5.

Flexibility is its strong point, you can


render clouds, nebulas, ground mist and
almost any kind of dense gas situation.
Downloads:
.avi
.mp4
.webm
FEATURED PROJECTS
SHOWROOM

If you would like to feature your project in the showroom, send me your request along with the requested info to contact@davidmiranda.me
FEATURED PROJECTS

PROJECT NAME PROJECT NAME


COMPANY NAME COMPANY NAME
www.web.com www.web.com

How are you using Fog Volume? How are you using Fog Volume?
Your company logo Your company logo

Screenshot description Screenshot description


FEATURES

● Light Halo
● Self Shadows
● In-scattering
● Point lights
● Volume shadows
● Projected soft shadows
● Cloud animation
● Light absorption
● Lambert Diffuse
● Distance fields

Click the images to watch the videos


DEMOS
All the scenes shown in this documentation and trailer video are
included in the product and are playable from this application

Windows build Mac build

Control map:

Action Keyboard Gamepad Mouse

Camera up E RT

Camera down Q LT

Look R Stick any mouse button


drag

Camera Speed RMB + wheel

Movement WASD L Stick

FOV Z, C RMB

Acceleration Shift (Speed x4) RT

FPS counter F
Menu and camera not working with wacom tablets. No bugs in editor though.
Press Escape to exit. Xbox Gamepad compatible.
SCENES
INFINITE CLOUD
In this case we have an example of generic cloudscape
that can be used as preset or starting point.

Camera is flying through the cloud automatically.


SCENES
INTERIOR
PRIMITIVES
This scene shows how we can use primitives to define
the noise boundaries.
We also see how GI and lights are used to light the fog
SCENES
SCOTLAND
This scene is using 2 volumes
● Clouds
○ Which casts shadows
● Ground clouds + fog
○ receives shadows
○ clouds defined with distance fields.

Light behaves in a very interesting way here. We can


see dramatic changes going from sunny to cloudy
without animating any parameter.
SCENES
LANDSCAPE
SHADOWS
The goal of this scene was to debug shadows. Clouds
are quite sharp and bright. Probably a good preset for
you.
The terrain is white to make the scene shadows more
visible.
SCENES
NEBULA
Built to demonstrate the usage of point lights.
SCENES
PILLARS
This was the first scene using the primitive modelling
feature. Inspired in “The Pillars of creation”.
SCENES
VENUS
ATMOSPHERE

This sample features light absorption and


long - distance shadows
SCENES
MOONLIGHT
Night scene featuring light source halo and light
absorption.
Cloud animation is especially interesting in this demo.
SCENES
NEBULA 3
SCENES
TOD TRANSITION

Animated sequence for dynamic sun rotation.


Commonly known as time-of-the-day transition.

This scene is a bit more costly than a normal situation


because of the cotton candy look. The cloud edges are
larger than it should, and this makes this cloud more
expensive . In production we would have shorter edges.

Sky background is Unity procedural sky. Clouds and fog


are generated with a single Fog Volume.
SCENES
MOCKUP
Cubed version of the scene ‘Scotland’.
I tried to make a glass box with a living scenery inside.
As soon as the camera gets inside of the box, what was
a mockup turns out into a big scale world.
SCENES
NEBULA 2
Variant of Nebula 3
SCENES
VR SHOWROOM
In this room, we will be able to see how people is using
Fog Volume and play with parameters in real-time.

Hoping to see your project in the VR Showroom!

Download content package

Download .EXE (windows + VIVE)


SCENES
FAST CLOUDS
Worried about performance?
Here is an example of a fast cloudy sky setup
SCENES
DENSITY BLUR 2
Simple example to demonstrate the new depth-based
blur effect
SCENES
LANDSCAPE SHADOWS
+ DENSITY BLUR

In this case, a textured fog volume is used as density


data for the camera effect.
This is not recommended because it has to be rendered
twice.
SCENES
TREES
Uniform fog sample using the new camera blur effect
SCENES
STATIC
VOLUMETRIC
SHADOWS
Single fog volume for ground and atmosphere.
A second FV is located on the top side to model cirrus
SCENES
DYNAMIC
VOLUMETRIC
SHADOWS
Single fog volume for ground and atmosphere.
A second FV is located on the top side to model cirrus
!
WHAT’S NOT
FOG VOLUME

Fog Volume is not a sky simulator.

Albeit you can render pretty convincing clouds, it was not


designed as a sky renderer system or time of the day suite.

Color won’t change with light angle.


Tutorials
Successfully tested on:

● GeForce GTX 970 ● GeForce GTX 970 ● GeForce GTX 980 Ti


● TITAN ● Samsung S5 ● TITAN
● iMac 27" with AMD Radeon R9 M395X
● GeForce GTX 980 Ti Uniform Fog only ● GeForce GTX 980 Ti
● iMac 27” Late 2012 with GTX 675MX
● GeForce GTX 1080 ● MacBook Pro (15-inch, 2016) Radeon Pro 460 ● GeForce GTX 1080
LIMITATIONS
Fog Volume uses scene depth to correctly interact with scene objects. Transparent shaders don’t write this information, which will cause Fog
Volume to ignore them. You won’t be able to sort transparent shaders inside a Fog Volume correctly. In this case, transparencies must be
rendered behind or in front of the volume, not inside.

Developed for shader level 4.0 Lower level compatibility is in the works. We will expect some limitations on lower end GPUs
COMPATIBILITY
WITH UNITY FEATURES

Orthographic cameras

Editor Isometric view

Reflection probes

MSAA

Prefabs

SpeedTree
COMPATIBILITY
TESTED UNITY VERSIONS

5.5

5.6.1p1

2017.1.0b10

2017.2.0b8

2018.2.0b4
COMPATIBILITY PlayWay Water
WITH OTHER ASSETS
COMPATIBILITY Helios
WITH OTHER ASSETS

Video done with Helios capture


COMPATIBILITY AQUAS
WITH OTHER ASSETS
COMPATIBILITY GAIA
WITH OTHER ASSETS

As of 3.2.1, Gaia will manage Fog Volume to be added to


the scene with a single click
PACKAGE CONTENT
BASE PACKAGE
You will get a 50mb base package after purchasing. It contains all the required code and the demo scenes.
PACKAGE CONTENT
EXTENDED CONTENT
There is a link to a big package of 200 mb with art content required for some of the scenes.
PROJECT SETUP
AND REQUIRED CONTENT
The included scenes require PostProcessing Stack.

POST-PROCESSING STACK
Link

Make sure that the camera script is correctly loaded.

EXPLORATION CAMERA
Xbox controller support: Download the input manager file from here and copy it to \ProjectSettings

COLOR SPACE
Linear recommended. Fog Volume will look similar in both cases, but light intensity will change.
Demo content has been adjusted for linear.

PROJECT REQUIREMENTS
4 layer slots available

UPDATING
Delete all the content in Assets/FogVolume before importing.
Fresh updates will be available from my site.

SCENE REQUIREMENTS
1 Directional light. It can be disabled, but FV needs its rotation, color and intensity.
GETTING STARTED
CREATING A FOG VOLUME

There are several ways to create Fog Volume objects:

Gameobject > Create Other > Fog Volume Fog Volume > Fog Volume

Create > Create Other > Fog Volume

Right click on Hierarchy > Create Other > Fog Volume


GETTING STARTED
SHADER VARIANTS
CUSTOMIZE YOUR KEYWORDS FOR QUICKER LOADS
Fog Volume has many options, and therefore, way too many shader variants. This takes too much time to compile, the editor takes ages
to load and we will get lag when enabling/disabling checkers. For this reason, what I do is to keep commented the features I never use:

This is done in FogVolume.shader


Make your changes in the first Subshader

The second Subshader belongs to the shadow render pass.


Fog Volume has a modular interface. You can hide panels
and inactive modules won’t show its properties.
FOG TYPES
UNIFORM
This is the most basic and cheapest fog type you may get and best suited for mobile
projects without blowing up the gpu :)

Parameters are very easy to understand. Here we only use visibility, size, color and
in-scattering.
FOG TYPES
GRADIENTS
Things are now much more complex. We have Gradient activated here. This means
we are now executing raymarching. You will see a new tab called Renderer. Here is
where we adjust the raymarching parameters.
You may noticed that Visibility disappeared. We have now to use “Intensity” inside
the Renderer tab.
Scene Collision will be activated by default. Turn it off if there aren’t objects
intersecting the volume.
The softness value adjusts the intersection range. 1 by default.
Jitter is useful to hide the gap between each raymarch iteration. Don’t abuse, it
makes things more expensive ;)
Sampling method defines the view ray method. You can choose between ray
distance to box or view aligned planes.
Unless the camera doesn’t look around, Eye2Box will be the best choice.

Max iterations tells the raymarcher the max iterations to perform.


Iteration step size is the size between each iteration. Less space means more
quality but more iterations needed to reach the end of the volume.
Draw distance is the max draw distance. The effect will fade before reaching the
end at the given distance.
Height gradient and radius fade are secondary fading methods.
View mode is a debug view mode. I will be adding more debug views in the future. I
will dig into this in another example.

The color parameter is now called Light Energy. With raymarch activated, this
name has more sense, since we have now a light equation. This value will multiply
the outgoing light.

We see now more lighting parameters. Ambient, which I set here to black and
absorption to zero. Those parameters have more sense when we have noise
activated.
FOG TYPES
NOISE
Noise has many options, and here is where performance will suffer more. Scale is the
global size of the noise. It multiplies Base Tiling and Detail layer tiling. Density makes
clouds more dense, affecting opacity and light absorption. Octaves represent the amount
of noise layers computed. When it is set to 1 it means: 1 base layer + 1 detail layer. By
default, 2 layers of noise are active. You can turn off the detail layer if Draw distance ==
1. Note that the more it repeats, the more expensive it will be.
Base layer has its own intensity value; Coverage, [0, 1] and own speed.
Detail layer will only be rendered when:
● Base layer opacity >0
● Base layer opacity < Cutoff
This saves a lot of unnecessary work.
Masking Threshold makes a soft transition to the detail layer where it starts.
Ambient and Absorption are active for this cloudy layer. Ambient is added to the light
equation and Absorption will play an important role. It is very cheap compared to other
lighting options. It will darken the dense parts of the noise and brighten the edges. It will
also affect In-scattering anisotropy and Halo opacity and diffusion.
In this case, lighting is a bit more complex. Directional Lighting is activated. One iteration
will be enough. Distance is used to displace the lighting result and Density will increase
light absorption and opacity.
Intensity and Contrast shapes the noise. To modify opacity without affecting the shape,
use Density.
We need Scene Collision activated to make it intersect correctly with the mountain and
trees. With Coordinates/Scroll we add a little of movement.
Jitter is activated in this case, since the gaps are more obvious when noise is activated.
Height Gradient sets a grayscale gradient from the bottom of the volume to the top given
min and max values to fade noise. This shapes the cloud opacity.
FOG TYPES
NOISE
In this scene we don’t activate Scene Collision in clouds because they do
not intersect the terrain, we must avoid unnecessary gpu work.

Height Gradient shapes the clouds making them less populated on top of
the volume.

We use here 2 Octaves (2 Base + 2 detail layers). When Octaves==2, a


new parameter appears: Curl. This value will reuse the Octave 1 detail to
distort the second detail layer.

Swirl Deformer is used to make repetition less obvious by shaping the


space coordinates with a swirl deformation.

Detail is added only at the edges of the base layer. Adjust the edge size
with Trim Threshold. Trim is used to subtract base layer with detail
layer. Making base layer dense with sharp edges will reduce the detail
sampling area, thus less expensive.
FOG TYPES
NOISE: RADIUS FADE

In volumes using noise we can use a spherical range to


fade the noise at the edges. This is not a very common
need, so it is disabled by default in the shader to avoid
shader variants. The tooltip explains how to activate it.

Activate Radius Fade and set a distance.


FOG TYPES
VOLUME FOG
We can fill the empty space left by noise or gradients adding fog. Activate
Volume Fog and a new In-scattering module will appear in the lighting tab.
The Volume Fog in-scattering works in the same way than the cloud
in-scattering. It will be correctly masked when it receives shadows.

We can push this effect with Start distance and make the transition softer
with Transition Wideness

Use the Ambient Color alpha to control the amount of ambient applied to the
volumetric shadow.

Low visibility will make the render cheaper. Raymarch stops once an opaque
pixel is drawn.
FOG VOLUME DATA
CAMERA SELECTION
A new object named “Fog Volume Data” will be created when there is a Each Volume will show now the camera in use at the very bottom of the
FV in the scene. We will manage from here what camera will be used to inspector. By clicking this button we will select that camera:
render Fog Volume.
If Game Camera is empty, it will search in the scene for a valid camera. If
none is found, Fog Volume will be disabled until a new camera is added
to the scene.
When we have several cameras in the scene we can assign any of them
manually or via scripting.
FOG VOLUME DATA
VIVE
After adding a Fog Volume, jump to Fog Volume Data and assign the eye camera:
Download sample scene

FV renderer expects to find the parent of the camera: (head)


STEREO CAMERA
To use a standard camera in stereo, make the game camera child of another gameObject and reset the camera transform
RENDERER
CAMERA SCRIPT
This script will manage the rendering in Game view.
Scene view is rendered at full resolution and performance will
be much slower compared to the Game view.

FogVolumeData.cs will assign this script to its assigned camera


automatically.
Depth layers: specify the layers that will be used to generate the depth
buffer (new in 3.2.1p2)
Activate depth-aware upsampling only if Scene Collision is enabled.
DeNoise can be used to soften the noise caused by jitter. Works only in
play. Seems like there are some problems with it from 5.6
RENDERER NOTE
Post Processing stack disables Depth generation. This will break
uniform fog and Scene view collisions. Workaround: enable DOF.

DEPTH & COLLISION WITH SCENE CameraDepthTexture will be used when Downsampling is 0 or
Camera Script is disabled. When enabled and set to 1, Fog Volume will
generate its own Depth map, so Fog Volume won't need
_CameraDepthTexture for textured fog (noise or gradient)

Depth is required when a textured Fog Volume (non uniform) intersects the scene and we use Downscale . With it enabled, we need Scene Collision active in our
volume:

Camera script

VIEWER
Use the prefab RT_Viewer to see the
generated buffers

Depth buffer in the scene Scotland


RENDERER
COLLISION ISSUES
Unity _CameraDepthTexture is a source of problems and there are many reasons that makes it not available.
Most common cases when running a forward camera:
● No directional light in scene
● Directional light without shadows enabled
● Postprocess stack turning off camera depth generation
● Scene View with light disabled
● Quality settings with shadows disabled

When is _CameraDepthTexture used?


● Fog Volume type: uniform

● Scene View
● Game view with FogVolumeRenderer.cs not in use
RENDERER
Ztest
In the case of background clouds, it will not be necessary to generate the depth buffer. Let's see how the scene “Fast Clouds” is set

Depth is disabled and we don’t


activate Collision in the volumes.
But we have to modify the cloud
Ztest value to make it to be
rendered in the background.
RENDERER
Ztest
Let’s go to the scene “Fast Clouds” and select the object Fog Volume [Clouds]. Within the tab Other we will find Rendering Options and then Ztest is set to
Less Equal.

This makes FV to be rendered in the background


RENDERER
Ztest
Ztest is set to Disabled by default
But for the scene Fast Clouds it is set
to Less Equal, so it is rendered in
the background

Ztest set to LessEqual

Ztest
Ztest is hardcoded in Surrogates.
Their Ztest is managed by the camera
script.
RENDERER
Ztest
If set to Always this is what we
would get.
It is seen correctly in Game
viewport because the Ztest is
internally managed for the
surrogate.

Ztest set to Always


RENDERER
Ztest
In “Scotland” we can see that
Ztest is set to Disabled. Always
works too. In this case we want
clouds that intersect the terrain,
thus we activate Depth, Collision
and then make them render on
top with Ztest=Always (or
Ztest set to Always
Disabled)
RENDERER
UPSAMPLING
By enabling Edge-Aware upscale we can fix the resulting artifacts from
low-resolution rendering.
A bilateral upsampling filter is applied to our RT based on depth
discontinuities. Enable Show edge mask to see the result of the edge
detection filter and tweak Depth Threshold until the artifacts are
minimal.

Edge fix and DeNoise don’t play well together because of the nature of DeNoise, which is a temporal effect
RENDERER
SURROGATES
We talk now about “surrogates”, which are cubes that sample the result of the offscreen render of the volumes. They are like TV screens, they just show the low-res
version in the scene. This way we can sort transparencies correctly.
When we turn on downsampling, textured fog volumes won’t be visible for the assigned camera. Our game camera will render the surrogates instead.

Auto Generated surrogates are made of a copy of the original volume mesh.

Every Textured Fog Volume will generate its surrogate (by default) when Downscale >0
We can cancel the surrogate at the very bottom of the Fog Volume UI:

Auto-generated surrogates have some limitations. They are good for a quick preview though.

LIMITATION
We can’t set the draw order in automatically created surrogates

They disappear when the editor is paused


RENDERER
SURROGATES
In some cases, we would have to create our surrogate manually because overlapping Surrogates don’t blend well together. It’s also good for performance to have as few
as possible to avoid unnecessary overdraw. Lets see some examples.
In the mockup demo we have 2 Fog Volumes. If we let them generate their surrogates, we can notice incorrect blending:
RENDERER
SURROGATES
Let’s create a surrogate manually instead.
Turn off Surrogates in the volumes:
RENDERER
SURROGATES
We will make a box that wraps the volumes. Then, apply the following material:

Set the layer:

Use RenderPriority.cs if required.


RENDERER
SURROGATES
And we’re done
RENDERER
SURROGATES
We are in the same situation in the ‘Showroom’ demo. In that case I used the “Render Priority” script to make it to be drawn before the glass:
Ground fog receives shadows from clouds volume.
Shadow caster
Go to the mesh renderer and set Cast Shadows ON
The shadow caster will show then some more options in the lighting tab:
LIGHTING
VOLUME
SHADOWS
Vertical offset is the distance from the shadow camera to the Fog SHADOW CASTER
Volume. To see the result, use the Prefab RT Viewer. You can see the 2
generated maps. First one is used for lightshafts, and second one is used
to shade the scene:
Relative rotation between Volume and
Sun can’t exceed 30º.

Shadows rotate with sun direction, but the angle between the assigned
light and the Volume can’t exceed 30º Beyond this angle, the shadows
position won’t be correct.
Attach light==true will lock the light rotation to the volume rotation. It is
useful to cast shadows from rotated volumes.

Shadow Color is the color of the scene shadows

The rest of the parameters controls the shadow blur.


Shadow projector
A new box will be created to shade your scene once you
have activated Casts Shadows. You will find it as a child of
your shadow caster volume: LIGHTING
VOLUME
Adjust its vertical position and vertical scale manually,
until every object in your scene is inside of it. SHADOWS
SHADOW PROJECTOR

A new object will be created to shade


your scene
Shadow receiver
Go to the mesh renderer and set Receive Shadows ON
The shadow caster will then show some more options in
the lighting tab: LIGHTING
VOLUMETRIC
Fill the slot with your shadow caster.
SHADOWS
Shadow Cutoff is simply a contrast adjust. SHADOW RECEIVER

At the very bottom of the inspector you will find


Shade a volume with another one
DrawOrder. Clouds must be drawn first.
Directional light
To enable scene volumetric shadows we add the script
“FogVolumeDirectionalLight” to our main light:
LIGHTING
SCENE
SHADOWS

Only textured volumes can sample shadows. Gradient or


noise must be enabled.
Directional light: setup

After adding the script, we are prompted to fill some slots.


1. Target Fog Volume
2. Layer used to cast shadows

https://youtu.be/OdvzG7oNR80?t=3m32s

NOTE
Shadows only affect direct light components:
● In-scattering
● Directional lighting
Directional light: view range
By default, the shadow camera will use the assigned volume size (X axis) to determine the view range. The whole volume will be visible and we will get
volumetric shadows for the whole volume.
Directional light: focus position
By default It will focus on the center of the assigned volume. But we can change that switching to Scale mode: Manual and Focus point: Game camera
position or GameObject. This way we can render the shadowmap only for a specific location when we have a large volume.

Example:
We want to bake a static shadow for these towers:
Directional light: baked shadow
With Update mode set to Interleaved (dynamic) we tweak Zoom and our game camera position until we have a good view of the area of interest where
we want to bake the shadow. Once we are happy with the location and view range we can switch to Update Mode: On Start.
We can now fly anywhere and the shadows will stay in the correct position. The cost of sampling this shadow depends on its size and FV iterations.
Directional light: shadowmap edges transition
If not taken into account, the edges of the shadowmap will cause shadows to appear suddenly. We will adjust the borders fade using “Edge Softness”.
Notice the smooth black frame in the miniature:

Smoothing range
Halo is an optical phenomena easily visible in cloudy nights
around the moonlight. Light gets refracted as it travels
throughout the cloud.
Halo
You will find Halo in the lighting tab. It starts with a
texture like this:
LIGHTING
It contains a 1D Grayscale gradient, which is used to
generate the colorful dispersion.
Left side corresponds to the center point of the
lightsource. Right side is where the halo phenomena is
more evident. We paint there sharper gradients.

HALO

Radial rainbows around


moon/sunlight.

Width and Radius will define the main shape of the ring.
Absorption will simulate how much light is scattered in
the cloud, becoming more blurry according to opacity.

To do: sliders to customize the RGB offsets


Lights

LIGHTING
For existing lights, add the script FogVolumeLight.cs and Fog Volume will automatically recognize
it. To create new lights, use the Fog Volume menu

METHODS
We can create lights that are not Unity lights, but simulated lights that only works in fog volume
and don’t cast shadows:


Fog Volume Point Light
Fog Volume Spot Light
LIGHTS
Turn Real-time search ON to refresh or hit play once. Lights found inside the volume will be
added. Turn Inside box only off to also add lights that are outside of the volume. LIMITATION
Once it is refreshed, turn off real-time search. Because of the big amount
of registers required,
Pointlights have been
disabled from 3.1.4 for
machines with shader level
below 4

You have 3 attenuation methods to choose:


● Beer’s Law (mainly for dense media)
● Inverse square (air)
● Linear (constant attenuation by distance)

Range Clamp helps to save gpu power, especially with Inverse square attenuation, which extends
over long distances.
Draw Distance is used to discard the lights according to its distance from the camera.
Lights discarding

Lights outside of the view frustum will be discarded from rendering. Light range is represented with a box and this is used to discard lights. When this box is not visible by the camera,
this light is discarded from the render. Usually, when we use the attenuation method: inverse square, which is extended along large distances, we have to increase the size of this box
so that the light is not discarded before it becomes not visible.
To view this box, enable other/ debug options / draw debug gizmos

Result:
Use Light visibility to increase the size of this box.
This value multiplies the light range
Self - shadowing

We can get more realistic shading if we activate Self shadow.


LIGHTING
In common cases, a small Shadow Distance and one Iteration
METHODS
will be enough. The image next shows an extreme situation,
where upper clouds shade lower clouds.

SELF - SHADOWING
Directional

LIGHTING
Directional lighting models the behaviour of light when it
travels inside the cloud. The amount of absorbed light is
defined by Density and the color inside the cloud is given

METHODS
by Extinction Color. Quality of this feature is adjusted
with Iterations. Adjust Distance to determinate the
distance between each iteration.

DIRECTIONA L
Lambertian

LIGHTING
Normals are computed to calculate diffuse lighting. This
method is extremely expensive, but we can compute it
only at a given Distance from the camera.

Amount is the intensity of the effect. METHODS


Lambertian Bias goes from 0 to 1. If set to 0, the effect will
darken all the lighting contributions. If set to 1, it brightens
the lighting contributions.
LAMBERTIAN
Normal detail will define how much detail to preserve
from the original cloud noise.

This option is disabled by default to avoid huge shader


variant counts. To enable, uncomment the following line in
FogVolume.shader:
Proxy Volume

As of 3.2 we can use proxy volumes to illuminate a


LIGHTING
textured fog. All we need is a light probe grid
METHODS

PROXY VOLUME
Proxy Volume

In some cases we will want to tint our (textured) Fog Color with the ambient, specially when using these GI probes
Proxy Volume: performance

Sampling the probe grid is a complex operation and performance suffers quite a lot:
Fog Volume allows to use box meshes to model / mask noise.
PRIMITIVES
We can create a primitive via menu button

Or using the “Create” button in the Hierarchy tab


We can feed Fog Volume with cube or spheres meshes to
shape noise.

Enable Primitives to activate this option. Turn Real-time


search on to find the primitives that are in the scene. Once
PRIMITIVES
they are detected, turn it off.

Distance fields only affect


noise and gradients.

Bug: when not in play


mode Enable primitives
and Show primitives
checkers are not updating
the viewport until you click
on it.

With Size==0, Softness==1 and Cutout==1 we get a sharp


cube, faithful to the original
In the case of the scene “Pillars” we want to get an artistic
look, we don’t want sharp boxes but soft shapes. With Size
we override the box mesh scale. With Softness we make
box edges softer. Cutout is used to trim ignoring the soft
PRIMITIVES
shape we defined above.

Turn off Real-time search once the list is filled with your
primitives. -Noise nor Gradients are not
computed outside the distance
Turn it on only to update the list. field.
-Each primitive you add increases
cost
PRIMITIVES
Let’s see another case where primitives would
be useful. Imagine the following situation

We want Fog only inside of the building and not


outside. We create a Volume that wraps the
building and then we add 3 FV primitives and
adjust their sizes and positions to match the
room and corridor volume

These are the values to match the distance field


with our given meshes.
PRIMITIVES
To enable the subtractive mode, choose between “Action types”

Only 20 primitives are rendered at once. The system will render the 20 closest ones and discard
the rest according to the camera proximity when persistence type == Cullable. To avoid a
primitive to be discarded, set the “Persistence type” to Persistent.
PRIMITIVES
BOX
We have now 3 different spaces resolved with a
single Fog Volume

We can look through the window to the wall in


front without having fog in the exterior.
COLOR
Management
In the Color tab we have some post-processing such as photographic
Tonemapper. Exposure will appear once activated.
Offset and Gamma are equivalent to the adjustment layer in Photoshop
called Exposure (similar to brightness and contrast)
Fog Volume provides different debug views to show us
useful info.

More modes will be added in future versions.

Uncomment this line in FogVolume.shader to enable this feature


Iterations

DEBUG VIEW
We find a drop-down list at the very bottom of the
Renderer tab containing all the debug view modes
currently available:

MODES

ITERATIONS

Raymarch stops when an opaque


pixel is drawn.

Iterations shows us the amount of iterations performed


per pixel.

Black means few iterations. Notice the black clouds. That


means that an opaque pixel has been reached and
therefore, the raymarch stops there. White means that the
total iterations performed are getting close to Max
Iterations.
In-Scattering

DEBUG VIEW
We can also isolate the effect of incident light scattering

MODES

IN - SCATTERING

Isolate and rule!


Volume Fog In-Scattering clamp

DEBUG VIEW
This will show the depth we set in the Volume Fog
In-scattering panel, in the lighting tab.

MODES
Start Distance is set to 0 by default, in that case what we
get is a linear depth [0, 1].
IN - SCATTERING CLAMP

Not to be confused with


In-scattering. This is the
In-scattering component added
to the Fog that fills the empty
space left by the noise cloud
(Volume Fog)
Volume Fog Phase (In-Scattering)

DEBUG VIEW
With this view mode we can isolate the final Volume Fog
In-scattering

MODES

VOLUME FOG IN - SCATTERING


SCREEN
EFFECT
Screen FX
Since 3.1.8 we have a new module for image effects. Use the prefab RT_Viewer to see the density input:

It will convolve the output image based on Fog Volumes


Density.

Add FogVolumeScreen.cs to the camera and select the


Fog Volume layer you want to use as density input.

RECOMMENDATION
Don’t ever use FogVolume layer as density
input, use FogVolumeSurrogate and it will be
free!!
IMPORTANT:

The assigned light must have these layers disabled:

Fog Volume will do this automatically anyway. In case that


the RT_Viewer does not show scene depth, this is the first
thing to check.
POSSIBLE ISSUES:

_CameraDepthTexture is required to make this work, but in some configurations it is not generated. With a deferred camera it
will always work, but lets see some cases with forward camera

● Using Postprocess-stack: it disables depth generation unless we turn on DOF, Motion blur, AO or TAA
● Not using PP stack?: you can use EnableDepthInForwardCamera.cs

No _CameraDepthTexture available
Screen FX: parameters

Module A: Scene Blur


- Density Layer: layer used as density input. This will be used as blur intensity
- Falloff: allows us to override the input density and make the blur stronger at lower distances
- Iterations: each iteration will sample the screen 4 times in full resolution. Be carefull with this :) 2 iterations will be enough
- Dither: this adds some noise to the sample coordinates. Use Playdead temporal reprojection to smooth the result
- Blur Spread: multiplies the fog density input (blur amount)
Module B: Bloom
- Bloom Dowsample: initial scale of the input sampler
- Threshold: luminance minimum value
- Intensity: effect intensity
- Saturation: color saturation of the blurred image
- Blur Size: bloom effect overall size
- Blur iterations: how many times to iterate the blur
- Scene Bloom==On: Fog Volume + Scene is used in the effect
- Scene Bloom==Off: Only Fog Volume is blurred
Screen FX
Select the Surrogate layer to use a textured Fog Volume as density input
NOISE
● Noise texture generator
FUTURE PLANS ●

3 Packed noises (RGB)
Texture mipmaps
● Optional world space coords.
ROADMAP
COORDINATES SPACE
● Gravity fields
● Currents, obstacle
AESTHETICS perturbation

● Density-based scene blur


● Gradient animation

LIGHTING
● Directional volumetric shadows
● Spotlights
● Density-based shadow convolution
● Point & spot lights volumetric shadows

USABILITY
● Preset system
● More debug view modes

PRIMITIVES
● Subtractive spherical
distance field
● Independent softness

BEYOND BETA
values
RENDERER
● Low-res rendering for VR
● Temporal sampling
● Adaptative resolution? This is the roadmap for the upcoming
● Low-res scene integration
versions of Fog Volume.
INTERFACE Feel free to contribute with feedback, ideas,
Custom inspector for requests or bug reports. Contact me directly
FogVolumeRenderer.cs
or post in the forum.

Your support makes this possible!


Done
CHANGE LOG
Older versions
NEW IN 3.2.1p2

● Fixed a bug related with visibility


● Mesh filter is hidden from inspector
● Lights can now be turned on/off without the need for toggling "Real-time search".
● Camera script can be removed when "Disable camera script"== ON in FogVolumeData
● Directional light debug miniature can be moved now
● Added a culling mask field for depth pass
● LightManager is correctly hidden from inspector
● Fixed unneeded shadow work performed in Depth pass
● Updated VR showroom (now mostly event driven, using SteamVR's libs, improved VR
start location -counter transformed start into meat space-, etc)
NEW IN 3.2.1p3
IN WORKS

● Enabled metal support for FV


● Fixed issues with PS4 support
● Quality settings fix
● Better depth-buffer behaviour on non-windows platforms
● Glitch fixing: shading rounding precision -Venus scene-, better quality-settings
behaviour, better scene-game viewports relationship.
● Lights now works on OpenGL (there was a too-many-uniforms error)
● Better behaviour of surrogates in Mac
● Better CPU perf
THE AUTHOR

DAVID
MIRANDA

Freelance Technical Artist

davidmiranda.me
ACKNOWLEDGMENTS
FOR SUPPORT IN DIVERSE FORMATS

RUBÉN CHRISTOPHER LEE CARLOS ROD


ALCAÑIZ SCHIEFER PERRY-SMITH MACARRÓN LÓPEZ

Indie game programmer Concept & Technical Artist Director at Infinite-Realities Rendering Engineer at DICE Software fellow at Unity Technologies
THANKS

Вам также может понравиться