01 June 2016

Default HoloLens Toolkit occlusion script turns magenta

After following some on-line video’s and snooping through some other’s people code I felt I had to start bottom-up to get at least a feeling for how you setup a HoloLens app – even though I don’t have a HoloLens. Call it my natural curiosity. So I followed my fellow MVP Morten Nielsen’s blog – highly recommended – as he starts with the real basics. Very good if you hardly have a clue what you are doing ;)

In his third post, I ran into a snag. According to his second post, I had unzipped the HoloLens toolkit into the assets folder as instructed, and started to add occlusion to my project. Morten explains in detail what this is – it makes holograms disappear behind physical objects like a wall when they are ‘in front’ of the holograms (which, in reality, they never can be as they are projected on a screen not 2 inch from your eyes, but that is the magic of HoloLens).

So I added a rectangular box as a Hologram, having it stick out of a wall like halfway, so I was supposed only to see the front part. That I did, but I did also see something else:

image

Yikes – that is my box all right, but where did that horrible magenta color come from? To this moment, I still don’t know, but I found out how to fix it.

First of all, it really helps if, in addition to making the settings to your project that Morten describes in his first post, you tick at least “Unity C# project” as well in Build Settings:

image

I do the “Development Build” as well, although I don’t really know if this is neccesary).

This makes all the scripts end up in your Visual Studio solution as well, and what is more, you can debug them. Thus I learned that the script “SpatialMappingRenderer.cs” (in folder Assets\HoloToolkit\SpatialMapping\Scripts\SpatialMappingComponent) looks for materials “Occlusion” and “WireFrame” that are clearly not there.

image

If you debug this script (you can now thanks to the setting above) you will see both OcclusionMaterial and RenderingMaterial end up as null. The materials are in HoloToolkit/SpatialMapping/Materials but changing “HoloToolkit” to “HoloToolkit/SpatialMapping/Materials” does not have any effect.

So I went back to the Unity editor, selected the Spatial Mapping Renderer script again, changed the dropdown “Render mode” from “Occlusion” to “Material”, and that made the property “Render Material” pop up. I found the Occlusion Material on top of it, and it was accepted.

image

If I now debug the code, the Occlusion material is still null, but RenderingMaterial is set, and lo and behold:

image

Now I am seeing what I expect to see – a box sticking out of a wall.

Disclaimer – I am just happily stumbling along trough Unity3D and HoloLens, not hampered by much knowledge of either. I found a problem (that I maybe caused myself) and I fixed it. I hope it helps someone. If I messed up, maybe someone can enlighten me. Unlike some other people, I am not afraid to look a n00b because in this case, that’s just what I am.

The project itself can be found in a good old-fashioned ZIP file as I don’t want to clutter up my GitHub account with every little thing I try at this stage. I am still in the stage of ‘programming by changing things and observing their effects’, so I hope you will humor me. And maybe this will help someone, who knows.

4 comments:

andy mule said...

I work on hololens. That's definitely a bug in the script and not your fault. Theoretically, you can submit the bug fix to github yourself, but as a self-proclaimed noob, that's an absurd thing to expect you to do. So, I'm going to submit the fix myself now, and i'm also going to fight for a MUCH simpler feedback mechanism on the HoloToolkit. Thanks for posting this, and keep hacking!

OH, and by the way, Unity makes textures crazy pink when it fails to load. So, it's a bit of a debugging mechanic. In this case, it failed to locate the Material in the location as specified in the script (the exact bug you found). The material is somewhere else, as you found, so the fix is just pointing to the proper location, as you also found!

Joost van Schaik said...

Wow. Thank you Andy. I am not a noob *programmer* - I have been a professional developer for nearly 24 years - but I don't think at this stage of my Unity3D programming I feel comfortable enough to actually do pull request. So go ahead. Be happy to help.

andy mule said...

Already done :)

https://github.com/Microsoft/HoloToolkit-Unity/commit/1e691602d2a919e1ef3664cec68f3bec174f257f

Thanks again, looking forward to more of your posts!

Joost van Schaik said...

There will be more Andy, don't worry. What strikes me as odd is that I think I tried your fix - in fact, I specifically write so - but that did not seem to work. So I wonder what I did wrong there.