Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Migrating to MRTK2: Mixed Reality Toolkit Standard Shader 'Breaks'

DZone 's Guide to

Migrating to MRTK2: Mixed Reality Toolkit Standard Shader 'Breaks'

Check out some of the common problems you might face when migrating to MRTK2.

· IoT Zone ·
Free Resource

At this moment, I am trying to learn as much as possible about the new Mixed Reality Toolkit 2 to be ready for HoloLens 2 when it comes. I opted for using a rather brutal cold turkey learning approach: I took my existing AMS HoloATC app, ripped out the ye goode olde HoloToolkit, and replaced it by the new MRTK2 — fresh from GitHub. Unsurprisingly, this breaks a lot. I am not sure if this is the intended way of migrating — it's like renovating the house by starting with bulldozering a couple of walls away. But this is the way I chose to do it, as it forces me to adhere to the new style and learn how stuff works, without compromises. It also makes it very clear where things are going to break when I do this to customer apps.

So, I am starting a series of short blog posts that basically document any bumps in the road as I encounter them, as well as how I solved them. I hope other people will benefit from this, especially as I will be showing a lot of moved cheese. And speaking of...

Help! My Standard Shader Is broken!

So, you had this nice Mixed Reality app that showed these awesome holograms:

And then, you decided to upgrade to the Mixed Reality Toolkit 2:

You did not expect to see this. This is typically the color Unity shows when a material is missing or something in the shader is thoroughly broken. And indeed, if you look at the materials:

Something, indeed, is broken.

How to Fix This

There is good news, bad news, and slightly better news.

  • The good news: It's easy to fix.
  • The bad news is: You have to do this for every material in your apps that used the 'old' HTK Standard shader
  • The slightly better news: You can do this for multiple materials in one go. Provided they are all in one folder, or you do something nifty with search

So, in your assets, select your materials:

Then, in the inspector, select the Mixed Reality Toolkit Standard Shader (again):

And boom. Everything looks like it should.

Or nearly so, because although it carries the same name, it's actually a different shader. Stuff actually might look a wee bit different. In my sample app, especially the blue, it seems to look a bit different.

So, What Happened?

If you look at what Git marks as changed, only the tree materials themselves are marked changed:

And if you look at a diff, you will see the referenced file GUID for the shader is changed. So indeed, although it carries the same name (Mixed Reality Toolkit Standard), as far as Unity is concerned, it's a different shader.

(You might want to click on the picture to be able to actually read this).

As you scroll down through the diff, you will see lots of additions too, so this is not only a different shader id, it's actually a different or new shader as well. Why they deliberately chose to break the shader ID — beats me. Maybe to make upgrading from one shader to another possible, or have both the old and the new one simultaneously work in one project, making the upgrade easier? But since they have the same name, this might also induce confusion. Whatever — but this is what causes the shader to 'break' at an upgrade, and now, you know how to fix it, too.

Conclusion

I hope to have eliminated one source of confusion today, and I wish you a lot of fun watching the //BUILD 2019 keynote.

You can find a demo project here.

  • Branch "master" shows the original project with HoloToolkit
  • Branch "broken" shows the project upgraded to MRTK2 — with broken shaders
  • Branch "fixed" shows the fixed project
Topics:
iot ,mixed reality ,mrtk2 ,standard shader ,tutorial ,breaks ,migration ,git ,mixed reality toolkit ,toolkit

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}