Hour 18. Environments
What You’ll Learn in This Hour:
Creating and manipulating World Environment
Enabling environmental effects such as fog and depth of field
Using skies and ambient lighting
Adding and managing Reflection probes
Improving global illumination withGI probes
This hour is focused on the ambient side of 3D worlds. Godot provides tools to create and enhance the environment of your game scenes.
These tools include the ability to create an ambient imagery, be it a solid, clear color or a panoramic sky, depth of field blurring, fog, and many
other adjustments. There are also two probe nodes, ReflectionProbe and GIProbe, that help create more realistic environments with better
reflection and materials that emit light.
World Environment
Godot provide a special node,
WorldEnvironment, to deal with the ambience of the stage. Usually, you only need one such node per
scene. Once it is placed on the tree, it starts to have an effect, because Godot searches for it by default. If you have do not have World
Environment in your scene, the engine will use a default one.
Environment Resource
While important, the World Environment node by itself will do nothing. It needs an
Environment resource to set up the ambience of the
scene. You can create one by using Inspector and then editing its properties.
TIP
Default Environment
When you create a new project, Godot automatically makes a file called default_env.tres, which contains the default settings for an
environment. This will be used if a World Environment node is not available. You can edit this file by double-clicking it in the file system dock. It
will be shown in Inspector, where it can be changed and saved.
You can also change the resource file to use or even remove the default by changing the Default Environment property in Project Settings,
under the Rendering > Environment section.
NOTE
Camera Environment
While you can set a World Environment node to see the effect of its environment resource in Editor, it’s also possible to set an environment
resource directly into the
Camera node. The camera’s environment will override the others when the camera is active. This won’t be
shown in Editor (unless you use the camera preview), and can be useful if you want different ambiences depending on the active camera, e.g.,
a desaturated view for a CCTV image.
Sky
The first section of the Environment properties controls the background. There are some simple options, such as using the default project’s
clear color (as defined in Project Settings) or using a custom color. Setting a clear color will make a solid background. Sometimes that’s all
that is needed, but you can also use a proper sky view for your own game world.
If the Background mode is set to Sky, you’ll have two options:
PanoramaSky or
ProceduralSky. You can create a new type of sky by
clicking the property field in Inspector and selecting the option to create a new one.
ProceduralSky
This type of sky is generated by the engine. If you don’t have a sky image available but want a more realistic view than a solid background, this
is a good option. It’s also great for quickly prototyping stages in the open. Note that this might take a toll on performance, so it’s better suited
for testing. The procedural sky has a few properties that allow you to customize the default look.
In the Sky section, you can select the colors for the sky and the horizon, as well as how much they’ll blend by using a curve setting.
The Ground section has similar options for the bottom section of the environment.
The Sun section has properties to change the appearance and position of the sun. Latitude controls how high in the sky the sun
appears, and Longitude changes its position around the horizon. The Angle Min/Max property changes the size of the sun and its halo,
respectively, while the Curve property controls the blending of these elements.
PanoramaSky
111111111
22222222A pale blue sky with a bright sun might be a great prototyping tool, but it will rarely fit the atmosphere of your game. When you need a custom
skybox, you can create a PanoramaSky resource for your environment sky. This type of sky takes a single image and uses it as the sky texture.
This works best with HDR panoramic images, hence the name of the resource.
NOTE
Radiance Size
A common property for both type of Sky resources is the Radiance Size. This property dictates how much of the sky affects the environment in
terms of quality. A larger value will have greater detail but will also require more of the hardware. The default of 512 is a good choice, though it
can be fine-tuned if needed.
Ambient Light
The environment can provide a default ambient light to a scene. This light is omnipresent and has no specific direction, so it does not cast a
shadow. It can be used, among other things, to create dark rooms without any lighting, yet avoiding pitch-black scenes. There are three
properties in this section:
Color: the color of the ambient light. If it’s black, there will be no light.
Energy: how much the light affects the scene.
Sky Contribution: how much the sky will contribute to the ambient light color.
Fog
A nice ambient effect is fog. This covers distant objects with a mist, improving the game’s immersive feel. There are a few interesting options
in this section of the Environment resource.
Besides being able to enable or disable the fog effect, you can also set its color. It’s usually set to a color that blends well with the sky. There’s
also an option for Sun Color, which dictates the scattering of light. This effect might need a change of angle to be visible in the scene. The
scattering can be weakened or disabled by setting the Sun Amount property.
FIGURE 18.1
The fog effect applied to a scene
The Depth property of the fog customizes how it will be affected by distance. You can set the distance where it begins and set a curve of how
much it will blend with the distance. It is also possible to add fog by set
ti
ng its related properties. Height Min and Max adjusts where the fog
starts and ends relative to the vertical axis. The height curve dictates how the blending with the environment works: a value closer to 0 will make
hard edges, while values higher than 1 will make the fog appear to be thinner.
NOTE
Light-Transmitting Fog
If you have lights in a scene, it might be interesting to turn on the Transmit Light property of the fog. This makes light permeate the fog,
improving visibility. Not only is this more realistic, it can help you guide the player to where he should go without getting lost in the mist.
Glow and Auto-Exposure
When a camera goes from a dark place to a bright one, it must adjust the exposure so the picture doesn’t get too white, and vice-versa: it
needs to increase exposure to capture the image of a darker place. The Auto Exposure properties of environments inGodot does exactly
that. It is not enabled by default, but it is readily available. It’s possible to configure how much it affects the scene (Scale), the minimum and
maximum brightness (Min/Max Luma), and the speed of transition when the ambient light changes.
The Glow property goes hand-in-hand with auto exposure. This property can make bright objects glow and can make great scene transitions
when the ambient light changes from one place to another. Here’s a breakdown of the glow properties:
Levels: enables or disables individual levels of glow. Lower levels have greater effect.
Intensity: controls how much of the effect is applied.
Strength: sets the power of the glow effect on objects.
Bloom: controls the bleeding of light around objects.
Blend Mode: controls how the glow is added to a scene.
HDR Threshold: determines the point at which the Glow property should start applying the effect.
HDR Scale: sets how the HDR is scaled to the effect.
Bicubic Upscale: enables bicubic filtering to upscale the glow, instead of bilinear filtering. This can avoid a blocky look.
Screen Space Effects
Godot has support for a couple of screen space effects: Screen Space Ambient Occlusion (SSAO), which gives the ability to compute in real
time places where shadows should form because light cannot reach those areas, and Screen Space Reflections, which calculates points
where light should be reflected. Both effects depend on point of view, because they’re based on what is on the screen.
111111111
22222222You can tweak the SSAO effect to look better in your scenes. The Radius property determines how the shadows will spread, while the
Intensity property changes how dark they will be. The Bias property acts as a threshold for the ambient occlusion to start. Color and Blur are
usually better suited for testing purposes only, because without blur, the shadows look pixelated.
TIP
Ambient Occlusion
Each material can have its own ambient occlusion set by a custom texture. This allows for a better and more precise occlusion shadow that is
independent of view. Of course, it requires more work for the artist, but it requires less work for the player’s hardware. It can also be used as a
complement to the SSAO effect on the environment.
Depth of Field Blur
A common effect of still and video cameras is how they tend to blur distant and near objects. While this is caused by how cameras and lenses
operate, it can be a very valuable effect to apply to a game scene. By blurring unrelated objects, you can guide the player to focus on a specific
point in a large ambient scene.
Godot provides depth-of-field blurring separately for near and far objects. You can selectively use one or both (or none), depending on your
needs. This effect is also set in the environment, and has the same options for both near and far objects:
Distance: where the blur should start (or finish).
Transition: the speed of the transition between an object moving from unfocused to focused.
Amount: the intensity of blur applied to unfocused elements.
Quality: the quality of the blur effect. Setting a Higher quality demands more of the hardware, but it looks better.
Adjustments
Keeping with the photographic camera analogy, sometimes you need to adjust the settings to capture a better image. Of course, “better” is
subjective, but both films and games use visuals to tell a story, and you should use the image that best conveys the message you’re trying to
communicate.
Godot’s Environment resource offers the option to add very simple adjustment settings. You can fine-tune the brightness, contrast, and
saturation of the scene, and set a custom gradient for custom color correction.
NOTE
Tone Mapping
Godot works internally with a linear color space. This means it uses raw color values instead of adjusting for how the eye perceives them. This
might sound bad, but it is actually the opposite: by using the linear space, the final image can be further processed to adjust the output curve,
showing or hiding details.
If your scene looks too dark or too bright, try playing with the environment’s tone-mapping settings. This can also be used for bright flashes in
animation.
Global Illumination
Usually, lights do not get completely absorbed by objects; instead, they bounce off objects to illuminate other places. This effect requires extra
processing inGodot to apply reflected light to other surfaces, but it pays off in terms of image quality. Another important point of global
illumination is how materials that emit light affect their surroundings.
Godot has a peculiar way of handling global illumination with the
GIProbe node. You place one (or more) nodes in the scene, set the
region it covers, and click on the
Bake button on the toolbar. That’s all you need to do. To change which objects affect the scene, you can
set the Use In Baked Light property of eachGeometry Instance (which can be
MeshInstance,
Particles, or
Sprite3D, for
example).
Baked Light
The global illumination generated by the GIProbe is prebaked; that is, the process is done in Editor, and the data is saved to be used in real
time. This ensures a higher quality and less usage of the player’s hardware. It also means that if changes are made to emissive objects in the
game, the global illumination won’t change and cause imprecision.
While moving emissive materials may cause trouble with the GIProbe, reflective materials work great. Dynamic objects are illuminated by
indirect light resulting from the bounces (see Figure 18.2).
FIGURE 18.2
A simple scene illuminated only by the light emitted from the ball in the center
Besides the extents of the GIProbe, there are a few other properties in the node:
Subdiv: sets the number of subdivisions to probe. Increasing this number will increase the quality and also the memory usage and time
it needs to bake.
Dynamic range: sets up the light’s dynamic range multiplier.
111111111
22222222Energy: determines how powerful the bounced light will be.
Propagation: determines how slowly the reflected light will degrade.
Bias: sets a threshold to determine whether the light will bounce off an object.
Normal Bias: how normal objects affect the direction of the light.
Interior: disregards the environment sky when computing illumination.
Compress: determines whether to compress the GIProbe data.
Data: sets custom preprocessed data. Can be useful when sharing data between multiple probes.
Reflection Probes
Since Godot uses the PBR workflow, materials can have multiple sources for reflections. One of these sources is the
ReflectionProbe
node. This is a special node that basically captures everything in a certain area, and the objects in that area use the probe as a reflection
source.
If the scene has multiple passages and rooms, you’ll need to set up a Reflection Probe for each one. This ensures that all reflections are
correctly applied. Godot has a nice way to blend adjacent probes without hard edges.
The probes also have a special setting for interiors. If enabled, Godot will ignore the environment sky and consider only the light sources inside
the scene. There’s a Box Projection option that is better suited for interior places, since it maps the reflection to the sides of the probe and
ensures a higher-quality reflection in closed spaces.
Extents and Origin
The main configuration of a Reflection Probe node consists of the extents and origin. The Extents property makes a box in which it will look for
reflections, and should be set to surround a room or area of your scene. Note that the extents are measured from the node’s position to its
border.
The Origin property sets up the center of the area. Usually, the default (center of the box) is ideal, but sometimes it can be over, under, or
inside an object, which will break the reflections. Set it to a place around the center of the room, where it can be seen by most objects.
TRY IT YOURSELF
Setting up Probes
Let’s try to set up a couple of probes to see how it’s done:
1. Create a new scene and add a
Spatial as the root. You can add some objects to the scene so it’s not empty.
2. Add a
GIProbe node as a child of the root.
3. You’ll see a green reticulated box in the Editor. It determines the probe’s actuation range.
4. Click on the
Move tool.
5. Move the
GIProbe around to position it away from the origin.
6. There are three circular handles, one for each axis. Move them around to make the box cover a certain area.
7. Now add a
ReflectionProbe node as a child of the root, Spatial.
8. Move it around away from the origin (see Figure 18.3).
FIGURE 18.3
A simple conference room scene shows the effect of the Global Illumination and Reflection probes.
9. Using the three handles on the box edges, change the area covered by the box.
10. In the center of the Reflection Probe box, there are three handles close together. Each of them moves the origin of the probe on
an axis.
11. Set the origin of the reflection to a different location.
Summary
This hour showed you the environmental effects of the Godot engine. You learned how to set up and tweak the World Environment for your
scene. You saw how to use global illumination to your advantage. You also learned about Reflection Probes and how they help with reflective
materials.
Q&A
Q. Do I need multiple GIProbes in a scene?
A. GIProbes doesn’t have any blending features, so using multiple probes close together isn’t advised. However, in a large scene, some
111111111
22222222small areas might have GIProbes where indirect light makes a difference.
Q. Do I need a reflection probe for reflections to work?
A. No. Reflective materials work by themselves. But Screen Space Reflections in the environment and reflection probes will enhance the
quality of reflections.
Q. What environment will be used: the one fromthe camera or the World Environment node?
A. The editor will show only the one from the World Environment. The running game or camera preview will show the one from the active
camera if it is set.
Workshop
To better grasp the concepts of this hour, try to answer the following questions.
Quiz
1. Where are the default environment settings?
2. What is the difference between
ProceduralSky and
PanoramaSky?
3. Can the environment fog be reduced in bright spots?
4. What are the two screen space effects?
5. True or False: you should set one Reflection Probe per room or passage.
Answers
1. In the file called default_env.tres, or where it is set in Project Settings.
2. Procedural Sky is generated on the fly by the engine, while Panorama Sky asks for a premade texture.
3. Yes. The Transmit Enabled property must be set for it to show.
4. Screen Space Ambient Occlusion (SSAO) and Screen Space Reflection (SSR).
5. True. Each room or passage should have its own probe for better reflection quality.
Exercises
To get yourself acquainted with environments and probes, try to execute the following exercises.
1. Create a new scene and add a
Spatial as the root node.
2. Add a
WorldEnvironment node.
3. In Inspector, click on the Environment property. On the menu that appears, select New Environment. This will create a new
Environment resource.
4. Click on the property again to edit the environment.
5. In the Background category, set the Mode property to Sky.
6. Click on the Sky property and create a new
ProceduralSky.
7. In the Tone Map category, change the settings and see how the scene changes.
8. Enable the Auto Exposure option.
9. Change the Scale and see how the scene is affected.
10. In a similar manner, change the Luma settings to see their effects.
11. Add some
MeshInstances to the scene with simple shapes and materials.
12. Try to change other environment properties and see how they affect the scene.
111111111
22222222