Learn the basics of Unity Lighting

In Unity, there is a Light object, like the Directional Light that exists by default when you create a new scene, which acts as a light source to illuminate the surrounding GameObjects (hereafter simply referred to as “objects”).

This is the basic element of lighting.

However, if we try to construct a space using only light objects, it is difficult to light the entire space evenly.

HDRI is an abbreviation for “High Dynamic Range Images,” which are images that have a more defined lightness and darkness than normal images.

In this course, we will go over basic lighting using the Light object and how to easily express clean lighting using HDRI and Skybox.

The characteristics of an object, such as whether it is affected by light or casts shadows, also depend on its material (shader), but we will assume the Unity built-in Standard Shader and will not discuss other shaders.

This course will cover the basics of lighting, one by one.

What is a Light object?

In Unity, there is a Light object that can be created from the Create menu in the Hierarchy window (hereafter referred to as the Hierarchy), which acts as a light source to illuminate the surroundings.

A Light object is actually a GameObject to which a Light component is attached, and the type of Light that can be created from the Create menu also depends on the Type property of the Light component.

The characteristics of each Light object are described below.

Place them in your scene and check them out for yourself.

Types of Light

Directional Light
A large light source that illuminates the entire scene with rays of light parallel to each other coming from infinity.
In other words, you can safely assume that the lighting effect is equivalent to that of the real sun.

Point

  • There is no definite light source position on the scene, i.e., changing the Position does not affect the lighting effect, but illuminates the entire scene with the same intensity.
  • Rotation has a significant effect on lighting effects because of the direction of light rays.

Let’s rotate the Directional Light that is present in the scene by default.
Then the Skybox (sky) will be linked and become a sunset sky or dark like night (we will explain how this works later).

Let’s create another Directional Light from the Create menu in the Hierarchy and add it to the scene.
When you rotate this one, the effect of illuminating the surrounding objects changes, but the sky does not change.

Image4

Point Light

A light source that emits rays of light from a point in space in all directions.
The intensity of the light is inversely proportional to the square of the distance from the light source and is zero at the distance set by Range.

You can visually see the change in the size of the Gizmo sphere in the scene view as you change the value of Range.

Since it shoots rays of light in all directions, Point Light has a higher drawing load than other types of light.
Depending on the scene and target platform, it is best to avoid excessive use of Point Light.

Image18

Spotlight

A light source that illuminates a cone from a point in space in the positive direction of the Z axis.
When created in the Create menu of the Hierarchy, the light is rotated 90 degrees along the X axis by default, so that the ground is illuminated.

The angle of the cone can be changed with the SpotAngle property.

As with Point Light, the intensity of the light is inversely proportional to the square of the distance from the light source, and is zero at the distance set by Range.

Image80

Area Light

A light source that emits rays of light uniformly from a rectangular or circular plane.

To use Area Light, you must use Global Illumination (GI), a technique for expressing indirect light.
GI can also be used to create beautiful lighting effects such as the following.

Image89

Shadows by Light

As an effect of light, in addition to illuminating objects as in reality, light can be blocked by illuminated objects to create shadows on surrounding objects.

Image69

The following conditions are required to create shadows.

Light

Shadow Type must be other than “No Shadows

Light Note that “No Shadows” is the default when creating a new Light!

Image17

The object on which the shadow is cast (projected)

Cast Shadows in Mesh Renderer is other than “Off”.

Objects on the Receive (projected) side of the shadow

Receive Shadows in Mesh Renderer is ON

Image75

Light object placement

Let’s actually watch the effect of lighting using a simple object in Unity.

Open a Unity project and start a new scene from New Scene.

In the scene, a Directional Light is pre-populated from the beginning.

Image79

In addition, place a Cube object and a Plane object as a floor.

Place the Cube and Plane objects as shown below.

Image7
Image118

The scene will look like the following.

Image104

Let’s look at the other side where the light is shining.

Image22

The other side of the cube is in shadow and completely dark.

In the real world, the shadowed areas are slightly illuminated by reflected light, etc. If this were the case, the lighting would be too far from the real world, and we would not be able to create a beautiful scene.

The same phenomenon occurs with Point Light and Spot Light.

In the next section, we will discuss an easy solution to this problem using HDRI.

