James Tatum: Pizza inhaling code monkey.
Shaders allow graphics programmers and artists to make things look pretty. We love them, but only when they work. When we started looking at shaders for Sure Footing, we initially used Shader Forge, a proprietary shader building plug-in tool. Shader Forge is amazing. It provides a visual scripting-style interface for building shaders, and is exceptionally flexible and easy to use, even for a novice. But, it has it’s drawbacks. As you build more and more shaders, the performance starts to take a massive hit. They are also in no way built for mobile, and when we tried to run Sure Footing on mobile, we got around 5fps. Not great. So, my job for last few weeks (and for the foreseeable future) is to build our own shaders from scratch. They’ll do the same thing, but without the overhead of Shader Forge. To that end, let’s look at some shaders!
First, I set up a scene for me to test the shaders in. Everything in the scene is using custom made shaders, with the exception of the right hand Pete. He’s my ‘control Pete’, still using Shader Forge shaders so I can compare my work to the goal. As you can see, my Pete shader isn’t built (it’s actually pretty empty right now) so he’s the default unity pink. Mmmmm pink.
Anyway, shaders in Unity use a language called CG (C for Graphics). I both love it and hate it at the same time. I’m used to HLSL (which it shares many similarities with) but have also dabbled with GLSL when the circumstances have needed it. With that in mind, take it with a pinch of salt when I say CG is weird. The language uses a ‘Properties’ deceleration for global inputs, doesn’t use line endings for the properties and it forces range caps for floats! So weird. But, I’m starting to get the hang of it. Here’s a shader that takes a texture, a bump map, a rim colour and a rim power to produce a realistic looking lit crate.
Which now produces:
That’s all for now! In a few weeks, I’m hoping to have Pete’s shader complete, and I’ll do an in depth tutorial on what everything in his shader is doing. Until then, it’s bye from me, but you should hear from another member of the team next week! So check back then for some fun stuff.