Using Lights
-
Prerequisite
Description
All scenes must contain some light source. If there is no light, then everything would be pitch black, just like what you see when you walk into a dark room without light.
Therefore, even the “empty” scene contains some light added for you, so it is not really empty.
Removing All Lights
If you want to change the lights in a scene, you often need to remove all the existing lights contained in the scene first. You can use this block to do that:
For example, here is what happens when you remove all the lights in the “village” scene:Removing One Light
If you just want to remove one light from the scene, you can use this block instead:
Note that you can specify the name of the light when you create it.
Ambient Lights
In most projects, you just need to have normal lights we get in broad daylight. This is called “ambient light”, which means lights surrounding us. Ambient lights are added to all scenes by default.
You can use the following block to add ambient lights to your scene:
- Color: The color of the light will be added to all objects. For example, suppose you want to create a sunset scene, then the light color should be golden:
- Main Light Direction: The ambient lights simulate how the objects around us reflect lights back to the sky. So you need to specify the direction of the sky, which is usually “x = 0, y = 0, z = 1”.
The scene will be light up in all directions, with the part facing the sky the brightness, and the side opposite to the sky darkest:
-
Intensity: the intensity value controls how bright the lights are. A value of 100 means the normal brightness. If you double that value, then the lights will double the brightness.
-
Light Name: You can name a light source and use this name to refer to the light later.
Directional Lights (Sunlight)
Sometimes you want the light to only come from one direction. For example, when lights from the Sun arrive on Earth, you can think of them as many parallel light rays going in one direction.
(image source: freepik)
You can use the following block to add a directional light to your scene:-
Color: Same as Ambient Light
-
Light Direction: The direction the light ray is pointing to, which is set to the “down direction” by default, with “x = 0, y = 0, z = 1”. Since the light is parallel, the opposite side of the object will not get any light:
-
Light Origin: You can also specify the origin point of the light source for directional lights. It will not affect the look of objects, but will be used for generating objects’ shadows.
-
Intensity: Same as Ambient Light
-
Light Name: Same as Ambient Light
Point Lights
A point light is a single point that emits light rays in all directions. Many light sources around us can be treated as point lights, such as a light bulb or a torch:
You can use the following block to add a point light to your scene:
-
Color: Same as Ambient Light
-
Light Origin: You can also specify the position of the light source, so all the lights will be emitted from this point in all directions.
-
Intensity: Same as Ambient Light
-
Show Position: Although a point light emits light rays, normally you can not see it in the scene. To help you debug your program, you can set “show position” to “yes” temporarily, which will add a small shining sphere at the light source position. Of course, even when you are not debugging, you still can show this light sphere as part of your scene.
-
Light Name: Same as Ambient Light
Demo
In this demo, 4 point lights are added to the 4 top corners of the box:
Spotlights
The forth type of light is called “spotlight”. It also emits light rays from a single point. However, just like real-life spotlights, the light rays are limited within a certain direction.
You can use the following block to add a spotlight to your scene. Note that by default, the direction of the spotlight will be the positive Y axis direction. You can rotate it to point to other directions.
-
Color: Same as Ambient Light
-
Light Origin: You can also specify the position of the light source, so all the lights will be emitted from this point.
-
Open Angle: This is the number of degrees for the emitting angle of the spotlight, which should be a value between 1 and 179.
-
Intensity: Same as Ambient Light
-
Blur: Justl like real-life lights, the further away you are from the light source, the more blurry the light becomes. You can control that effect using the “blur” parameter.
-
Show Position: When you set “show position” to “yes”, a shining cone will be added to the scene to represent the position and direction of the spotlight.
-
Light Name: Same as Ambient Light
Demo
In this demo, a spotlight is added right above the box on the Z-axis. It’s open angle is 60 degrees, and it rotates around the Z-axis.
-