Snippets
Snippet Types
ObjectSnippet
Defines a primitive shape.
MaterialSnippet
Determines what happens when light hits an object.
ModifierSnippet
Changes space.
BlendSnippet
Blends object primitives together.
Snippet Inputs
When writing snippet code, you use HLSL like usual in Unity, with one exception. For variables you want to expose as knobs in the editor for easy tweaking, you can use the “SnippetInput” syntax, which is just a normal variable name prefixed with a dollar sign:
float myVal = someOtherVal * $intensity;
The $intensity
variable will be exposed as an “input” that appears anytime you use this snippet. This lets you easily tweak the value from the inspector for your object. For example, in a modifier:
SnippetInput Types
float | A floating point value. |
Vector2 | A Vector of two floating point values. |
Vector3 | A Vector of three floating point values. |
Vector4 | A Vector of four floating point values. |
Toggle |
A boolean value passed as a float 1 or 0.
|
Axis |
Lets you choose X, Y, or Z, and is passed to your shader as float3(1, 0, 0) , float3(0, 1, 0) , or float3(0, 0, 1) respectively.
|
Transform |
A link to a Transform in your scene. You can't set a default from the snippet editor, but in the actual object in your Hierarchy Window you can link up to another Transform. It is passed as a float4x4 matrix to your shader. To use it inside a snippet use the TransformPoint function to modify p:
|
Gradient |
A gradient between two or more colors. Uses the built-in Unity Gradient editor. Your gradient is automatically sampled and turned into a 1 pixel high texture and passed to the shader. To use it inside a snippet, try something like: where f is a value from 0 to 1 along the gradient.
|