>> Welcome to Unreal Tips and Tricks.
In today's episode, we'll look at creating crepuscular rays,
more commonly referred to as God rays or sunbeams.
God rays are most visible when the sun is below the horizon,
but can appear at other times if the conditions are right.
The reason for their appearance
is due to particles in the atmosphere.
The lower the sun's position in the sky,
the greater the chances of seeing them
as there are more particles in the way.
In Unreal, God rays can be simulated
in a number of different ways, each with its pros and cons.
One way to create God rays
is using geometry and gray scale materials.
We can also use light shafts on directional lights.
And finally, Volumetric Fog allows us to create
physically accurate God rays.
Let's quickly discuss some of the pros
and cons of each technique before we jump into Unreal.
First up, we have the geometry and material method.
Now this has the lowest GPU cost,
but you're going to have to build your God rays from scratch
by creating the geometry in the materials needed.
Now this technique, while cheap,
does not look the greatest from all angles or in all situations
and it's not going to be physically accurate.
This technique works great for lower power devices
such as mobile phones.
The second technique is using light shafts.
Light shafts have a higher GPU cost
and they only work on directional lights
and only in screen space,
meaning that the directional light source
has to be on the screen in order for you to see the light rays.
There are two techniques when generating light shafts
and that is to use bloom
to basically create your light shafts
by brightening the screen or to use occlusion
to create light shafts by darkening the screen.
You can use both together,
but this will also increase the performance cost.
Finally we have Volumetric Fog,
which is the technique we'll be using today.
Volumetric Fog does have a higher GPU cost
and the more lights you use in your scene,
especially lights that generate volumetric shadows,
the higher that cost will be.
The great thing is that Volumetric Fog
works with point lights, spotlights,
rectangle lights, and directional lights.
It also works with light functions on directional lights
and it can work with dynamic as well as static shadowing.
You can even limit the fog to specific areas in your scene
by using particles.
That's beyond this tips and tricks video today.
At the end of the tips and tricks video,
I will be providing you with a link to the documentation
as well as a YouTube video
that goes into more detail on using particles in this way.
The other great thing about Volumetric Fog
is it's physically accurate and it supports translucency,
but it doesn't work with IES profiles currently.
Alright, let's jump into Unreal.
In order for our God rays to show up,
the first thing we're going to need
is some Exponential Height Fog. You can either search for fog
and then grab exponential height fog from there,
or you can go to Visual Effects
and then find Exponential Height Fog there
and just drag that into the scene.
Of course, you'll also need a light
and in this case we've already got a sunlight in the scene.
Now before we actually create our Volumetric Fog light rays,
let's take a look at the second technique
and that is using light shafts on our directional light.
So with the directional light selected,
we'll just go down to the Details Panel
and scroll down until we find Light Shafts.
From here you can see the two techniques that we can use.
Light Shaft Occlusion and Light Shaft Bloom.
We'll go ahead and enable Occlusion
and Light Shaft Bloom at the same time.
You'll notice that Occlusion didn't really
make that much of a difference while Light Shaft Bloom
made a greater difference.
Now we can go through the settings here
and reduce the brightness,
but another option is to select our material for our Skydome
and adjust that image. I'm going to select the Skydome
and then we'll go to the material that's applied to it.
In this case we have an HDR image
and we can control the brightness
as well as the contrast of the image.
So I'm going to control the brightness here.
We'll go ahead and bring that down
and you can see how it affects
the overall brightness of our God rays.
Likewise, I can adjust the contrast
to help eliminate that really bright ray.
But let's go ahead and set these back
to their default properties for now
and we'll go back to our sunlight
and we'll scroll back down to the Light Shaft section.
Using Bloom Scale, we can control the intensity
of the bloom effect on our God rays and again,
that's brightening the screen to create the God rays.
Alright, so let's go ahead and turn that off
and now let's look at using Volumetric Fog
to generate our God rays. The first thing we need to do
is take note of some of the properties
on our directional light.
On the Details Panel under Light,
the first thing we need to take note of
is Volumetric Scattering Intensity.
This setting will control
how intense the lighting is of our God rays.
If we scroll down a little further,
we need to make sure that we have the advanced settings open
and we need to enable Atmosphere Fog Sunlight.
Finally, if we scroll down a little further,
you'll notice that Cast Volumetric Shadows
is enabled by default on a directional light.
Now we can jump over to our Exponential Height Fog.
From here, we'll scroll down to Volumetric Fog
and simply enable it.
With all the default settings, it doesn't really do much.
For Volumetric Scattering Intensity,
I'm going to boost this up
just for the purposes of this demonstration
to something pretty high.
We'll go ahead and set this to a value of 30.
Now obviously this is very blown out
and not very realistic looking,
but this will allow me to demonstrate some of the points
that we're about to look at next.
So we're going to jump back to Exponential Height Fog.
The density of height fog can be controlled in a number of ways.
First up, you can control
how thick the fog is using Fog Density.
You can control how high up the fog goes using
Fog Height Falloff.
You can also adjust the fog's height
by simply moving the Fog Actor up and down.
This controls the starting point of the thickest part of the fog
normally found at ground level.
This is the point at which the Fog Height Falloff
begins its calculations.
Let's move down to the Volumetric Fog rollout now
and talk about the different properties
we have available to us.
First of all, we have Scattering Distribution.
Now this is going to control
how intense the light rays are based on
where you're looking at them from or the source of the light.
At a value of 0.2, if I turn my camera away from the light,
I can still pretty much see the God rays.
In fact, I can even look all the way to the other direction
and still see the God rays.
If I bring this closer to a value of one,
so let's set it to a value of 0.9.
Now you can see I can't see the God rays anymore
unless I turn my camera towards the sun.
I'm going to set this back down to a value of about 0.3.
Next up is Albedo.
Albedo controls the reflectivity of the particles in the air
and in the case of water-based particles like fog or clouds
or whatever the case may be,
like mist, you're going to want to keep
that close to a value of one or white.
But if you bring it down lower,
you're going to be simulating things like smoke and smog
and other particles that aren't water-based.
So let's go ahead and bring this back up
and leave it at a value of one. Incidentally, if you want to,
you can actually tint the fog color here as well,
but instead I like to leave it at a value of white or one.
Next, we have Emissive.
Emissive can be used to simulate global illumination
if you're not using baked lighting
as well as being used to generate illuminated fog
and other artistic effects. Next step is Extinction Scale
and that basically controls the intensity of the fog rays.
And what it's really doing is it's basically controlling
how much of the participating media is blocking the light.
So if we bring this up higher,
you can see that it gets much more opaque, the God rays.
But a lower value is going to make the God rays
much more transparent.
After that, we have View Distance
which controls how far away from the camera
the fog effect is being generated.
Now the further away you set this,
the greater the chance
that there will be rendering artifacts,
so you want to be careful about increasing this value too far,
but obviously if you bring this value down too low,
then you may see a visual artifact
where the Volumetric Fog kicks in in the background.
I'm just going to leave this at the default value of 6,000.
Static Light Scattering controls the contribution
of baked lighting to the Volumetric Fog.
It does this using a Volumetric Lightmap.
The Volumetric Lightmap is generated
as part of the lightmass baking process.
We can visualize the Volumetric Lightmap using the Show menu,
then Visualize, and then choose Volumetric Lightmap.
Modifying the Volumetric Lightmap
is beyond this Tips and Tricks video.
If you'd like to learn more about it,
be sure to check out the Unreal documentation.
You'll find it under Engine Features,
Rendering and Graphics, Lighting the Environment,
Volumetric Lightmaps. The last setting here,
you'll need to open up the advanced settings here,
and this is Override Light Colors with Fog
in Scattering Colors.
So if we enable that, we're going to alter the color
of the Volumetric Fog based on three different settings here.
The first one is Fog in Scattering Color.
The next one is an Inscattering Cubemap Texture
that we could use here
and finally Directional and Scattering Color.
For instance, if I go ahead and select Directional
Inscattering Color, I can tweak the God rays here
and the Volumetric Fog color using a color wheel.
As a final point, let's take a quick
look at the performance of our God rays.
If we go to our viewport options and then go down to Stat,
Advanced, we can select GPU.
Here in GPU we can see Volumetric Fog currently running
at an average of 0.3 milliseconds.
And now let's talk briefly
about the scalability settings in Unreal
and we'll see what kind of effect changing them
has on Volumetric Fog. If we go to Settings,
and then go to Engine Scalability,
we want to change the Shadow settings.
Right now we're using Epic.
Now this is best for a high end PC,
but if say you were developing for console,
we'd want to click on High and that's going to reduce
the quality of shadows as well as Volumetric Fog.
Back in the viewport, you'll notice now that Volumetric Fog
is only taking up about 0.05 milliseconds on average,
but you can also see
there's a lot more artifacting in the viewport.
So we'll go ahead and go back to our Scalability settings
and set Shadows back to Epic.
The artifacting is now gone, but our Volumetric Fog
is now taking an average of 0.24 milliseconds.
The other thing that will affect performance with Volumetric Fog
is using Volumetric Shadows on point and spotlights.
To demonstrate this, we'll use a spotlight,
so we'll drag that guy into the scene
and we'll increase the intensity to a thousand candelas
and we'll pump up our Volumetric Scattering Intensity.
And finally we're going to turn on Volumetric Shadows.
And before we enable it,
you can tell that right now Volumetric Fog
is currently taking up about 0.24 milliseconds of the render.
So if we go ahead and turn that on now
you'll see that it's jumped up to an average of 0.27.
So obviously the more of these we add to the scene,
the greater amount of time Volumetric Fog
will take up on the render thread.
If you're trying to get God rays
without too much fog in your scene,
you can reduce the Global Fog Density and increase Volumetric
Scattering Intensity on the light
to create stronger light shafts without having a lot of fog.
And Volumetric Fog based God rays
can also be used in conjunction
with the light shafts on a directional light.
For instance, turning on Light Shaft Occlusion here
and then increasing this here we can see the effect
that it has on our volumetric based God rays.
If you'd like any additional help in learning
how to use Volumetric Fog,
be sure to check out the two links on the screen.
The first one leads to the Unreal documentation
on Volumetric Fog,
and the second one leads to the Volumetric Fog
feature highlight YouTube video. Thanks for watching,
and we'll see you on the next Unreal Tips and Tricks.