♪ ♪ My name is Sjoerd de Jong. I'm the
evangelist for Unreal Engine in Europe. I am going to talk about
volumetric lighting and fog. Which means we are going to talk about
recent changes we made regarding this. Then I'm going to talk about
the basics of how to enable it. I'm going to talk about configuring it
and understanding it in general, and also how it is being affected
by lighting and shadows. Then we are
going to move forward. We are going to find out
that is actually not good enough. We are going to move forward by
making local volumetric fog clouds. To further enhance it, I'm
going to wrap up with a brief look at a more an
advanced setup of all of this. Good.
This is what we want to build. We have a beautiful
little nature scene here. That is the level we have
on the other screen. I put that on Lit mode too. No lighting.
You see we have a deer here We are going to have sunrise. That is essentially
what we will work with. Good. Now I'm going to start
very, very basically. We are going to simply add
lights to the environment. In the Modes panel, I will go to Lights.
I'm going to drag in a Directional Light. In the Viewport, I will set
the View Mode back to Lit. This is the sunlight. The Directional Light is the sunlight.
If I rotate it, obviously it changes. There is not too much to say about this.
It is pretty straightforward. Add a light; that is it. The reason why I bring it up
very early now is because later on I'm going to change some
of the settings in the Directional Light because that is going to be important
for the fog we are going to add. For the time being,
there is nothing more to say. I will just add the next one. We have a Skylight. A Skylight is
the indirect lighting. The Directional Light
is the sunlight itself. That is the light that comes
directly from the sun. The Skylight
is the indirect lighting. That is the light
from the atmosphere; the sunlight that gets caught in
the atmosphere of the planet, gets bounced around, and then
comes from all different directions back to the surface. We can see this work if we disable
the Directional Light for a second. I am disabling that. I will select the Skylight. I'm going to
increase the Intensity quite a bit, so you can see what is happening.
You can see, we have this. We have this because a Skylight
actually captures a picture or cube map, of the entire surrounding geometry. Now the surrounding geometry
usually means the sky itself. Essentially, it takes a picture of this. Then it uses that picture to
project the lighting back down. The lighting that gets
projected onto the world is actually a picture of the sky
projected downwards. This means if the sky is
orange on one side like here and blue on the other side, then the light is going to reflect that. When l go back to the level and
switch the View Mode to Lighting Only, you can see this happening.
It is orange here, and bluish there. That is quite nice. Unreal Engine already
did that for several years. There is nothing too
new or special about it. Recently, we have been improving that
further because it wasn't good enough. Recently we have added multiple Skylight
bounces, improved Skylight precision, and volumetric lightmaps. The following is what it all means. First of all, it is more precise. You can see the image
switch in a second. This is how it used to be.
It is very uniform. It is not very interesting. This is what it is doing now.
It simply got more precise. You get more, richer colors;
and more variation in brightness. That is happening by default. If you are using 4.18 or 4.19,
it simply happens. Then secondly,
we have more Skylight bounces. Before we changed this, light from
a Skylight could only bounce once. The light from the Skylight comes in,
it hits the surface, it bounces away, and that is it. It does one single
light bounce, and that is it. That is not enough. We changed that.
If you go into World Settings, there is a setting you can configure
called Num Sky Lighting Bounces. I set it to 2 because in this
environment, you don't really notice that very clearly,
it is bouncing a lot. You can now configure it. Because of those two changes,
you can do crazy stuff. For example in this setup,
imagine this picture is the sky. It is a very strange sky, but imagine
for a second this is how the sky looks. Then we made a box.
This is a box inside the box with a small hole in it.
You can see that is the hole in the box. The light is actually precise enough
to bounce itself into that hole, back into the surface inside, hit it the wall on this side,
and project itself. You can see that is the face of
the person there upside down. It is like a 19th century pinhole camera.
It is simulating a camera. It is a game engine. We can get this more precise
if we shrink the size of the hole. That is crazy! It is completely useless for games
because you will never do this. It took half an hour to render
that little cube here. You would never do that, but the fact you can do that
if you want to is awesome. Anyway. The third and most important change
for us right now is volumetric lightmaps. I will show you exactly
what it is in a second. Let's first focus on the difference. The left picture is
how it used to be. The right picture is what it is now.
Again the lighting is richer, there is more variation, etc. The challenge we have in real-time
rendering in general, not just in Unreal is if we bake the lighting
into the environment... If the lighting has been baked
and pre-processed into lightmaps and if you then have dynamic models
that go through the environment such as a character, weapons,
vehicles, monsters, enemies, or anything that is moving
through the environment; then how do you figure out
what the lighting is for that model? You couldn't have baked that
because the light was already baked. Up until a couple of months ago,
we did this in UE4 by placing an indirect lighting cache, which is is essentially a
large grid of lots of points. There would be a point
here, a point here, a point here, etc.
We simply covered the world in points. Every point remembers
how much light it has. But it wasn't very precise.
You can see what is happening here. We have now changed that with volumetric
lightmaps, which means the following. I'm changing the level to the exact same
level with the lighting already there. It is just the same set up. You can see here. If I click Show >
Visualize > Volumetric Lightmap, it shows this. Now, this is crazy.
Do not do this at home. For the sake of the demo,
I increased the settings a lot. The density of those spheres you see
is much higher than it probably should be. It is probably a bad idea to do
this in a game with this density, but for the sake of example it works. Even with default settings you would
get the same, just at a lower density. You can see it populates the world
in points. Each of these points not only remembers the ambient
lighting in that given location, it also remembers the direction
of the light at that given location. It remembers there is ambient light
coming from this side, which is orange; and coming from this side
which is kind of bluish. It captures much more richness in how
the lighting is stored and remembered. I'm going to click
Show > Use Defaults to turn it off. I will set the View Mode back to Lit. Since we have the volumetric lightmaps there
and we are essentially storing the light
brightness and direction in the world with
different points in the world, we can then use
that information to apply to the color and
brightness to the fog itself. I'm going to go forward and
set up a very basic fog effect. From the Modes panel,
I will drag in Exponential Height Fog. We get this. First, I have to change
these two numbers very quickly because later on I'm
going to have to rely on them. I will increase the Density. We get this. Cool. That is how fog
used to look in games. This is how it always looked in games.
There is nothing special about it. It is just a layer of color that is blended on top and blended
with distance. That is essentially it. We have grown used to that
over time in games. We have grown used
to this kind of look. We have grown used to the
problems that this has as well. Imagine we have a forest
like we have here, with bright blue fog
like we have here. Then imagine in that forest there is
an abandoned house somewhere. The moment you walked into
that dark, abandoned house you wouldn't expect to have
bright blue fog inside. It should be dark inside. That is not what happens
with this kind of setup. You can see I don't have a
house here, but I have a bush. [Laughing]
Imagine this is a house. If you are underneath the bush, it doesn't really get dark.
You get this layer of blue on top. You get this.
See? That is not really supposed to happen. We have grown used to that over the
years, and it is completely incorrect. This is where
volumetric lightmaps come in. If I check the Volumetric Fog property
under Settings in the Details panel, the color changes instantly
because the color is now red from those volumetric lightmaps that
populate the world. That is why the color is
now mostly orange. The color is also affected
by the Directional Light, the sunlight. For the sake of making this
easier to explain, I'm going to temporarily disable the
Directional Light. Sunlight is off. We are only using the Skylight, which in turn, because
it was set to static, was baked into
the volumetric lightmap. This is only using the
volumetric lightmaps. I'm going to increase
the settings a bit. Everything I'm going to do in the
next couple of minutes will be extreme. It is going to look like
a nuclear bomb has gone off. That is okay. I just want to demonstrate
and then we'll bring it back to a more reasonable
density later on. You can see there is a bit of
richness in the color. It is not just one color
of fog, it is richer. If you go back to this
bush we had earlier, you can see it actually
darkens if you are underneath. It actually respects the lighting
and the shadowing. It goes really really far.
If I go back to the main area and in the Palette under Lights
I drag in a Spot Light, now there is a setting for
Volumetric Scattering Intensity. In other words how much
does this light, light up the fog? I'm going to say okay, you know what?
That should be probably be pretty high
set to 20-40 or so. We get this now. We now have a Spot Light
actually illuminating the fog itself. it is proper. Look, we can
actually go through it. You see it is completely smooth
no matter how you look at it. It just works. If we have that, then we can
go another step further because this works
in every single light. That means it works
on particles too. These fireflies you see flying around
here is a little Particle System. There is a particle. It is a very simple particle,
but it has a Light module in here. Every particle is casting a light. If it is casting a light, we can make
the light also affect the fog again. In the Details panel,
we have Radius Scale. I am going to change the
radius to something bigger. You can see what
you get here is this. It is actually lighting up the fog
itself as the particles move through. The settings are a little bit extreme.
Maybe I should do a bit less. Maybe something like that. Imagine having
a fire with embers. If the embers fly away,
they actually light up the fog. Isn't that cool? It is just some clicks.
You just click, click, click, and effect. That is awesome.
That is what I love about Unreal. Anyway, let's make this
more reasonable again. Back to what I had. Then let's take a look
at the sunlight because what I did a few
minutes ago was disable the sunlight. I disabled that one. In the Details panel,
I will click Affects World to enable it. You can see the fog instantly
changes color again as expected because the fog is now also
receiving lighting from the sunlight. It is reading the value of
the volumetric lightmaps, and it is reading the light value
of the sunlight as well. That is now the color we see,
but we also see these god rays. You get this. The god rays we are seeing here
are actually the shadows itself. The sunlight is now
shadowing the fog. It is receiving dynamic shadows
blended on the fog. It is crazy how far this goes. If I turn off Cast Shadows,
you clearly see the difference. It is literally the shadows
affecting the fog. It is not a visual effect;
it is literally the shadows. That is really cool, but it is
still not good enough. There are two settings you
can enable to further complement this and make it even cooler. I'm going to turn off
the fog temporarily because I want to look at take a look
at one of them without any fog present. In the Details panel for
the Directional Light under Light Shafts, there is Light Shaft
Occlusion and Light Shaft Bloom. If I turn on Light Shaft Bloom,
I get this. It is kind of the same thing.
You get god rays, but you get god rays by
brightening the screen. Light Shaft Bloom is
god rays by brightening. Light Shaft Occlusion is
god rays by darkening. That is it.
Brighten, and darken. I have to turn the
fog back on again. A nuclear bomb went off.
Ignore that for a second. If I turn off Light Shaft Occlusion
and bring the Intensity up or down, you can see what happens. It is a similar kind of effect;
you get god rays just like a shadow, but it can use this to further
complement that. I think a blend of all three
is probably the best. Now we end up with this. It is cool but it is a bit
extreme, right? It is really rather extreme. I will go back to ExponentialHeightFog
by selecting it in the World Outliner. You distract me.
[Laughing] Let's turn down the fog settings. Maybe this is more reasonable,
maybe that is prettier. But is it really? Because it is still the
same color covering the entire screen. It is still the same density
covering the entire screen. We would like more control.
We would like to say there should be more fog
here near the tree, but a lot
less near the deer. Preferably, we have a nice
composition going on where we have a wall of fog
or smoke coming in almost. Some pretty little smoke near the deer
so you can properly see the deer, and then a lot more smoke on this side.
We want to control it. We want to control the color as well,
so it is not all the same. In order to do that we have
to make local volumetric fog. I'm going to scale the actual fog down,
and set Fog Density to 0.1, which is pretty subtle. I'm going to set up a Material. Right-click n the Content Browser,
and select Material. In this Material, essentially I'm going to recreate
what you see on the slides. You can create local volumetric fog
by using the Material Editor, and by configuring that to be a Volume
Material; it is a special kind of Material. Then hook that into a Particle System,
and then it will be rendered as fog. That is what I am going
to set up now. I need to setup what I see on the slides.
I need to know the world position. I need to know the
particle position because this is connected to
the Particle System, and therefore also
the particle radius. I also need to simply have
the value of 0. They all come together
into a Sphere Mask. The Sphere Mask is a bit too intense.
I'm going to multiply it by 0.05. We multiply it by 0.05,
and that is it. You can see the Material as a whole here;
you can see the inputs there. It is still a regular Material.
I just made a Material, but it should be a Volume Material.
It should be a special kind of Material. I'm going to click away. The main
properties are on the bottom left. In the Details panel, Material
Domain is set to Surface. Let's set Material Domain to Volume. That changes the inputs.
That is cool. There is an error at the
bottom which says, "Volume materials must use
an Additive blend mode". Blend Mode is set to Opaque.
Click the drop down and select Additive. That is it.
It is just a requirement. Having changed
these two properties, I can now hook this up to
Extinction on the FogMat node. It is cool.
I have to set a color. I'm going to set the color to some kind
of blue similar to what we had earlier. Roughly something like that. Click Apply to apply that.
Let's close that window. Let's make a Particle System. I have the Material assigned to the Particle System.
This is the Material I just made. I'm going to say it
should spawn a little bit more. This will be a very basic particle;
it is not going to be super pretty. It is going to flicker, and you're going
to see some popping and such going on. But it is going to show the
basic idea of how this works. This will be a basic Particle System
that spawns pretty large sprites. In the Initial Size module,
I will set X for Min and Max to1500. It should be spawning in a radius. Right-click go to Parameter,
and select Cylinder for location. Set the Constant to 1750 or so. That is kind of it. Again, we are going to see some popping
and it is not going to be 100% ideal, but the idea will work.
The moment I drag this in, we get this. See it is literally a local cloud. You can drag that up, see? It somewhat renders as particles, but it
is not entirely a regular Particle System. In fact if I were to place this here and
start flying in there with my camera, you don't see the sprites appearing.
It literally behaves as the fog looks. It looks the same, see? Except, you can see some popping
in and out. We will fix it in a second. It is kind of behaving the same which
means we can now make local little clouds. We can say there should be
one cloud there and one cloud somewhere there.
I don't know. Something like that.
You see, you can make local clouds. Here is the thing.
If it is using... I am trying to delete these.
Let's delete these. If it is using the regular Material
system and the regular Particle Editor, then how far can you go? What can you do with it? I got carried away when I
was building this and I spent over a day building
what you are going to see. This is what you can do
if you keep pushing it. It is meant to inspire you.
It is a bit over the top, but just where is the limit? First of all, I need to have that
specific shape into it. I can accomplish that by
making a mesh like this one, which is the shape I want
to have for the fog effect. It turned out that it was a bit too small,
I am going to set the Scale to 2.0. I will position it roughly somewhere
there, which is kind of what I need. Then, I have a particle made.
This is the particle I'm going to use. I'm going to show you in a
second exactly how it works, but this is how it looks
in the Particle Editor. There is nothing special going on;
this is very, very basic. The only thing that
special is this one, which is a Skeletal Mesh Vertex/Surface
Location (Skel Vert/Surf Loc) which will essentially spawn
the particle based on a mesh. That is the mesh I just added. This one has a parameter added
with this particular name. Let's close that.
If go back to the level, these are the properties of the particle,
and I press Expose Parameter it automatically detects
all the parameters within my particle.
I only have one. It shows here instance parameters. This automatically showed up. That is the
same name you just saw seconds ago. That asks for an Actor. Let me select the floor here. That is not the right one;
let's do this again. I have the floor selected.
The Actor now says SM_FogMesh. This is somewhat hacky. In order to get rid of
this mesh here, I am going to add
an invisible Material to it. It is somewhat hacky. That step could have
been done better. Now if I move that model up
in the air, you can see what happens. We get this.
It has a specific shape. I will make this full-screen. It has pretty advanced shading. You can literally go into
those clouds and I get this. You can kind of see there is some
lighting and shading going on. It is not just a flat piece of fog.
It is actually kind of billowing out. Again if you go into it with a camera,
there is no issue with doing that. It doesn't look like you go
through sprites or anything else. Essentially, we get this. It also has more color variation. You can see it is clearly yellowish
there and blue in other parts. Let's move that back down
to something like this. Let's go back to windowed mode. I also have a small local cloud
I'm going to place alongside of it, which is this one. It is kind of the same idea,
it just doesn't have a specific shape. It is just one little cloud of something. I'm just going to drag that
left and right next to it. I think I want one cloud
somewhere here. Maybe something like that. Maybe one there, and I think one in the
back near where the camera is located. We end up with
something like this. You may ask, "How did I
make this setup?" This is how it works. This is the Particle System.
You saw this a few seconds ago as well. There is nothing special here. That has a Material underneath;
it is a Material Instance. That just tracks all my settings.
There is nothing special there. It track settings.
There is another instance underneath. Sorry. Actually,
I should have taken this one. They all go to the
same one eventually, but... [Indistinct] Then, we get the Material. This is the Material I'm using.
That is the thing. If we are using the regular
Material system, the sky is the limit. Keep building.
How far can you push this? It is the Material Editor.
It is the same for the Particle Editor. The really cool part about Unreal
is how all the tools are tied together. You can kind of see what
I have done here. I will briefly go over it. First of all, I'm simulating lighting
by darkening the bottom of every cloud. You kind of get this feeling that
the cloud is shadowing itself because the bottom is simply darker. Then I take this texture, which is some
kind of cloud texture blended on top using macro UVs, which is
an existing particle function and feature. This gets blended on top,
so it gives some extra richness. It is not just a flat color of fog,
there is some extra turbulence in there. Then, I also brighten the inside
because it felt better. It kind of simulates lighting,
as well as it just felt more complex. Then, I fake additional god rays. This is actually the fourth way
I am doing god rays. I take the texture I have over here, which looks like that. This is actually a merge map so it should
be viewed with just one color at a time. Say something like
that or this. I took one of these textures and essentially I'm planar mapping
the fog with the texture. Imagine you have a model,
and you planar map a texture on top. It would stretch out on the sides. You get rays. Essentially,
you get lines going down. If you were to take
a cloud of volumetric fog and you project a noise texture on top, you get lines going through
the entire thing. Now I have god rays. Then I rotate the
projection of my planar map to match the direction of the sun, and now I have lines passing through
all of the fog. I have god rays. It is a very cheap and fake effect. It is pretty fake and it wouldn't
respect the fact there might be shadow. There might be an object blocking the sun.
It wouldn't respect that. But in general,
it works pretty well. Another thing that I did is color. Most of this looks kind of complicated,
but is pretty straightforward. The one thing that special is this because this is the color
you are looking at. The fact it is yellow in the middle
and bluish on the side is because I painted this
texture in Photoshop, and then projected the
texture on top of it. I manually colored it
by painting this. That is defining what the color of
the fog is at different locations. I had complete control. This is this the same we have done
before with one extra setting. That is basically it. Now what we end up with is this. Before I've wrap this up and
show you the final fly-through, just a brief word
about performance. Like everything, it cost something.
This has an impact on performance. The performance impact is not huge,
but it still exists. The engine clearly tells
you how much it costs. If you bring up the GPU Profiler,
you see this is volumetric fog. It clearly tells you this is what
we are spending on this effect. That is reasonably big.
It is the biggest bar of the whole profiler.
It is pretty expensive. But if you look at the number,
it is less than three milliseconds. That is doable. This is a fairly powerful
computer I have here, but it is doable. I'm doing is in the editor, which is
affecting the accuracy of this. I'm doing this with the most
complex setup you can probably do. I have an advanced Material in there,
I have multiple particle clouds here, and the particles of the fireflies
affecting this as well. This is like the worst-case setup and
it is still only three milliseconds. It is pretty decent. It does cost
something, but it is pretty decent. If you were to switch this back to
only having standard volumetric fog without all the particles and
the Volume Materials set up, to my test it is usually around
0.5 to 1 millisecond to run this. It is perfectly doable. The more lights you add
that affect the fog, for example all the
particle lights of fireflies, for every light that lights up the fog
it gets a little bit more expensive. The expense comes down to how many
lights do you have affecting this thing? Then on top of that, it comes down
to how many particles with Volume Materials do you have
and how complex is that Material? If you are a little smart about these
things, you can make it more performant. Let me just fly it through,
and that will lead to the end. This is the result. Just a small one-minute fly through. The reflection on the water is too sharp
for being in a foggy environment. You can tweak that with a
setting on the sunlight. On the Directional Lights
there is a property for how wide the specularity
should be spread. You can fix that by
changing that number. Then, this is the result. Cool. Thank you. ♪ ♪