Skip to main content

Rendering Lights and Shadows in AR - The Projector Method

I talked about the problems of rendering light and shadows in AR with Unity3D and Vuforia in my previous post - Rendering Light and Shadow with Unity in AR. In the post, I also developed a method using Post-Effect to do the light and shadow rendering.

However, the Post-Effect method is doable. But since Unity can't separate an object and its shadow into a different layer. So you have to make a copy to an object if you want to render its shadow in AR. That is very problematic. The performance is bad (though I didn't test it, but it should be), and the most annoying is it mess up the Hierarchy.

So I tried to develop another method. And after several tests, I found a solution using the Projector in Unity's Standard Assets Package. And this projector method is the solution I implemented in all my A Week A Project AR series. (the Post-Effect method only use in the Paper House Demo)

This Projector method is simple. You need to build the 3D model of the environment, and create a projector which the view is exactly same as the ARCamera, and project the (smart phone's) image onto the environment.

This is a screenshot of Project Week 6 - Door


It might be confused only reading the description. So below is the setup tutorial video, with description. And there are a few notes here for you:

  1. All the custom script you need in the tutorial can be found in my Github repository - Unity Vuforia AR Tools
  2. There are different kinds of projector shader: Light, Additive, Multiply. You need a different environment color with a different shader. For example, use dark floor with additive shader, and white floor with multiply shader.
  3. The additive projector shader is not included in Unity's  Standard Assets, I googled for it. And it's included in my Github repository I mentioned.
  4. The light control and the environment color is the key to creating nice light and shadow in AR. If you use multiply projector with white floor, you will notice that the light will not rendered on it. Because white is the brightest color, can't be brighter. So you need to use gray instead. But the cons is the whole screen is a little dark though. 




Comments

Popular posts from this blog

Rendering Light and Shadow with Unity in AR

    Lights and shadows are very important. The lack of shadow will make a scene looks not real. The picture below shows the difference, you can't really tell is the man standing on the plane or floating in the air, if there is no shadow. With and without shadow makes a big difference     You can see the difference in 3D, so it definitely affect a lot in AR. This article will guide you how to render lights and shadows with Unity and Vuforia SDK. And I think the idea should also work on other SDK or game engines. Problem     In Unity, if you want to render lights or shadows, there has to be a mesh. But we add a mesh on, we can't see the camera's view. With the plane, I can't see the desk's surface     I also tried with transparent material, but the shadow can't cast on it. (at least not with Unity's standard shader, maybe some custom shader can do it) With transparent material, we see the desk's surface, but there's no shadow