In this blog post, we’ll learn about selective lighting using a passthrough layer. With that, we’ll be able to create an amazing mixed reality experience where the user will be able to see the real world using a virtual flashlight.
Previously, we've learned about Passthrough and how it is set up, about implementing Passthrough and we saw how to customize the passthrough layer. Later, we've also learned about surface project passthrough and selective passthrough. If you haven’t checked it out yet, we highly recommend checking it.
<div class=callout><div class="callout-emoji">💡</div><p style="margin-bottom:0px;">Note: Make sure you have a Unity project with version 39 of the Oculus Integration package imported.<p></div>
In this section, we’ll set up our scene to work with passthrough.
Now let’s create a simple flashlight model using the 3D objects. If you have a different 3D model, feel free to use it and skip to the next section.
Now let’s create a simple flashlight model using the 3D objects. If you have a different 3D model, feel free to use it and skip to the next section.
With that, we have the Flashlight model ready.
To make the Flashlight model grabbable:
Now we’ll set up those components:
Now, we should be able to grab the Flashlight but if you play the scene and try to grab it, you’ll not be able to do it. Do you know why?
If you said “it’s because we don’t have an interactor” then, you are right. We need the Grab Interactor for us to be able to grab the Flashlight. For now, we’ll enable grabbing only with the right hand.
With that, we have successfully made the Flashlight grabbable
Now we’ll add a light source to the Flashlight.
We’ll now create the lighting volume using 3D Quads and the selective passthrough material.
If you are not sure how to create a selective passthrough material, feel free to check out the ‘Creating Selective Passthrough Material’ section of this blog. However, for this case, we want to add a circular texture and also we want the passthrough material to be rendered before all other materials. To do that:
<div class=callout><div class="callout-emoji">💡</div><p style="margin-bottom:0px;">Note: The Render queue sets the priority/order of the material being rendered. The higher the number, the later it gets rendered. All the default materials have a render queue of 2000, so by setting the Render Queue of passthrough material to 1999, it will ensure that the passthrough gets rendered before all other materials are done rendering.<p></div>
We’ll create the Light Volumes using 3D quads and then add the material we just created.
Here we have two things to address, one is the gap between the Quads and the other is turning the light on and off with the press of a button. For that, we’ll write a little script which will add this functionality:
In this blog post, we saw how to make use of passthrough and lighting to create this amazing experience. You can extend this experience by adding visual effects, sound effects and even changing the color of the object when it gets detected using the flashlight.
If you've enjoyed the insights shared here, why not spread the word? Share the post with your friends and colleagues who might also find it valuable.
Your support means the world to us and helps us create more content you'll love.