009rendering Lab Manual-Part II
009rendering Lab Manual-Part II
Introduction
In this lab, you will setup a simple scene in Unity for global illumination, getting familiar with lighting
rendering effect with various materials or different types of lights.
After implementing this lab, you will know how to: (bold lines are covered in Part II)
1. Set up materials for global illumination in Unity.
2. Set up Unity’s lightmapper.
3. Set up reflection probes and link custom shaders to materials
4. Set up an ambient light and customize a skybox
5. Set up common four types of lights for rendering in Unity
6. Make use of different effects among four types of light in Unity
7. Create a new scene with customized texture.
2. Light Sources
Broadly there are two types of lighting in Unity, dynamic and backed lighting. Dynamic lighting is
rendered in real-time when our game is running, while backed lighting is calculated offline and saved to
a texture. Unity supports several build-in light sources, point light, directional light, spotlight and area
light (for baked lighting only) (reference: https://docs.unity3d.com/Manual/Lighting.html). In a scene in
Unity, the whole scene’s lighting usually consists of invisible light sources (four types of lights mentioned
above), ambient light and visible emissive surfaces/objects.
Ambient light is an indirect global light illuminate the scene equally in all directions in the scene.
Emissive surfaces are a light source that behaves like indirect bounced light, for example the emissive
ceiling surface in Part I. In this Lighting Part, we will skip the emissive object as a light source, we only
focus on invisible light sources.
The following sessions, we continue the experiment with previous Cornell box and we will learn:
If you like, you can change the parameters to gain some interesting ambient lighting results (see Figure
2.1.2 and 2.1.3). You might use this setting in the future work but for now we can just make use of the
default setting “Skybox” with intensity 1.
emissive ceiling
Import new Skybox You can import Skybox materials from unity AssetStore. And under “Assets” folder
there will be a new folder (e.g. name “skyb1”) including 6-sided images. And we can rename the folder
as “Skybox”.
Create New Skybox Material Create a Material named “Skybox” for the new Skybox under “Skybox”
folder. And with “Skybox” selected in “Inspector” window, select the Shader drop-down menu and
select Skybox > 6 Sided.
Assign New Skybox Material into Scene In order to assign our new Skybox to our scene, in “Lighting”
settings window, click on the small circle to the right of the Skybox Material input field. Then, close the
selection window and the Lighting window.
A Point Light can be thought of as a point in 3D space from which light is emitted in all directions. These
are useful for creating effects like light bulbs, weapon glow or explosions where you expect light to
radiate out from an object.
The intensity of Point Lights in Unity diminishes quadratically from full intensity at the center of the
light, to zero at the limit of the light’s reach defined by the ‘Range’ property of the component in the
Inspector. Light intensity is inversely proportional to the square of the distance from the source (as
mentioned in the lecture: 𝐿 𝑖𝑛 = 𝐿 𝑖 cos 𝜃 ⁄𝑟 2). This is known as ‘inverse square law’ and is similar to how
light behaves in the real world.
Let’s create a new point light via “GameObject”→ “Light” → “Point Light” and name it “Point Light” (see
Figure 2.2.2) and you can see a new light looking like a light bulb at the center (see Figure 2.2.3).
Now change some parameters of this point light and get better lighting result. In “Inspector” window of
“Point Light” object, reset the position “XYZ” as “X: 4, Y: 4, Z: -4” (at the left top corner), and set “Range”
larger enough as “50”, rendering mode as “Baked”, and select “Soft Shadows” as “Shadow Type” ”(see
Figure 2.2.4). And now you can see the rendered result with one point light (see Figure 2.2.5) and
ambient light.
Now you can try rotating (use the rotate tool or manually change the “Rotation” value in “Inspector”
window) the point light and we can find that the rendered results will never change (see Figure 2.2.6).
That’s because the point light illuminates the scene in all directions with equal intensity.
Now let’s create a new directional light or just change the “Type” of the light object “Point Light” to
“Directional” and name it “Directional Light” (see Figure 2.3.1).
Let’s change some settings, set “Rotation” to “X: 50, Y: 50, Z:0”, “Shadow Type” as “Soft Shadow” (see
Figure 2.3.2). “Mode” can be “Realtime” or “Mixed”.
Figure 2.3.3 Rendered results with directional light with different positions
And we can change the “Rotation” values (use Rotate Tool or manually change the values) to make the
light have different directions and see the results (see Figure 2.3.4).
Figure 2.3.3 Rendered results with directional light with different directions
Distance from the directional lights to the objects never affects the directional lighting, but directions
will influence the result to a large extent.
2.4. Spotlight
Spotlights project a cone of light in their forward direction. The width of this cone is defined by the
light’s ‘Spot Angle’ parameter. Light will “falloff” from the source position towards the extent of the
light’s range, where it will eventually diminish to zero. Light also diminishes at the edges of the
Spotlight’s cone. Widening the Spot Angle increases the width of the cone and with it, increases the size
of this fade. Spotlights are generally used for artificial light sources such as flashlights, car headlights and
searchlights. With the direction controlled from a script or animation, a moving spotlight will illuminate
just a small area of the scene and create dramatic lighting effects.
Likewise, we can find spotlight under “GameObject”→ “Light” → “Spotlight” or directly change the light
type to “Spot” and name the light “Spot Light” (see Figure 2.4.1).
Figure 2.4.1 Create a spotlight
Let’s change the settings of the spotlight. Set “Position” with values “X: 0, Y: 4, Z: 0”, “Rotation” as “X:
90, Y:0, Z: 0”, “Range” as “20”, “Spot Area” as “50”, “Mode” as “Baked”, “Intensity” as “5”, “Shadow
Type” as “Soft Shadow” (see Figure 2.4.2).
We can also try other parameters, for instance, we can change the light color to violet (see Figure 2.4.3).
Figure 2.4.3 Colored spotlight
Now we can feel free the change the position or rotation of the spotlight, and we can know both
position and direction will affect the rendered results with spotlight (see Figure 2.4.4).
Figure 2.4.4 Rendered results with spotlight with different directions and positions
Since the lighting calculation is quite processor-intensive, area lights are not available at runtime and
can only be baked into lightmaps.
We can find spotlight under “GameObject”→ “Light” → “Area Light” or directly change the light type to
“Area (baked only)” and name the light “Area Light” (see Figure 2.5.1).
Figure 2.5.1 Create an area light
Now change the “Position” to “X:1, Y:-3, Z:5” and “Rotation” to “X:180, Y:30, Z:0”, and increase the
“Intensity” to “5” and “Indirect Multiplier” to “3” (see Figure 2.5.2). When there is only one area light,
the brightness is relatively weak. We can see that the light merely emit to one side (forward side) in all
directions.
Let’s add two more area lights and make all three area lights with intensity of 3 and indirect multiplier 1.
We can just duplicate the “Area Light” from the “Hierarchy” window. And rename all lights “Area Light
1”, “Area Light 2” and “Area Light 3”. And change their colors blue, pink, and orange, and their positions
to “X:1, Y:-3, Z:5”, “X:1, Y:0, Z:5”, “X:1, Y:3, Z:5” in respectively. And you can see a mysterious result (see
Figure 2.5.3).
Figure 2.5.3 Rendered result with three area lights
If we freely change the positions or rotations of our area light, we will easily find the result change
accordingly. Both position and direction of an area light influence the rendering result.
2) Adjust the “Range”, “Position” and “Rotation” of point light, and get different rendering. Try to
explain how these parameters affect or do not affect the lighting results.
3) Adjust the “Position” and “Rotation” of directional light, and get different rendering. Try to explain
how these parameters affect or do not affect the lighting results.
4) Adjust the “Range”, “Spot Angle”, “Position” and “Rotation” of spotlight, and get different rendering
results. Try to explain how these parameters affect or do not affect the lighting results.
5) Adjust the “Position” and “Rotation” of area lights with proper Intensity and Indirect Multiplier, and
get different rendering results. Try to explain how these parameters affect or do not affect the lighting
results.
3. Texture Mapping
In Unity, textures are bitmap images. A material can contain references to textures, so that the
material’s shader can use the textures while calculating the surface color of a GameObject. In addition
to basic color (Albedo) of a GameObject’s surface, textures can represent many other aspects of a
material’s surface such as its reflectivity or roughness.
This part won’t introduce all types of textures in Unity, but will make use of the texture mapping in Unity
to create our realistic scene combined with proper lighting.
This part we will build a simple indoor basketball court, we have provided the basic scene with planes
and cubes as walls, floor and doors for convenient use (the Scene “Basketball Court”). Open the
“Basketball Court” scene (see Figure 3.1.1), and import the prepared textures and normal maps.
Set up texture materials Create a material with “Standard” shader and name it “Floor”. From “Asset”
window, drag Texture “basketball_court_texture” to the left quad of “Albedo”. And Now the Material
“Floor” owns the texture of the floor of basketball court (see Figure 3.1.3).
Figure 3.1.3 Create a new material for court floor
Attach normal map to texture For the wall and the door, we can attach a normal map for their texture
respectively. We have prepared both the wall and door texture image and normal maps. Create a
material with standard shader, name it “Door”, drag “door_wood_texture” to “Albedo” and drag
“door_wood_normal” to “Normal Map” in the “Inspector” window. You can now preview the texture in
the bottom of the “Inspector” window and see the roughness of the surface (see Figure 3.1.4).
Likewise, we can create a new material named “Wall” with “Albedo” using “wall_texture”, and “Normal
Map” using “wall_normal” (see Figure 3.1.5).
Figure 3.1.5 Create a new material for walls
Assign texture material to objects Now let’s drag the texture materials “Floor”, “Wall” to the floor and
4 walls correspondingly. In the next section “UV Mapping” we will create cubes as a door, and do the UV
mapping for more detailed and accurate texture mapping.
3.2. UV Mapping
Download ProBuilder To model objects or texture objects by UVs in Unity, we need to download
ProBuilder first, and we can download it from Asset Store for free. After we downloaded, we can just
import the package and you will see the ProCore folder in the project (see Figure 3.2.1).
Create cuboid We can click “New Shape” and create a cuboid by 2 x 4 cubes (see Figure 3.2.3). And we
name this object “Left Door”. Likewise we can duplicate it as “Right Door”.
Now let’s scale the doors into a suitable size and move them to the wall (see Figure 3.2.4).
Figure 3.2.4 Resize and place the doors
UV Mapping Drag the “Door” texture material to the doors and we get abnormal texturing results (see
Figure 3.2.5). This is not what we want to have.
To tweak the UV mapping, we should open the “UV Editor” in “ProBuilder” window. And we can see the
UV Editor with some lines and our texture image (see Figure 3.2.6). The lines or surfaces are
corresponding lines or surfaces in the object (see Figure 3.2.7).
How can we operate the UV surfaces? There are some Unity editor similar tools for us to use (see Figure
3.2.8).
Scale Tool
We can directly change the UV mapping by moving, rotating or scaling the vertices, edges or surfaces in
the object, until the mapping is exactly correct according to the texture image. For example, we can
move and scale the front surface of the door exactly suit the texture central component. And the 3D
object will accordingly change the texture mapping as well (see Figure 3.2.9).
And we can get a good texture mapping result, no matter front/back, top/bottom, left/right sides (see
Figure 3.2.11).
Something need noticing is that when the texture is flipped, we can directly flip U or V coordinate of the
UV surface (see Figure 3.2.12).
Figure 3.2.12 Flip UV
Get rendered results Likewise, we can tweak the texture mapping in the same way for another door.
After setting up the lighting, we can finally have the door like this. You can see with the normal map, the
texture on the surface is rough due to the normal map (see Figure 3.2.13). And we can check the overall
rendered scene (see Figure 3.2.14).
2) You are supposed to customize the Skybox Material with different background images. You can
download preferred skybox from http://www.custommapmakers.org/skyboxes.php for use and refer to
https://docs.unity3d.com/Manual/HOWTO-UseSkybox.html for more details.
3) Extra: you can import your own 3d model to Unity (drag and drop model file into the “Assets”
window, then drag to the scene) from Rhino or Blender or any preferred external 3D modelling program
of your choice. Set up the material, texture mapping and lighting settings, and then take a
screenshot/video of the final result. The results can be as innovative as possible, e.g. add some
animation to the model. You can refer to the previous lab “Human Model MOCAP Animation” for more
information.