Totem Teller is about discovering things alone. Explore a beautifully broken world of stories. Truth is in the Telling.

Report RSS Totem Teller: DevLog - Shader Mastery

Bringing workflow-efficient life and motion to our world via 'Master Shaders' in Unity 3D.

Posted by on

Void Path - Concept & Visuals

LOG: SHADER MASTERY

We've been working more on crafting a more responsive world -- populated with assets that react to the presence of the Teller. We wanted to do this using shaders. We realized many of our shaders did things we want (movement, color shifting, masking, distortion...), but there wasn't one that handled it all. We already had too many shader variations and it was getting unwieldy.

Tackling this resulted in some fantastic re-working of the shader code/workflow, alongside an injection of life into our forest flora assets.

shader magic


Breakdown: Building the Master Shaders

In this log, Jerry gives an overview of our new Unity 3D shader implementation.


Shaders have always been a bit of an undercooked feature in Unity. You have to write the code by hand, there’s no good syntax highlighting for it, it feels clumsy. And what about this: You have made a nice shader and an artist asks you “Hey, I need another tint color in that shader but I’m only going to need it for this one asset. Can you give me another shader with that tint color added? K Thanks!”.
After some muttered curses and a facepalm you have no choice but to reply “Sure.”.

You end up with another shader file, another slight variation. Perhaps that shader is now called “Character shader panning glow emissive masked normal boost extra tint” That’s just insane!

This exact situation has bothered me for years, especially since I’ve worked extensively with Unreal 3 and 4 where dealing with this is just a breeze.
In unreal there is the concept of a MaterialInstance, basically a shader with options. You want to enable the tint? Just check the checkbox and slap that color on there! Easy.

So now your shader can just be called “Character shader” and all those other things; panning, glow, emissive, normal boost etc. are options that can be turned on or off based on the needs of the artist. Makes sense.

Of course I would not be writing this If there wasn’t a way to do this in Unity so let’s dive right in! Fortunately, almost all of the hard work had already been done by others. Mainly Unity itself and Martin Palko.

First, lets look at Unity, in Unity 5 they introduced the Standard Shader. This shader has some dropdown options to change BlendMode and UV channel. So, not many options, but options nonetheless. That means it’s at least possible to achieve something like what we want.

Unity - Standard Shader


Time for some further investigation. All the built-in shaders can be downloaded from the Unity site to see how they function. I don’t want to go to deep into the details of it but there are two main aspects to make this work:

1. The #pragma multi_compile shader preprocessor keyword.
2. Using a CustomEditor for the shader.

Martin Palko has taken these concepts and built a system out of it that’s quite similar to that of Unreal.

Martin Palko's Shader System


In essence this is the system I wanted. However I did add some features that I felt were missing. First, I added a way to show or hide togglegroups based on the state of another togglegroup.

Show/Hide Dependency


I also integrated the concept from the Unity Standard Shader to be able to switch between different blend modes.The current blend mode can also determine if a property or togglegroup is visible or not.

Blend Mode Switching


I also changed #pragma multi_compile to #pragma shader_feature to avoid compiling an insane amount of variations. Highly recommend doing this.Docs.unity3d.com

FX Proto Area

Two caveats:
1. I wanted to set the "IgnoreBatching" tag from code but this is currently broken.
2. I wanted to have a switch for using Stencil. I don't believe it's possible to have #if blocks outside the CGPROGRAM block so I don't think this can be done.


Still, it's pretty awesome and really speeds up the workflow.

Here's some of the resulting in-game work using Master Shaders to selectively combine different effects, such as vertex animation, color shifting, scaling, distortion, secondary add/multiply layer blending, and so on) :

example use


example use


example use


example use


If you have any questions, don't hesitate to ask.

Stay up to date on Totem Teller:

Comments
DarkForestCrow
DarkForestCrow

The style of this game is awesome. And the world is already alive. Good job, keep it up.

Reply Good karma Bad karma+5 votes
benjkers Author
benjkers

Thanks - more life yet to come!

Reply Good karma+2 votes
izzyfiver
izzyfiver

Awesome

Reply Good karma Bad karma+2 votes
manofano
manofano

cool

Reply Good karma Bad karma+2 votes
Zapcade
Zapcade

What a marvel.

Reply Good karma Bad karma+2 votes
dedofrio
dedofrio

looking awesome so far! keep doing that good work

Reply Good karma Bad karma+2 votes
GrinningPickle Creator
GrinningPickle

That's the real trick of it :) We will!

Reply Good karma+2 votes
yuna-roxas
yuna-roxas

wow i love the style of the game it so beautiful :) nice work keep it up

Reply Good karma Bad karma+1 vote
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Follow Report Profile
Icon
Totem Teller
Platforms
Windows, Mac, Linux, XONE, PS4
Developer & Publisher
Grinning Pickle
Engine
Unity
Contact
Send Message
Homepage
Totemteller.com
Release date
Game watch
Follow
News
Tags
Dev Diary
Browse
News
Report
Report
Share
Related Games
Totem Teller
Totem Teller Adventure
Related Engines
Unity
Unity Commercial
Related Groups
Grinning Pickle
Grinning Pickle Developer