### HDRP Box Light Adjustment Component Setup Source: https://context7.com/unity-technologies/com.unity.toonshader/llms.txt This C# code provides the structure for the BoxLightAdjustment component. It requires a Light component and links renderers to a specific Box Light, optionally following a target GameObject. Setup involves creating a Spot Light with a Box shape, adding the component, assigning targets and the HDAdditionalLightData reference, and enabling follow options if needed. ```csharp using UnityEngine; #if UNITY_EDITOR using UnityEditor; #endif // Box Light Adjustment is an HDRP-only feature // Add component via: GameObject > Toon Shader > Box Light Adjustment // The BoxLightAdjustment component: // - Requires a Light component on the same GameObject // - Links renderers to a specific Box Light // - Optionally follows target GameObject position/rotation // Setup in Editor: // 1. Create a Spot Light with Shape set to "Box" // 2. Add BoxLightAdjustment component to the light // 3. Assign target GameObjects (character meshes) // 4. Assign the HDAdditionalLightData reference // 5. Enable "Follow GameObject Position/Rotation" if needed // The component automatically: // - Applies light layer masks to all child renderers // - Maintains position/rotation offsets relative to target // - Works with HDRP's light layering system ``` -------------------------------- ### Complete Character Setup Script Source: https://context7.com/unity-technologies/com.unity.toonshader/llms.txt Use this C# script to programmatically configure a Unity Material with the Toon Shader. It allows for detailed customization of textures, colors, and various shading effects for a character. ```csharp using UnityEngine; public class CompleteToonCharacterSetup : MonoBehaviour { [Header("Texture Maps")] public Texture2D baseMap; public Texture2D firstShadingMap; public Texture2D secondShadingMap; public Texture2D normalMap; public Texture2D highlightMask; public Texture2D rimLightMask; public Texture2D matCapTexture; public Texture2D outlineWidthMap; public Texture2D emissionMap; [Header("Colors")] public Color baseColor = Color.white; public Color firstShadeColor = new Color(0.85f, 0.75f, 0.7f); public Color secondShadeColor = new Color(0.7f, 0.55f, 0.5f); public Color highlightColor = Color.white; public Color rimColor = new Color(0.8f, 0.9f, 1f); public Color outlineColor = new Color(0.2f, 0.15f, 0.1f); [Header("Style Settings")] [Range(0f, 1f)] public float baseColorStep = 0.5f; [Range(0f, 1f)] public float baseShadingFeather = 0.05f; [Range(0f, 1f)] public float highlightPower = 0.3f; [Range(0f, 5f)] public float outlineWidth = 1f; void Start() { SetupToonMaterial(); } void SetupToonMaterial() { Material mat = new Material(Shader.Find("Toon")); // === Three Basic Colors === mat.SetTexture("_MainTex", baseMap); mat.SetColor("_BaseColor", baseColor); mat.SetTexture("_1st_ShadeMap", firstShadingMap); mat.SetColor("_1st_ShadeColor", firstShadeColor); mat.SetTexture("_2nd_ShadeMap", secondShadingMap); mat.SetColor("_2nd_ShadeColor", secondShadeColor); // === Shading Steps === mat.SetFloat("_BaseColor_Step", baseColorStep); mat.SetFloat("_BaseShade_Feather", baseShadingFeather); mat.SetFloat("_ShadeColor_Step", 0.5f); mat.SetFloat("_1st2nd_Shades_Feather", 0.05f); mat.SetFloat("_Set_SystemShadowsToBase", 1f); // === Normal Map === if (normalMap != null) { mat.SetTexture("_NormalMap", normalMap); mat.SetFloat("_BumpScale", 1f); mat.SetFloat("_Is_NormalMapToBase", 1f); mat.SetFloat("_Is_NormalMapToHighColor", 1f); mat.SetFloat("_Is_NormalMapToRimLight", 1f); } // === Highlight === mat.SetColor("_HighColor", highlightColor); mat.SetFloat("_HighColor_Power", highlightPower); mat.SetFloat("_Is_SpecularToHighColor", 0f); // Hard mode if (highlightMask != null) mat.SetTexture("_Set_HighColorMask", highlightMask); // === Rim Light === mat.SetFloat("_RimLight", 1f); mat.SetColor("_RimLightColor", rimColor); mat.SetFloat("_RimLight_Power", 0.4f); mat.SetFloat("_RimLight_InsideMask", 0.5f); mat.SetFloat("_LightDirection_MaskOn", 1f); if (rimLightMask != null) mat.SetTexture("_Set_RimLightMask", rimLightMask); // === MatCap === if (matCapTexture != null) { mat.SetTexture("_MatCap_Sampler", matCapTexture); mat.SetFloat("_Is_BlendAddToMatCap", 1f); mat.SetFloat("_CameraRolling_Stabilizer", 1f); } // === Outline === mat.SetFloat("_OUTLINE", 1f); mat.SetFloat("_Outline_Width", outlineWidth); mat.SetColor("_Outline_Color", outlineColor); mat.SetFloat("_Is_BlendBaseColor", 1f); if (outlineWidthMap != null) mat.SetTexture("_Outline_Sampler", outlineWidthMap); // === Emission === if (emissionMap != null) { mat.SetTexture("_Emissive_Tex", emissionMap); mat.SetColor("_Emissive_Color", Color.white); } // === Light Effectiveness === mat.SetFloat("_Is_LightColor_Base", 0f); mat.SetFloat("_Is_LightColor_1st_Shade", 0f); mat.SetFloat("_Is_LightColor_2nd_Shade", 0f); mat.SetFloat("_Is_Filter_LightColor", 1f); mat.SetFloat("_GI_Intensity", 0.5f); // Apply to all renderers foreach (var renderer in GetComponentsInChildren()) { renderer.material = mat; } } } ``` -------------------------------- ### Install Unity Toon Shader via Unity Editor Source: https://context7.com/unity-technologies/com.unity.toonshader/llms.txt Alternative method to install the Unity Toon Shader package using the Unity Editor's Package Manager. ```csharp // Or install via Unity Editor: // 1. Window > Package Manager // 2. Click "+" button > "Add package by name..." // 3. Enter: com.unity.toonshader ``` -------------------------------- ### Install Unity Toon Shader via Package Manager Source: https://context7.com/unity-technologies/com.unity.toonshader/llms.txt Add the Unity Toon Shader package to your project by modifying the manifest.json file. ```json { "dependencies": { "com.unity.toonshader": "0.13.4-preview" } } ``` -------------------------------- ### Instantiate UTS2GUID objects Source: https://github.com/unity-technologies/com.unity.toonshader/blob/master/ToonShaderTessMeta.txt Creates new UTS2GUID instances for specific shader variants. Ensure these GUIDs match the corresponding shader assets in the project. ```csharp new UTS2GUID( "e667137c8b6fd3d4390fc364b2e5c70b", "Toon_ShadingGradeMap_Tess_StencilOut"), new UTS2GUID( "feba437d8ff93f745a78828529e9a272", "Toon_ShadingGradeMap_TransClipping_Tess"), new UTS2GUID( "8d1395a9f4bfad44d8fddd0f2af19b1e", "Toon_ShadingGradeMap_TransClipping_Tess_StencilMask"), new UTS2GUID( "08c6bb334aed21c4198cf46b71ebca2d", "Toon_ShadingGradeMap_TransClipping_Tess_StencilOut"), ``` -------------------------------- ### HDRP Toon EV Adjustment Setup Source: https://context7.com/unity-technologies/com.unity.toonshader/llms.txt This C# code outlines the setup for Scene and Model Toon EV Adjustment in HDRP. Scene adjustment affects all UTS materials in the scene, while Model adjustment targets specific models. Key properties include 'Ignore Volume Exposure', 'Light High Cut Filter', and 'Toon EV Adjustment Curve', which uses EV units for artistic control over the material's response to extreme lighting. ```csharp using UnityEngine; // Scene Toon EV Adjustment - affects all UTS materials in scene // Create via: GameObject > Toon Shader > Scene Toon EV Adjustment // Only one SceneToonEvAdjustment can exist per scene // Properties are set via Inspector or script: // Model Toon EV Adjustment - affects specific models // Create via: Select model > GameObject > Toon Shader > Attach Model Toon EV Adjustment // Key Properties: // - Ignore Volume Exposure: bypass HDRP automatic corrections // - Light High Cut Filter: clip light above 1 lux // - Toon EV Adjustment Curve: custom exposure response curve // The adjustment curve uses EV (Exposure Value) units: // Default range: -10 EV to -1.32 EV // This allows artistic control over how UTS responds to // extreme lighting conditions without whiteout or crushing // Example adjustment curve keyframes: // AnimationCurve.Linear(-10f, -10f, -1.32f, -1.32f) ``` -------------------------------- ### Create and Configure a Toon Material Source: https://context7.com/unity-technologies/com.unity.toonshader/llms.txt Sets up a new material using the Unity Toon Shader and assigns base color maps and colors. ```csharp using UnityEngine; public class ToonMaterialSetup : MonoBehaviour { public Texture2D baseMap; public Texture2D firstShadingMap; public Texture2D secondShadingMap; void Start() { // Create a new material with Unity Toon Shader Material toonMaterial = new Material(Shader.Find("Toon")); // Set the three basic color maps toonMaterial.SetTexture("_MainTex", baseMap); toonMaterial.SetTexture("_1st_ShadeMap", firstShadingMap); toonMaterial.SetTexture("_2nd_ShadeMap", secondShadingMap); // Set base colors (multiplied with textures) toonMaterial.SetColor("_BaseColor", Color.white); toonMaterial.SetColor("_1st_ShadeColor", new Color(0.8f, 0.7f, 0.6f)); toonMaterial.SetColor("_2nd_ShadeColor", new Color(0.6f, 0.5f, 0.4f)); // Apply to renderer GetComponent().material = toonMaterial; } } ``` -------------------------------- ### Material Converter Instructions Source: https://context7.com/unity-technologies/com.unity.toonshader/llms.txt Use the Unity Editor menu to migrate legacy toon shader materials to the current Unity Toon Shader format. Always perform a project backup before conversion. ```text // Material conversion is done through the Unity Editor menu: // Window > Rendering > Unity Toon Shader Converter // The converter supports: // 1. Unity-Chan Toon Shader 2 (Built-in) // 2. Universal Toon Shader (URP) // 3. UTS3 Built-in (older than 0.7.x) // 4. UTS3 Universal (older versions) // 5. UTS3 HDRP (older versions) // Steps: // 1. Open Window > Rendering > Unity Toon Shader Converter // 2. Select the source shader type from dropdown // 3. Click "Scan" to find convertible materials // 4. Review the list and fix any errors // 5. Click "Convert" to update all materials // Note: Always backup your project before conversion // Materials saved with UTS2 older than 2.0.6 must be // re-saved with version 2.0.7 or newer before conversion ``` -------------------------------- ### View Project File Structure Source: https://github.com/unity-technologies/com.unity.toonshader/blob/master/com.unity.toon-graphics-test/Editor/README_UnityToonShaderGenerator.md Overview of the directory layout for the generator scripts, property blocks, and target shader files. ```text com.unity.toon-graphics-test/ └── Editor/ ├── UnityToonShaderGenerator.cs # Unity Editor script ├── UnityToonShaderGeneratorTest.cs # Editor test harness └── README_UnityToonShaderGenerator.md # This file com.unity.toonshader/Runtime/Shaders/Common/Parts/ ├── CommonProperties.shaderblock # Shared properties (plain text) └── TessellationProperties.shaderblock # Tessellation-specific properties (plain text) com.unity.toonshader/Runtime/Integrated/Shaders/ ├── UnityToon.shader # Generated shader (regular) └── UnityToonTessellation.shader # Generated shader (tessellation) generate_UnityToon.py # Python generator (root) test_generate_UnityToon.py # Python smoke test (root) test_shader_generation.cs # .NET console smoke test (root) generate_UnityToon.sh / .bat # Platform launchers for the Python generator ``` -------------------------------- ### Execute Manual Shader Generation via Python Source: https://github.com/unity-technologies/com.unity.toonshader/blob/master/com.unity.toon-graphics-test/Editor/README_UnityToonShaderGenerator.md Run the Python helper script from the repository root to manually trigger the shader generation process. ```bash cd /workspace python3 generate_UnityToon.py ``` -------------------------------- ### Configure Emission with Animation in Unity Source: https://context7.com/unity-technologies/com.unity.toonshader/llms.txt Use this script to set up emission maps, colors, and animations including UV scrolling, color shifting, and rotation. Ensure the material has emission properties configured. ```csharp using UnityEngine; public class EmissionSetup : MonoBehaviour { public Texture2D emissionMap; public Color emissionColor = Color.white; public Color shiftTargetColor = Color.cyan; void ConfigureEmission(Material mat) { // Emission Map and Color mat.SetTexture("_Emissive_Tex", emissionMap); mat.SetColor("_Emissive_Color", emissionColor); // Enable Emission Animation mat.SetFloat("_Is_ViewCoord_Scroll", 0f); // 0 = UV Scroll, 1 = View Scroll // Base Animation Speed (1 = 1 second per cycle) mat.SetFloat("_Base_Speed", 1f); // UV Scroll Direction mat.SetFloat("_Scroll_EmissiveU", 0.5f); // U (horizontal) scroll mat.SetFloat("_Scroll_EmissiveV", 0f); // V (vertical) scroll // Rotation around UV center mat.SetFloat("_Rotate_EmissiveUV", 0f); // Degrees per base speed // Ping-pong animation (back and forth) mat.SetFloat("_Is_PingPong_Base", 0f); // Color Shifting with Time mat.SetFloat("_Is_ColorShift", 1f); mat.SetColor("_ColorShift", shiftTargetColor); mat.SetFloat("_ColorShift_Speed", 0.5f); // Color Shifting with View Angle mat.SetFloat("_Is_ViewShift", 1f); mat.SetColor("_ViewShift", new Color(1f, 0.5f, 1f)); } void Start() { Material mat = GetComponent().material; ConfigureEmission(mat); } } ``` -------------------------------- ### Configure Specular Highlights Source: https://context7.com/unity-technologies/com.unity.toonshader/llms.txt Sets up cel-style specular highlights including size, hardness, and mask control on a material. ```csharp using UnityEngine; public class HighlightSetup : MonoBehaviour { public Texture2D highlightMask; void ConfigureHighlight(Material mat) { // Highlight color and texture mat.SetColor("_HighColor", Color.white); // Highlight Power: controls size (0 = large, 1 = small) mat.SetFloat("_HighColor_Power", 0.5f); // Specular Mode: 0 = Hard (crisp edge), 1 = Soft (blurred) mat.SetFloat("_Is_SpecularToHighColor", 0f); // Hard mode // Color Blending Mode (only for Hard mode) // 0 = Multiply, 1 = Add mat.SetFloat("_Is_BlendAddToHiColor", 0f); // Highlight behavior on shadows mat.SetFloat("_Is_UseTweakHighColorOnShadow", 1f); mat.SetFloat("_TweakHighColorOnShadow", 0.5f); // Blending level // Highlight Mask: grayscale texture to control highlight intensity if (highlightMask != null) { mat.SetTexture("_Set_HighColorMask", highlightMask); mat.SetFloat("_Tweak_HighColorMaskLevel", 0f); // -1 to 1 } } void Start() { Material mat = GetComponent().material; ConfigureHighlight(mat); } } ``` -------------------------------- ### Configure Metaverse Light Settings Source: https://context7.com/unity-technologies/com.unity.toonshader/llms.txt Use this to enable virtual directional lighting for scenes lacking real directional lights, such as in VRChat environments. ```csharp using UnityEngine; public class MetaverseLightSetup : MonoBehaviour { void ConfigureMetaverseLight(Material mat) { // Enable Metaverse Light (for scenes without directional lights) mat.SetFloat("_Is_BLD", 1f); // Metaverse Light Intensity mat.SetFloat("_Unlit_Intensity", 1f); // Metaverse Light Direction mat.SetFloat("_Is_BLDOffsetX", 0f); // X offset disabled mat.SetFloat("_Offset_X_Axis_BLD", 0f); mat.SetFloat("_Is_BLDOffsetY", 0f); // Y offset disabled mat.SetFloat("_Offset_Y_Axis_BLD", 0f); mat.SetFloat("_Inverse_Z_Axis_BLD", 0f); // Invert Z direction } void Start() { Material mat = GetComponent().material; ConfigureMetaverseLight(mat); } } ``` -------------------------------- ### Configure Git for Symbolic Links Source: https://github.com/unity-technologies/com.unity.toonshader/blob/master/AutoGenerateParts/ReadmeFooter.md Enables symbolic link support in Git. Use `--local` for repository-specific settings or `--global` for user-wide settings. ```bash git config --local core.symlinks true ``` ```bash git config --global core.symlinks true ``` -------------------------------- ### Configure Angel Ring Projection in Unity Source: https://context7.com/unity-technologies/com.unity.toonshader/llms.txt Set up the Angel Ring effect for hair highlights, which requires the 'With Additional Control Maps' mode and 2nd UV coordinates. This script configures the texture, color, and offset. ```csharp using UnityEngine; public class AngelRingSetup : MonoBehaviour { public Texture2D angelRingTexture; void ConfigureAngelRing(Material mat) { // Set mode to "With Additional Control Maps" (required) mat.SetFloat("_utsTechnique", 1f); // Enable Angel Ring mat.SetFloat("_AngelRing", 1f); // Angel Ring Texture and Color mat.SetTexture("_AngelRing_Sampler", angelRingTexture); mat.SetColor("_AngelRing_Color", Color.white); // Offset U/V: adjust shape position mat.SetFloat("_AR_OffsetU", 0f); // Horizontal adjustment mat.SetFloat("_AR_OffsetV", 0f); // Vertical adjustment // Use alpha channel as clipping mask mat.SetFloat("_ARSampler_AlphaOn", 1f); } void Start() { Material mat = GetComponent().material; ConfigureAngelRing(mat); } } ``` -------------------------------- ### Configure Shading Step and Feather Properties Source: https://context7.com/unity-technologies/com.unity.toonshader/llms.txt Adjusts shading boundaries and transition softness for cel-shading effects, and enables system shadows. ```csharp using UnityEngine; public class ShadingConfiguration : MonoBehaviour { [Range(0f, 1f)] public float baseColorStep = 0.5f; [Range(0f, 1f)] public float baseShadingFeather = 0.01f; [Range(0f, 1f)] public float shadingColorStep = 0.5f; [Range(0f, 1f)] public float firstSecondFeather = 0.01f; void ConfigureShading(Material mat) { // Base Color Step: boundary between Base and 1st Shade // Higher values = more shadow visible mat.SetFloat("_BaseColor_Step", baseColorStep); // Base Shading Feather: softness of Base/1st boundary // 0 = sharp edge (posterized), 1 = smooth gradient mat.SetFloat("_BaseShade_Feather", baseShadingFeather); // Shading Color Step: boundary between 1st and 2nd Shade // Set to 0 if 2nd shade is not needed mat.SetFloat("_ShadeColor_Step", shadingColorStep); // 1st/2nd Shading Feather: softness between shade colors mat.SetFloat("_1st2nd_Shades_Feather", firstSecondFeather); // Enable receiving system shadows mat.SetFloat("_Set_SystemShadowsToBase", 1f); mat.SetFloat("_Tweak_SystemShadowsLevel", 0.5f); } void Start() { Material mat = GetComponent().material; ConfigureShading(mat); } } ``` -------------------------------- ### Configure Outline Settings Source: https://context7.com/unity-technologies/com.unity.toonshader/llms.txt Use this script to toggle outline modes and adjust width, color, and distance-based scaling. Supports texture-based width and color maps for advanced control. ```csharp using UnityEngine; public class OutlineSetup : MonoBehaviour { public Texture2D outlineWidthMap; public Texture2D outlineColorMap; public Texture2D bakedNormalMap; void ConfigureOutline(Material mat) { // Outline Mode: 0 = Normal Direction, 1 = Position Scaling mat.SetFloat("_OUTLINE", 1f); // Enable outline mat.SetFloat("_Outline_Mode", 0f); // Normal Direction // Outline Width (scale-dependent) mat.SetFloat("_Outline_Width", 1f); // Outline Color mat.SetColor("_Outline_Color", new Color(0.2f, 0.2f, 0.2f)); // Blend Base Color to Outline (outline takes nearby texture colors) mat.SetFloat("_Is_BlendBaseColor", 1f); // Offset Outline with Camera Z-axis (improves appearance on spiky meshes) mat.SetFloat("_Offset_Z", 0f); // Camera Distance for Outline Width mat.SetFloat("_Farthest_Distance", 100f); // Distance where outline vanishes mat.SetFloat("_Nearest_Distance", 0.5f); // Distance for full width // Outline Width Map (grayscale: white = thick, black = thin) if (outlineWidthMap != null) { mat.SetTexture("_Outline_Sampler", outlineWidthMap); } // Outline Color Map (texture-based outline color) if (outlineColorMap != null) { mat.SetFloat("_Is_OutlineTex", 1f); mat.SetTexture("_OutlineTex", outlineColorMap); } // Baked Normal Map (use normals from different model) if (bakedNormalMap != null) { mat.SetFloat("_Is_BakedNormal", 1f); mat.SetTexture("_BakedNormal", bakedNormalMap); } } void Start() { Material mat = GetComponent().material; ConfigureOutline(mat); } } ``` -------------------------------- ### Configure Normal Map Settings Source: https://context7.com/unity-technologies/com.unity.toonshader/llms.txt Apply normal maps to cel-shaded materials and define which lighting components are affected by surface bump details. ```csharp using UnityEngine; public class NormalMapSetup : MonoBehaviour { public Texture2D normalMap; void ConfigureNormalMap(Material mat) { // Set Normal Map mat.SetTexture("_NormalMap", normalMap); // Normal Map Strength (0 = no effect, 1 = full effect) mat.SetFloat("_BumpScale", 1f); // Normal Map Effectiveness on different areas // Toggle which areas are affected by normal map // Three Basic Colors (lit, 1st shade, 2nd shade) mat.SetFloat("_Is_NormalMapToBase", 1f); // Highlight mat.SetFloat("_Is_NormalMapToHighColor", 1f); // Rim Light mat.SetFloat("_Is_NormalMapToRimLight", 1f); } void Start() { Material mat = GetComponent().material; ConfigureNormalMap(mat); } } ``` -------------------------------- ### Define Shader Properties in .shaderblock Files Source: https://github.com/unity-technologies/com.unity.toonshader/blob/master/com.unity.toon-graphics-test/Editor/README_UnityToonShaderGenerator.md Use standard ShaderLab syntax within .shaderblock files to define properties. Comments and blank lines are preserved during the generation process. ```shaderlab // 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) ```