Light and Shadow
Lighting
Adding a Light Source
All templates come with a default light source in the scene. To create a new light source, first click the +
button in the Scene Hierarchy
panel and then select Light
from the drop down menu.
Types of Light Sources
The following types of light sources are available in Lens Studio.
Point
The Point Light is an omnidirectional light source that can be positioned anywhere in the scene.
Color | The color of the light source |
Intensity | The intensity of the light source |
Layers | This light source will only act on objects in the selected render layers |
You can specify a scene object's render layer or choose the set of render layers that a camera will render. Read more about render layers here.
Directional
The Directional Light simulates an infinitely far away light source emitting in a configurable direction. You can use directional light to simulate sunlight in the scene. To change the direction of the directional light emission, rotate the light object. To cast real-time shadows in your scene, use a Directional Light.
Color | The color of the light source |
Intensity | The intensity of the light source |
Shadows | When enabled, this light will cast real-time shadows from any Mesh Visuals with a Shadow Mode of "Caster" |
Auto Position | Available when Shadows is enabled. If enabled, the light will use its rotation to automatically drive its position to optimally cast the shadows of all Shadow Casters in the scene |
Auto Frustum Size | Available when Auto Position is enabled. If enabled, the light will adjust its frustum size to optimally cast the shadows of all Shadow Casters in the scene |
Frustum Size | Available when Shadows is enabled. The size of the light's frustum |
Frustum Far | Available when Shadows is enabled. The far plane of the light's frustum |
Frustum Near | Available when Shadows is enabled. The near plane of the light's frustum |
Shadow Density | Controls the shadow density on all shadows cast by this Light Source |
Layers | This light source will only act on objects in the selected render layers |
Real-time shadows can only be casted by Directional Lights.
Ambient
Ambient light illuminates all objects in the scene equally and globally.
Color | The color of the light source |
Intensity | The intensity of the light source |
Layers | This light source will only act on objects in the selected render layers |
EnvMap
EnvMap light uses an environment map to illuminate all objects in the scene.
Diffuse Envmap | You can generate env map by using + -> Environment Map in the Asset Browser panel |
Specular Envmap | You can generate env map by using + -> Environment Map in the Asset Browser panel |
Exposure | The exposure of the Environment Map |
Rotation | Controls the rotation of the Environment Map |
Layers | This light source will only act on objects in the selected render layers |
You can also add your own custom Environment Map by dragging and dropping a .hdr
into the Asset Browser
panel. Or alternatively, by select + -> + From Files
in the Asset Browser
panel and selecting a .hdr
from your computer. Once added, the diffuse and specular environment textures will be created for you which you can then plug into your EnvMap light.
Shadow
Adding the Directional Light
To add a real time shadow to your Lens Studio project, first add a directional light and check the Shadows
checkbox. You can only have one directional light casting shadows in a scene.
For the best result, change your directional light rotation to point in the direction you want it to cast shadows. Then, check both the Auto Position
and Auto Frust. Size
checkboxes to let Lens Studio automatically set the best values for the shadow.
For more information about the Light Source
component in Lens Studio, visit the LightSource API.
Configuring your Mesh
Next, select the SceneObject that you want to cast a shadow. In the Inspector
panel find the Mesh Visual
component and set the Shadow Mode
drop down to Caster
. You can further adjust the shadow intensity of this object using the Shadow Density
slider.
The intensity of the shadow can be tuned globally by changing the Shadow Density
of the Directional Light Source, which sets the maximum shadow density globally. Adjust the individual shadow density of one object only when you want to specifically set this object's shadow density.
Adding the Shadow Plane
Finally, you must create a ground plane to receive the real time shadow. To create the shadow plane, follow the steps below:
- In the
Scene Hierarchy
panel, click the+
button and from the drop down menu selectMesh Visuals -> Shadow Plane
- Make sure your object has Caster selected in its Shadow Mode.
- Make sure the Shadow Plane has Matte Shadow material attached, and set as Receiver in Shadow Mode, these should be set by default.
- Make sure the Directional Light has Shadows enabled, and its Layers is set as the same as your object and Shadow Plane's layer.
You only need one shadow plane in a project if it is big enough to cover all objects casting shadow in the scene.
Make sure your shadow plane is at ground level, below the object.
Add Shadow For 2D Assets
You can add shadow for 2D assets that have a hard cut-out outline. Add a plane mesh and clear its rotation so that it faces the camera. Create an Unlit Material and change its Blend Mode to Normal to enable transparency of your 2D asset.
Apply the material to your plane mesh. Enable the shadow mode and set it to Caster
as described above. You are not limited to still images. You can cast shadow in this way for animated 2D textures.
Below is a list of things to ensure when working with lights and shadow in Lens Studio:
• Your scene total lights count should add up to less than 8 Lights
in a scene
• You can only have one directional light casting shadows
• If you want to learn more about optimizing your scene, follow the Performance and Optimization guide