Guide: Custom Shaders
Keen Vectors is based on Shader Graph, allowing it to function on every render pipeline, and easing shader authoring for non-programmers.
Since distance fields are a very low-level primitive for graphics, the main things you need to know to work with them are:
- How to set your shader up so the asset can work with it;
- How to decode the distance field in your shader;
- The artistic properties of distance fields versus simple alpha masks;
Let's get straight to the point, with no examples or context. If you want something more on-hands, check out the Simple Morph Shader guide, it goes a bit slower and explains more context.
Using a Distance Field
- Create a Texture 2D property and take note of its Reference value;
- Create a Float property and set its Reference to
<value from previous step>_PixelRange
; - If your shader is going to be used in UGUI, connect the Pixel Range to a Pixel Range Input node;
- Connect the pixel range to a Perspective-aware Range to ensure it respects the scale it's displayed at;
- Add a Sample MSDF node and connect your Distance Field to it and the desired UV;
If you just want a mask to draw the shape as-is, use Distance to Mask on the Sharp output.
Improving the material UI
- Go to the Graph Settings page of your shader's Graph Inspector;
- Set Custom Editor GUI to one of the following:
Kroltan.Keen.Editor.SpriteMaterialEditor
: For shaders based on MSDF SpriteKroltan.Keen.Editor.DecalMaterialEditor
: For shaders based on MSDF Decal
If you want to create your own shader GUI with sections, you can inherit one of the classes above, or directly from MsdfMaterialEditorBase if they are not useful.