Lighting and Rendering

In this tutorial, you will learn how to illuminate the real world with virtual lights, and cast shadows on it from virtual objects.

We will use the project created in the previous tutorial Build your first MR App.

Add ZED Rig Prefab

  • In the Hierarchy, click on Camera_Left.

    Hierarchy camera

  • In the Inspector panel, select your Rendering Path (Deferred or Forward). See below for details on how each will affect your scene.

    Inspector camera

  • Right-click the ZED_Rig_Prefab object in the Hierarchy panel, select Light > Spotlight. You should see the spotlight pointing in the same direction as the camera in the Scene window.

  • With the spotlight selected, click on the white box beside Color in the Inspector window. This will open up a color wheel. Change the color to something bright and distinct, like red.

  • Select the sphere you added in the last section. In the Transform section of the Inspector, set its position to X = 0, Y = 0 and Z = 2.

Note: Only directional lights can cast shadows. Keep this in mind when setting the angle of your scene’s directional light, and make sure your scene has at least one if you want shadows.

If you choose Deferred Rendering, your scene is ready to go. If you choose Forward, you must follow one more step.

Forward Rendering

Forward is the traditional rendering path. Using the Forward rendering path provides increased performance, and currently, you will need to choose Forward rendering if you plan on using a green screen. However, you are limited to 8 lights at a time that will affect the real world, and must attach a script to each of them.

Select each light you want to use to illuminate the real world, and add a script called ZEDLight to them.

Lights

Deferred Rendering

In deferred rendering, you do not need to add any scripts to your lights. The ZED plugin has its own custom deferred lighting pass that handles mixed-reality lighting. However, this path is less performant and will not allow you to use the plugin’s green screen component.

If you chose the Deferred rendering path, you can now run your scene. You’ll see colored light on both the sphere and the real world behind it, and the sphere will cast shadows on the floor if you added a Direction Light to the scene. You can play with the Range and Intensity values on the spotlight to make it stronger.