What is HDRI?

As verified in the previous section, it is difficult to express a full and bright realistic lighting in Unity by just placing Light objects.

Therefore, we use “HDRI.

The official name for HDRI is “High Dynamic Range Images”; the literal translation is High Dynamic Range Image, where dynamic range is the width (range) of values a single pixel has, given by the ratio of the highest, luminance to the lowest.

(Taken from “HDRI (High Dynamic Range Image) Glossary,” Okuda Laboratory, School of International Environmental Engineering, The University of Kitakyushu, http://vig.is.env.kitakyu-u.ac.jp/etc/hdri.html )

Compared to jpg/png, which are normal image formats, HDRI is image data with more information in dark and bright areas.

Software that deals with 3DCG uses 360-degree image data to represent ambient light and reflections.

This is called Image Based Lighting.

The method introduced here also handles this Image Based Lighting.

Download HDRI

Download HDRI.

Download images from ” Poly Haven,” which distributes HDRIs that can be used copyright-free, for commercial use, and without credit notation (CC0).

Poly Haven distributes high-quality HDRIs, textures, and 3D models under CC0.

Image53

In this case, we will download HDRIs.

Click on HDRIs in the lower left corner.

Image68

Various types of HDRIs are distributed.

Image57

Download the HDRI of your choice.

In this case, we will download the following HDRIs.

Image105

Once you are on the image page, set the items in the upper right corner.

Image39

Where it says “1K” is the resolution of the image.

In this case, we selected a 1K (1920*1080) image.

Note that the higher the resolution, the better the quality, but the larger the capacity!

Change the EXR field to HDR.

When the settings are complete, you should see the following

Image19

Select “Download” to download the HDRI.

Import into Unity

After the download is complete, drag and drop it into your Unity project and save it in the desired location.

Image97

You will not be able to use HDRI for lighting at this point.

With HDRI selected, bring up the Inspector window.

Change the Texture Shape from 2D to Cube.

Image102

After changing to Cube, select “Apply” at the bottom.

The HDRI will then change to a spherical shape.

Image23

This completes the setup.

To do Image Based Lighting with HDRI in Unity, HDRI must be used as a Skybox.

The next section describes the Skybox.

Creating a Skybox Material

A skybox is like a “background” in a Unity scene.

The default background is a monotone sky.

Image47

By changing this background from the HDRI default to HDRI and setting Image based Lighting, the entire space can be illuminated.

To set the background, the HDRI must be changed to a Skybox material.

In this case, we will use the HDRI we downloaded earlier and change it to a Skybox material.

First, let’s create a simple space by launching New Scene.

Create a Plane and a Cube from the Hierarchy window and place them as shown below.

Image114
Image42

The space will look like the image below.

Image74

Next, create a Skybox material from the HDRI that was used for the Cube map.

Right-click on the project window and create a new material by selecting Create > Material.

Image44

Name the material “HDRI_SKYBOX.

Image106

Change the Shader type.

Currently it is set to Standard, but change it to Skybox > Cubemap.

Image15
Image98

Once changed, the material will look like the following.

Image46

Drag and drop an HDRI image into the Cubemap (HDR) field.

Image16

The Skybox material is now set up.

Generating Lighting from Skybox

Next, apply the Skybox material to Skybox to generate lighting.

Generating and setting up lighting is done in the Lighting window.

Display the Lighting window.

Select Window > Rendering > Lighting Settings from the top menu.

Image113

The Lighting window will appear.

Image2

Drag and drop the HDRI_SKYBOX from the Skybox Material in the Environment.

Image54

The background of the scene view will change.

Image103

Changing the Skybox changes the background of the scene.

HDRI is now the background.

However, the lighting of the HDRI image is not applied as it is.

Click on Generate Lighting at the bottom of the Lighting window.

Image45

A window will then appear asking you to “Save Scene.

Click “Save Scene” to save the scene anywhere in the project.

Image52

Once saved, the lighting will be generated automatically.

Image110

Once the lighting generation is complete, HDRI lighting will be applied to the objects in the scene window and the objects in the scene will be brightened.

Image120

The Direction Light has caused them to become too bright.

If the Direction Light is removed, the result is as follows.

Image9

The boundaries of the surfaces are now a little more visible.

In addition, if you want to change the value of the HDRI lighting, change the value of “Intensity Multiplie” in the Lighting window.

Image107

In this case, we changed the value from 1 to 0.5. The boundary is more clearly expressed.

Image119

Let’s look at the other side.

The light is slightly shining and the color is gray instead of pitch black.

Image34

In this way, lighting can be easily expressed.

Other objects are also placed.

Image66

It is not necessarily a perfect representation of realistic lighting, but by generating lighting from HDRI, you can represent lighting closer to reality.

Introduction to Skybox Materials

In this case, we downloaded an HDRI from a website and used it as a Skybox.

However, with this HDRI, the background is too realistic and may cause a sense of discomfort when creating a game.

To avoid this, we will introduce the “Sky” HDRI / Skybox material distributed on the Asset Store.

The material introduced here is ” Skybox Series Free “.

Download and import it from the Unity Asset Store.

Image71

After downloading and importing is complete, save the material to any location in the project.

Image122

Select one of the objects with the image icon to display the inspector window.

This is one of the Skyxbox materials.

Image82

There are two main types of Skybox materials.

One type is 6 Sides with 6 images pasted on the surface.

The other is the Cubemap type, in which an HDRI image is made into a Cubemap and materialized.

Image43

Let’s use this “DayInTheClouds” in this case.

Follow the same procedure as before to generate lighting.

HDRI lighting is applied to the objects in the scene window and the objects in the scene are now brightened.

Image92

The Unity Asset Store distributes appropriate Skybox materials for creating VR scenes set in the outside world, so you can use whatever you like.

That’s all for the Skybox settings.

Next, we will explain how to use Reflection Probe.

Let’s experience the scene to be created.

Finally, to wrap up the course, let’s practice creating spatial effects using Light objects and HDRI/Skybox.

Create a scene similar to the following

Image8

Lighting Practice: https: //gallery.styly.cc/scene/0b03c2f3-a2eb-484c-9ea8-a39dd8d702cd

Create a space set indoors and use lighting to enrich the space.

Creating a space

Select New Scene to create a new scene.

Image126

Prepare six Cubes from the Hierarchy window.

Image31

Each Cube will be a wall or floor of a room.

Place them with the following names and Transforms.

Image78
Image121
Image95
Image6
Image123
Image99

They will then be arranged in a cube shape as shown in the image below.

Image117

Generating Lighting

The Direction Light, which is placed by default, is not used this time, so let’s delete it.

Next, let’s generate lighting using HDRI.

HDRI can be any data; this time we will use the “park_parking_1k” data downloaded earlier.

Display the Lighting window and apply the “Skybox_HDRI” Skybox material prepared earlier to the Skybox Material.

Image50

As in the previous step, click “Generate Lighting” at the bottom of the Lighting window to generate lighting.

Image111

The Save Scene window will appear, and you can save the scene to any name and location.

In this case, we will save the scene under the name Lighting Practice.

Image33

When lighting is generated, the entire space will be brightened.

Image20

The inside will also be brightened.

Image91

In its current state, it is too bright, resulting in a white-out effect.

The intensity of the lighting can be adjusted by adjusting the “Intensity Multiplie” value in the Environment Lighting section of the Lighting window.

In this case, the value is set to 0.3.

Image109

The overall brightness is now just right, as is the brightness of the Point Light.

Image58

We can now place objects in this space and use the lighting to create the effect.

Creating Objects

First, we create a pedestal to place the object.

Create five Cubes from the Hierarchy window, name them as shown below, and place them.

Image11
Image48
Image62
Image51
Image88

The pedestals have been placed.

Image32

Let’s place the objects.

Create a Sphere from the Hierarchy window.

Name the Sphere as follows and place it.

Image101

The object has been placed in the center.

Image72

Create a Sphere from the Hierarchy window, name it as follows and place it.

Image13

Next, place a Capsule type object.

Create four Capsules from the Hierarchy Window, name them as follows and place them.

Image3
Image12
Image26
Image100

Sub Object placement is complete.

Image93

Next, place the Wall object.

Create two Cubes from the Hierarchy Window, name them as follows and place them.

Image67
Image125

The wall objects have been placed.

Image124

Attaching Textures

Let’s add textures to each object.

Download textures from the Asset Store.

This time, we will use ” Yughues Free Architectural Materials,” which are free to use.

Image77

The Yughues Free Architectural Materials will be displayed, so download and import it.

After the download is complete, apply the material to the object.

You can use any material you like, but in this case we will apply the following.

For the floor, we will apply “Bricks weather Mat”.

Image85

The result is as shown in the image.

Image29

Skip the Main Object because we will apply a different material to it.

Apply “Gabion wall Mat” to the Pedestrial.

Image60

Apply “Bricks grey Mat” to the Sub Object.

Image112

The result is as shown in the following image.

Image55

Apply “Tiling concave Mat” to the Wall.

Image90
Image24

Finally, apply the material to the Main Object.

In this case, we will apply a material like a pearl to the Main Object.

We will apply the material from Unity’s Standard shader and adjust the texture to make it look like a pearl.

Right-click anywhere in the project window and create a Material from Create.

Name it “Pearl” and set the Metallic and Smoothness to the following values

Image116

The following is the result when applied to the Main Obejct.

Image76

Reflections have been expressed and a pearl-like appearance has been achieved.

This is because the lighting is generated by HDRI and applied to the material’s reflections.

Placing a lighting object

Since the space is dark at this point, let’s place lighting objects to create light.

First, place a Point Light to brighten the entire space.

Place it as follows

Image25

Adjust the light component.

Set Range to 40 and Render Mode to Important.

Image65

The entire space is now brightened.

Image96

Areas not illuminated by the Point Light are still dark.

Let’s adjust the overall lighting.

The Intensity Multipile in the Lighting window is set to 0.3, but you can adjust the overall lighting by adjusting this value.

Image38

Set it to 0.5.

Image108

The space is now brighter.

Image63

If the brightness of the Point Light is too strong, adjust Range and Intensity to the desired brightness.

When illuminating lights from the top of the room, as in the Point Light placed this time, it will be more realistic if the objects are placed like fluorescent lamps.

Again, we will actually place the object.

Create a Cube, name it as follows, and place it.

Image64

Apply the Emmissive material to the Cube.

Create a Standard shader material anywhere.

Name it Emmissive and place it as follows

Image61

We have placed an object that looks like a fluorescent light.

Image21

Next, we light the Sub Object with Spot Light.

Prepare four Spot Light objects and place them as follows.

Image81
Image84
Image36
Image1

Set the light component of each Spot Light as follows.

Image59

Change the color of each Point Light.

You can use any color you like, but this time, set as follows.

1 : red

2 : Blue

3 : Yellow

4 : Green

Now we can shine a colored spotlight on the Sub Object.

Image14

Next, we will illuminate the Wall Object with Spot Lights.

Create four Spot Lights, name them as follows, and place them.

Image40
Image49
Image56
Image37

The light component of each Spot Light should be as follows.

Image27

The Wall Object is now illuminated.

Image127

Finally, we will illuminate the wall with the Point Light.

Create two Point Lights and place them as follows.

Image41
Image87

Set the light component of Point Light 1 as follows

Set the color to green and the Render Mode to Important.

Image35

Set the Point Light2 light component as follows

Set the color to red and the Render Mode to Important.

Image115

All light settings are now complete.

Image86

Compared to the state where there were no lights, the color information has increased and the space has become richer.

upload to STYLY and add effects

Save your scene and upload it to STYLY.

Create a VR scene, name it Lighting Practice.

Image70

Delete all objects placed in the scene except Your Position.

Image73

Go to [ My uploads ] > [ Unity ] and place the Lighting Practice scene you just uploaded.

Image5

The scene has been placed.

Image83

You can leave the scene as it is, but you can use a STYLY asset filter to enrich the light.

Select a filter for the STYLY asset.

Image10

In this case, select Standard.

Image28

In this case, I chose PostEffect Standard.

The result is as follows.

Image30

The color saturation is increased and the light is softly expressed.

By using this Filter, you can create a variety of spatial effects.

Try it out!

Finally, publish the scene and you are done.

Image94

We have learned how to generate lighting for an entire space using HDRI and how to use lighting objects for individual lighting.

This time we learned about lighting methods that even beginners can easily use.

Let’s challenge ourselves to create rich spatial expressions by making full use of lighting.