0% found this document useful (0 votes)
45 views25 pages

009rendering Lab Manual-Part II

This document discusses setting up lighting in Unity. It covers adding ambient lighting by customizing the skybox and adjusting lighting settings. It also covers the four main types of lights in Unity: point lights, directional lights, spotlights, and area lights. For each light type, the document demonstrates how to create the light, adjust its parameters, and shows the different rendering effects that can be achieved.

Uploaded by

iimsheung
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views25 pages

009rendering Lab Manual-Part II

This document discusses setting up lighting in Unity. It covers adding ambient lighting by customizing the skybox and adjusting lighting settings. It also covers the four main types of lights in Unity: point lights, directional lights, spotlights, and area lights. For each light type, the document demonstrates how to create the light, adjust its parameters, and shows the different rendering effects that can be achieved.

Uploaded by

iimsheung
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

ISDN 2300 - Rendering Lab 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:

- how to set up an ambient light


- how to set up common four types of lights for rendering in Unity
- the different effects among four types of light in Unity

2.1. Ambient Light


Each scene has default value for ambient light. Ambient light illuminates all surfaces in the scene.

2.1.1 Ambient Light


Ambient light is controlled by the settings in the lighting panel in “Environment Lighting” tab. The
ambient light can be created by using different sources, “Skybox” (default), “Gradient” with 3 colors, or
a single “Color” (see Figure 2.1.1).

Figure 2.1.1.1 Ambient light settings

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

Figure 2.1.1.2 Lower intensity/brightness of skybox lighting


Figure 2.1.1.3 Set 3 colors for gradient ambient lighting

2.1.2 Skybox Customization


We can also change the default skybox to customized background.

Perform the following steps to create a Skybox:

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”.

Figure 2.1.2.1 Import Skybox images from AssetStore


Or create a “Skybox” subfolder in the Assets folder which stores our textures and materials for the
Skybox. You can customize or download other skybox images from here and drag your own six Skybox
images into the new “Skybox” folder.

Figure 2.1.2.2 Import customized Skybox images

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.

Figure 2.1.2.3 Create a material for skybox


Assign 6-sided Images Use the “Select” button for each of the six images and navigate to the images. Be
sure to match the appropriate texture to the appropriate cube face. For example, the front texture
matches the “Front[+Z]” cube face on the Skybox Material.

Figure 2.1.2.4 Assign 6-sided images to skybox material

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.

Figure 2.1.2.5 Change environment Skybox material


Figure 2.1.2.6 Final results of different Skybox Materials

2.2. Point Light


In the following exploration of different types of light source, to have a better effect and see the
difference, let’s change the ceiling light “Plane Light” object back to a non-emissive plane (see Figure
2.2.1).
Figure 2.2.1 Attach a default material to ceiling block “Plane Light”

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).

Figure 2.2.2 Create a new point light


Figure 2.2.3 Bulb-like point light

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.

Figure 2.2.4 Settings of point light


Figure 2.2.5 Rendered result of one point light only

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.

Figure 2.2.6 Directions/angles will not affect the point lighting

2.3. Directional Light


Directional lights are very useful for creating effects such as sunlight in your scenes. Behaving in many
ways like the sun, directional lights can be thought of as distant light sources which exist infinitely far
away. A directional light does not have any identifiable source position and so the light object can be
placed anywhere in the scene. All objects in the scene are illuminated as if the light is always from the
same direction. The distance of the light from the target object is not defined and so the light does not
diminish.

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).

Figure 2.3.1 Create a new directional light with default rotation

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.2 Rendered result with directional light


Let’s move (use Move Tool or manually change the value of “Position”) the light object anywhere as you
like and we will find that the rendered results are all the same (see Figure 2.3.3). And the wall cannot
occlude the light.

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).

Figure 2.4.2 Rendered effect with a spotlight

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

2.5. Area Light (Backed Lighting Only)


Area Lights can be thought of as similar to a photographer’s softbox. Light is emitted in all directions
uniformly across their surface area, but only from one side of the rectangle. There is no manual control
for the range of an Area Light, however intensity will diminish at inverse square of the distance as it
travels away from the source.

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.

Figure 2.5.2 Rendered result with an area light

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.4. Practice Details


1) Adjust the “Skybox” intensity of ambient lighting, change “Skybox” material and compare rendering
results.

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.

After this part, you will know:

- how to attach normal map to the texture


- how to use UV mapping to map 2D texture to 3D model
- how to create a scene with textures

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.

Figure 3.1.1 Open the basketball scene

3.1. Create Texture with Normal Map


Set configurations for texture images and normal maps For texture base image, we can set the
texture type as “Sprite (2D and UI)” in this case. For normal maps, we set its type as “Normal Map”. And
click the “Apply” button (see Figure 3.1.2). If you are interested in texture types in Unity, please check
more details at https://docs.unity3d.com/Manual/TextureTypes.html.
Figure 3.1.2 Set configurations of 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).

Figure 3.1.4 Create a new material for door

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).

Figure 3.2.1 Download “ProBuilder”


Open ProBuilder Window Now we can open the ProBuilder Window under “Tools” → “ProBuilder” →
“ProBuilderWindow” (see Figure 3.2.2).

Figure 3.2.2 Open “ProBuilder” window

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”.

Figure 3.2.3 Create a door cuboid

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.

Figure 3.2.5 Wrong texture mapping

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).

Figure 3.2.6 Open UV Editor


Figure 3.2.7 (Left)corresponding front surface and (right) right side surface

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

View Tool Surface Selection

Move Tool Rotate Tool Vertex Selection Edge Selection


Figure 3.2.8 Tools in UV Editor

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).

Figure 3.2.9 Move UV and change the texture mapping


Another way is to use the Photoshop or other image editor to change the layout the texture image such
that fitting the layout in UVs and import the texture again. This method is not covered in this tutorial.

The final mapping should be like this (see Figure 3.2.10).

Figure 3.2.10 Matched UV mapping

And we can get a good texture mapping result, no matter front/back, top/bottom, left/right sides (see
Figure 3.2.11).

Figure 3.2.11 UV mapping result after correction

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).

Figure 3.2.13 Rendered result of doors with UV mapping (close-up shot)


Figure 3.2.14 Overall scene (long shot)

3.3. Report Details


1) Change the textures of the scene and produce a creative indoor/outdoor scene for rendering. You can
get some textures from https://3dtextures.me/ or use your customized images. Manipulate the camera
and get at least a long shot (a.k.a. wide shot, including all objects in the scene) and 2 close-up shots for
each object from different shooting angles with appropriate lighting settings and texture details. And
explain how you set the material, texture, lighting configurations to get the results.

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.

3) Any plagiarism is not allowed.

You might also like