Unity Toon Shader (UTS3)

repository·master·Indexed 23 days ago

https://github.com/unity-technologies/com.unity.toonshader

A professional-grade shading solution for cel-shaded 3D-CG animations, providing fine-grained control over color design and shading steps across all major Unity render pipelines. The package includes support for Entities Graphics, URP Lit material property overrides, Shader Graph integration, and lightprobe/lightmap support for Entities.

Tokens
16.8K
Snippets
8
Records
120
Agent score
80%

What's inside Unity Toon Shader

  1. Overview of Unity Toon Shader (UTS3)

    master

    The Unity Toon Shader (UTS3) is a specialized set of shaders designed for cel-shaded 3D-CG animation. It allows creators to implement detailed color designs by specifying colors for light and shadow areas independently of the actual scene light colors. This is achieved through a system of three basic colors: base color, 1st shading color, and 2nd shading color.

    Key features include:

    • Color Control: Apply specific colors for highlights and multiple shading steps.
    • Advanced Effects: Support for Highlight, Rim Light, Emission, Angel Ring, Material Capture (MatCap), and Outlines.
    • Pipeline Agnostic: Works across multiple render pipelines with varying feature sets.
  2. Format property files for the Shader Generator

    master

    Property files (ending in .shaderblock) are plain text files containing only ShaderLab property declarations. They do not require a Shader wrapper. You can include comments and blank lines, which the generator will preserve and indent correctly into the target shaders.

    Example of valid content for a .shaderblock file:

    // Comments are preserved
    [HideInInspector] _simpleUI ("SimpleUI", Int ) = 0
    [Enum(OFF, 0, ON, 1)] _isUnityToonshader("Material is touched by Unity Toon Shader", Int) = 1
    _BaseColor ("BaseColor", Color) = (1,1,1,1)
  3. Check Render Pipeline compatibility for Unity Toon Shader

    master

    Unity Toon Shader is compatible with the following render pipelines:

    • Built-in Render Pipeline
    • Universal Render Pipeline (URP)
    • High Definition Render Pipeline (HDRP)

    2D Project Support

    Starting with Unity 6.3, UTS partially supports URP in 2D projects by allowing the rendering of 3D GameObjects within 2D URP scenes.

    Important Notes

    • Feature Availability: Not all features are available across all pipelines. You must check the Feature Difference documentation to confirm support for your specific pipeline and project type (3D vs 2D).
    • Color Space: The use of linear color space is strongly recommended for optimal results.
  4. Use Normal Map Specular Mask for MatCap

    master

    When Normal Map Specular Mask for MatCap is enabled, the shader uses a dedicated normal map for the MatCap projection. This is particularly useful when using MatCap as specular lighting, as the normal map acts as a specular mask to add fine detail (like individual hair strands) to the highlights.

    Available sub-settings:

    • Normal Map: The texture defining the bumpiness/detail for the MatCap.
    • Rotate Normal Map UV: Rotates the MatCap normal map UV based on its center.
  5. Use Shadow Control Maps for Fixed Shadows

    master

    Shadow Control Maps are used to dictate fixed shadows on a material using UV coordinates. Unlike dynamic lighting shadows, these are defined by textures.

    1st Shading Position Map

    Specifies where the 1st shade color areas should appear.

    • Format: Texture(linear)

    2nd Shading Position Map

    Specifies where the 2nd shade color areas should appear.

    • Format: Texture(linear)

    To apply fixed shadows, assign a grayscale texture (where black/white values dictate shadow placement) to these properties in the Inspector.

  6. Handle transparent entity ordering in Entities Graphics

    master

    When working with semi-transparent entities in a DOTS/Entities environment, correct rendering requires a back-to-front draw order. The Entities Graphics package automates this by using the DepthSorted_Tag tag component.

    When an Entity is baked with a transparent Material, the DepthSorted_Tag component is automatically added to that Entity. This tag enables the Entities Graphics system to perform the necessary depth sorting for correct transparency results.

  7. Understand Mesh Deformation methods in the sample

    master

    The sample scene visualizes three different deformation methods using color coding:

    • Red meshes: Deformed using blend shapes only.
    • Blue meshes: Deformed using skinning only.
    • Purple meshes: Both blend shapes and skinning applied to the same mesh.

    All values and transforms are animated via a simple animation system that writes to ECS transform components. The Mesh Deformation system then uses these components to calculate the skin matrices.

  8. Configure MatCap (Material Capture) settings

    master

    MatCap (Material Capture) is a lighting technique that uses pre-rendered sphere images to simulate material and light expressions. Use these settings to control how specular highlights and material properties are projected onto your mesh.

    Key configuration areas include:

    • MatCap Map: The primary texture used for the effect.
    • MatCap Blur Level: Controls the sharpness of the MatCap using Mip Maps.
    • Color Blending Mode: Determines how the MatCap color interacts with the surface (Multiply or Add).
    • MatCap Mask: Uses a texture aligned with the mesh's UVs to define where the MatCap is visible (black regions are hidden).
    • MatCap Camera Mode: Controls rendering behavior based on the camera type.