Skip to main content

Shaders with Deformations

For the correct rendering of skinned meshes deformed by Rukhanka, a deformation-aware shader should be created. To make this task Unity Shader Graph, Amplify Shader Editor, or Better Shaders tool can be used.

Warning

Entities.Graphics deformation shader usage is deprecated with Rukhanka Animation and its support will be removed in future releases

tip

Sample deformation-compatible shaders can be found in Rukhanka samples

Unity Shader Graph

Creating deformation-compatible shaders using Unity Shader Graph is straightforward:

  1. Create a shader graph (URP or HDRP depending on the render pipeline you are using) and open it for editing.

    Create shader graph

  2. Navigate to the Packages/Rukhanka Animation System 2/Rukhanka.Editor/ShaderGraph/ folder in the project inspector window.

    Rukhanka Deformation Subgraph Folder

  3. Add Rukhanka Deformation subgraph to the created ShaderGraph by dragging and dropping it from the project inspector.

  4. Connect position, normal, and tangent output ports of the Rukhanka Deformation node to the corresponding input ports of the master node.

    Final Shader Graph

  5. Create two shader parameters:

  • _DeformedMeshIndex with type float.

  • _DeformationParamsForMotionVectors with type Vector4.

    Make both parameters declared as Hybrid Per Instance.

    Shader Parameters

  1. Save and assign this newly created shader to the materials of skinned mesh renderers.

Amplify Shader Editor

The process of creating deformation aware shader in Amplify Shader Editor is also simple:

  1. Create Amplify Shader and open it for editing.

    Create Amplify Shader

  2. Navigate to the Packages/Rukhanka Animation System 2/Rukhanka.Editor/AmplifyShaderEditor/ folder in the project inspector window.

    Rukhanka Deformation ASE Subgraph Folder

  3. Add RukhankaMeshDeformation amplify shader function to the created shader by dragging and dropping it from the project inspector.

  4. Connect the vertex position, normal, and tangent output ports of the Rukhanka Mesh Deformation node to the corresponding input ports of the master node.

  5. Set vertex position mode of the master node to Absolute.

    Final ASE Shader

  6. Save and assign this newly created shader to the materials of skinned mesh renderers.

Better Shaders

The Better Shaders is a source-based shader generation tool. Rukhanka provides the shader snippets that can be included in your BetterShaders shader.

Navigate to the Rukhanka installation directory and copy Rukhanka.Editor/BetterShaders/StackableRukhankaDeformation.surfshader and Rukhanka.Editor/BetterShaders/StackableRukhankaDeformationMotionVectors.surfshader files to the directory with your BetterShaders shader. Use StackableRukhankaDeformation.surfshader or StackableRukhankaDeformationMotionVectors.surfshader (depending on motion vector requirements) in the first line of BEGIN_SUBSHADERS/END_SUBSHADERS block. An example of a lit shader can be as follows:

BEGIN_OPTIONS
Stackable "False"
ShaderName "BetterShaders/LitAnimated"
END_OPTIONS

BEGIN_SUBSHADERS
// Must be first line in subshader list
"StackableRukhankaDeformation.surfshader"

// Use this line instead if ENABLE_DOTS_DEFORMATION_MOTION_VECTORS script symbol is defined
//"StackableRukhankaDeformationMotionVectors.surfshader"

"Lit.surfshader"
END_SUBSHADERS

Third-Party Shaders

Rukhanka Technologies can help you adapt custom shaders to work with Rukhanka Animation. Please contact us by support email or the official Discord server.