Snippet Types


Defines a primitive shape.


Determines what happens when light hits an object.


Changes space.


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:

Example of a RaymarchModifier with a SnippetInput

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:
float3 p = float3(0, 0, 0); 
p = TransformPoint($myObjectTransform, 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:
float4 myGradientColor = tex2Dlod($gradient, float4(f, 0, 0, 0));
where f is a value from 0 to 1 along the gradient.

Using SnippetInput in Code

You can retrieve SnippetInputs in your script code and control their values programmatically.

To get SnippetInputs:

On a RaymarchObject, use GetObjectInput(inputName) or GetMaterialInput(inputName) to get the ObjectSnippet or MaterialSnippet input.

On a RaymarchModifier, use GetInput(inputName) to get the ModifierSnippet input.

On a RaymarchBlend, use GetInput(inputName) to get the BlendSnippet input.

SnippetInput Methods

CopyFrom(SnippetInput input) Copy values from another SnippetInput.
SetFloat(float value)Set the value of this "float" SnippetInput.
SetInt(int value)Set the value of this "int" SnippetInput.
SetToggle(bool value)Set the value (true or false) of this "Toggle" SnippetInput.
SetVector3(Vector3 value)Set the value of this "Vector3" SnippetInput.
SetVector4(Vector4 value)Set the value of this "Vector4" SnippetInput.
SetTexture(Texture2D texture)Set the value of this "Texture2D" SnippetInput.
SetTexture3D(Texture3D texture)Set the value of this "Texture3D" SnippetInput.
ResetReset this SnippetInput's values back to its default.