From the archive

HoloLens Tutorial – Occlusion

Last Updated: Jun 4, 2017

Tutorial Accomplishments
  1. Add occlusion to the scene
  2. Fix Voice command to swap between grid and occlusion
  Every time I show this demo to people I highlight the problems that are caused by not having the real world occlude your holograms.  The picture above shows an example of this problem, can you tell which sphere is covered by the wall and which isn't? Although it appears that the one on the right should be occluded, they both should be. This tutorial shows how to fix this.   Occlusion for Spatial Understanding This became very easy to accomplish due to PR#663 on the HoloToolkit done by Rafał Legiędź. Take a look at the code changes here: https://github.com/Microsoft/HoloToolkit-Unity/pull/663/commits/22d1d94b54d64e19fcfbf3e157990eefb04b8f99 These changes allow the Material to be updated while spatial understanding is running.  This allows us to switch the material to the any other material and have the surface update in real time. Open ObjectPlacer.cs in Visual studio and change this method to have the following code: https://gist.github.com/CameronVetter/64e4389b3b847b77020d96cd51afa3b5 Open your scene in Unity and Select Placement in the Hierarchy.  Set Occluded Material in Object Placer to the Material "Occlusion".  The properties should look like this: That's it! Build and Deploy the project.  Notice that after spatial understanding is complete and the world is generated there is now occlusion with the  real world.  Stand behind a real world object that blocks your view of a hologram.  Try having a hologram partially blocked. This seems like it totally solves the problem, but be warned, this level of occlusion highlights every flaw in your spatial mesh, so use this technique carefully.     Updating our Voice Command In a previous tutorial we created a  voice command that looked like this:   Due to the addition of occlusion this no longer works, lets correct the "Toggle" command to only work after we have finalized the spatial mesh and to swap between occlusion and the grid visualizing the spatial mesh.  Edit the Speech.cs file to look like this:   https://gist.github.com/CameronVetter/ad091666bc3d5ab52285f902e68c7e07 On Start we store a copy of the Spatial Understanding Mesh Material which is the standard Spatial Understanding Grid.  When the voice command for toggle is received we first make sure that spatial understanding is completed before we do anything.  If it is complete we swap the currently displayed material for the material we have stored.  This allows us to toggle between the occluded material and the grid. Build and Deploy the application. You should be to speak the word "Toggle" after you have finalized the spatial mesh to switch between the grid and occlusion.     Tutorial Index [rps-include post=186]

Originally published June 4, 2017. Preserved from the legacy CameronVetter.com archive.

← Browse archive