### Get Optimized Shader Settings with lilToon Source: https://context7.com/lilxyzw/liltoon/llms.txt Retrieve the optimized HLSL text and shader setting string for given materials and animation clips without writing to disk. This is useful for previewing optimizer results. ```csharp Material[] materials = new[] { mat1, mat2 }; AnimationClip[] clips = new[] { clip1 }; lilToonSetting.GetOptimizedSetting( materials, clips, out string usedShaders, out string optimizedHLSL, out string shaderSettingText ); Debug.Log("Shaders in use: " + usedShaders); // "lilToon\nHidden/lilToonTransparent" Debug.Log("Setting block:\n" + shaderSettingText); // "#define LIL_FEATURE_SHADOW\n#define LIL_FEATURE_EMISSION_1ST\n..." ``` -------------------------------- ### SemVerParser - Semantic Version Comparison Source: https://context7.com/lilxyzw/liltoon/llms.txt Parses and compares semantic version strings. Used by `lilConstants` to compare the installed package version against the latest remote version fetched from GitHub. ```APIDOC ## SemVerParser ### Description Parses and compares semver strings. Used by `lilConstants` to compare the installed package version against the latest remote version fetched from GitHub. ### Constructor - `SemVerParser(string version, bool isForced = false)`: Parses a semantic version string. If `isForced` is true and the version string is invalid, it defaults to `999999.999999.999999`. ### Properties - `major` (int): The major version number. - `minor` (int): The minor version number. - `patch` (int): The patch version number. - `prerelease` (string): The pre-release tag, if any. ### Example ```csharp var v1 = new SemVerParser("2.3.2"); var v2 = new SemVerParser("2.1.0"); var v3 = new SemVerParser("3.0.0-beta.1"); Debug.Log(v1 > v2); // true Debug.Log(v1 < v3); // true (release < pre-release of next major) Debug.Log(v1.major); // 2 Debug.Log(v1.minor); // 3 Debug.Log(v1.patch); // 2 Debug.Log(v3.prerelease); // "beta.1" // Forced parse (sets version to 999999.999999.999999 on invalid input) var forced = new SemVerParser("not-a-version", isForced: true); Debug.Log(forced.major); // 999999 ``` ``` -------------------------------- ### Detect Active Unity Render Pipeline Source: https://context7.com/lilxyzw/liltoon/llms.txt Query Unity's graphics settings to get the active render pipeline enum and its version information. This is useful for tools that need to adapt to different pipeline configurations. ```csharp // Get the pipeline type lilRenderPipeline rp = lilRenderPipelineReader.GetRP(); switch (rp) { case lilRenderPipeline.BRP: Debug.Log("Built-in"); break; case lilRenderPipeline.URP: Debug.Log("Universal"); break; case lilRenderPipeline.HDRP: Debug.Log("High Definition"); break; case lilRenderPipeline.LWRP: Debug.Log("Lightweight (legacy)"); break; } // Get full version information PackageVersionInfos info = lilRenderPipelineReader.GetRPInfos(); Debug.Log($"Pipeline: {info.RP} Version: {info.Major}.{info.Minor}.{info.Patch}"); // "Pipeline: URP Version: 14.0.9" ``` -------------------------------- ### lilToonSetting: Managing Shader Feature Flags Source: https://context7.com/lilxyzw/liltoon/llms.txt Demonstrates how to initialize, modify, and apply project-wide shader settings using the lilToonSetting ScriptableObject. This includes enabling/disabling specific features and reapplying settings to regenerate shaders. ```APIDOC ## lilToonSetting: Managing Shader Feature Flags ### Description This section covers the `lilToonSetting` ScriptableObject, which manages compile-time feature toggles and default lighting parameters for the lilToon shader. Settings are persisted to `ProjectSettings/lilToonSetting.json`. ### Methods - **InitializeShaderSetting**: Initializes or retrieves the `lilToonSetting` instance. - **TurnOffAllShaderSetting**: Disables all shader features. - **TurnOnAllShaderSetting**: Enables all shader features. - **SaveShaderSetting**: Persists the current shader settings. - **ApplyShaderSetting**: Regenerates shaders based on the current settings. ### Usage Example ```csharp // Load, mutate, and apply shader settings lilToonSetting shaderSetting = null; lilToonSetting.InitializeShaderSetting(ref shaderSetting); // Enable only what you need (start from a clean slate) lilToonSetting.TurnOffAllShaderSetting(ref shaderSetting); shaderSetting.LIL_FEATURE_SHADOW = true; shaderSetting.LIL_FEATURE_EMISSION_1ST = true; shaderSetting.LIL_FEATURE_RIMLIGHT = true; shaderSetting.LIL_FEATURE_OUTLINE_RECEIVE_SHADOW = true; shaderSetting.LIL_OPTIMIZE_USE_FORWARDADD = true; // Persist and recompile shaders lilToonSetting.SaveShaderSetting(shaderSetting); lilToonSetting.ApplyShaderSetting(shaderSetting, "[MyTool] Applied settings"); // Output: "[MyTool] Applied settings\n#define LIL_FEATURE_SHADOW\n#define LIL_FEATURE_EMISSION_1ST\n..." // Or turn everything on at once lilToonSetting.TurnOnAllShaderSetting(ref shaderSetting); lilToonSetting.ApplyShaderSetting(shaderSetting); ``` ``` -------------------------------- ### lilToonSetting.SetupShaderSettingFromMaterial: Auto-Detect Required Features Source: https://context7.com/lilxyzw/liltoon/llms.txt Details how to automatically detect and enable shader features used by a specific `Material`. This method is used by the build-time optimizer to include only necessary features. ```APIDOC ## lilToonSetting.SetupShaderSettingFromMaterial: Auto-Detect Required Features ### Description Inspects a `Material`'s property values and enables all feature flags that are actually in use. This method is fundamental to the build-time optimizer, which iterates through all scene materials and calls this function to determine the minimal set of shader features required. ### Methods - **SetupShaderSettingFromMaterial(Material mat, ref lilToonSetting shaderSetting)**: Scans a given `Material` to enable its used features in the `lilToonSetting`. ### Usage Example ```csharp // Scan a specific material to enable only the features it uses Material mat = AssetDatabase.LoadAssetAtPath("Assets/Characters/MyAvatar.mat"); lilToonSetting shaderSetting = null; lilToonSetting.InitializeShaderSetting(ref shaderSetting); lilToonSetting.TurnOffAllShaderSetting(ref shaderSetting); // Internally checks properties like _UseShadow, _UseEmission, _UseRim, etc. lilToonSetting.SetupShaderSettingFromMaterial(mat, ref shaderSetting); Debug.Log("Shadow enabled: " + shaderSetting.LIL_FEATURE_SHADOW); // true if _UseShadow != 0 Debug.Log("Emission enabled: " + shaderSetting.LIL_FEATURE_EMISSION_1ST); // true if _UseEmission != 0 ``` ``` -------------------------------- ### Generate HLSL Define Block with lilToonSetting Source: https://context7.com/lilxyzw/liltoon/llms.txt Convert the current `lilToonSetting` state into a `#define` string for HLSL shader files. Use `isFile: true` for a full header file string with include guards, or `isFile: false` for a compact string for multi-variant keywords. Optionally query shadow and backlight usage. ```csharp // Generate the full header file string (with include guards) string hlslBlock = lilToonSetting.BuildShaderSettingString(isFile: true); Debug.Log(hlslBlock); /* #ifndef LIL_SETTING_INCLUDED #define LIL_SETTING_INCLUDED #define LIL_FEATURE_ANIMATE_MAIN_UV #define LIL_FEATURE_SHADOW #define LIL_FEATURE_EMISSION_1ST ... #endif */ // Generate a compact string for per-shader multi-variant keywords (no include guards) string multiBlock = lilToonSetting.BuildShaderSettingStringMulti(); // Query shadow and backlight usage for conditional pass compilation bool useBaseShadow = false; bool useOutlineShadow = false; string settingStr = lilToonSetting.BuildShaderSettingString( isFile: false, ref useBaseShadow, ref useOutlineShadow); // useBaseShadow == true if SHADOW+RECEIVE_SHADOW or BACKLIGHT is enabled // useOutlineShadow == true if OUTLINE_RECEIVE_SHADOW is enabled ``` -------------------------------- ### lilToonSetting.SetShaderSettingBeforeBuild / SetShaderSettingAfterBuild Source: https://context7.com/lilxyzw/liltoon/llms.txt These methods are build hooks that optimize shaders by stripping unused features before a build and restoring them afterward. They can be called automatically during Unity builds or manually from custom scripts. ```APIDOC ## `lilToonSetting.SetShaderSettingBeforeBuild` / `SetShaderSettingAfterBuild` — Build Hooks These are called automatically by `lilToonAssetPostprocessor` during Unity builds. You can also call them manually from an NDMF plugin or custom build script to optimize shaders before packaging. ```csharp // Optimize shaders by scanning all scene-referenced materials and animation clips // Call before building to strip unused features lilToonSetting.SetShaderSettingBeforeBuild(loadBuildScene: true); // Rebuilds shaders with minimal feature set drawn from active scene content // Debug.Log: "[lilToon] PreprocessBuild\n#define LIL_FEATURE_SHADOW\n..." // After build, restore shaders to full feature set lilToonSetting.SetShaderSettingAfterBuild(); // Restores all features so the editor stays fully functional // Advanced: supply specific materials and clips (e.g. from an avatar descriptor) Material[] avatarMaterials = GetAvatarMaterials(); // your helper AnimationClip[] avatarClips = GetAvatarClips(); // your helper lilToonSetting.SetShaderSettingBeforeBuild(avatarMaterials, avatarClips); ``` ``` -------------------------------- ### lilToonSetting.GetOptimizedSetting Source: https://context7.com/lilxyzw/liltoon/llms.txt Retrieves the optimized HLSL text and shader setting string for given materials and animation clips without modifying any files. This is useful for previewing optimization results. ```APIDOC ## `lilToonSetting.GetOptimizedSetting` — NDMF / Tool Integration Returns the optimized HLSL text and shader setting string for a given set of materials and animation clips, without writing anything to disk. Useful for previewing what the optimizer would do. ```csharp Material[] materials = new[] { mat1, mat2 }; AnimationClip[] clips = new[] { clip1 }; lilToonSetting.GetOptimizedSetting( materials, clips, out string usedShaders, out string optimizedHLSL, out string shaderSettingText ); Debug.Log("Shaders in use: " + usedShaders); // "lilToon\nHidden/lilToonTransparent" Debug.Log("Setting block:\n" + shaderSettingText); // "#define LIL_FEATURE_SHADOW\n#define LIL_FEATURE_EMISSION_1ST\n..." ``` ``` -------------------------------- ### Compare Semantic Versions Source: https://context7.com/lilxyzw/liltoon/llms.txt Parse and compare semantic version strings. This utility is used to check package versions against remote releases, ensuring compatibility. ```csharp var v1 = new SemVerParser("2.3.2"); var v2 = new SemVerParser("2.1.0"); var v3 = new SemVerParser("3.0.0-beta.1"); Debug.Log(v1 > v2); // true Debug.Log(v1 < v3); // true (release < pre-release of next major) Debug.Log(v1.major); // 2 Debug.Log(v1.minor); // 3 Debug.Log(v1.patch); // 2 Debug.Log(v3.prerelease); // "beta.1" // Forced parse (sets version to 999999.999999.999999 on invalid input) var forced = new SemVerParser("not-a-version", isForced: true); Debug.Log(forced.major); // 999999 ``` -------------------------------- ### lilTooning Core Toon Shading Math (HLSL) Source: https://context7.com/lilxyzw/liltoon/llms.txt Implements fundamental step/smooth-step functions for toon shading effects like shadow borders and rim lights. Supports hard steps and anti-aliasing using fwidth. ```hlsl // In a custom lilToon shader include: #include "Packages/jp.lilxyzw.liltoon/Assets/lilToon/Shader/Includes/lil_common_functions.hlsl" // Hard or AA-smoothed step at a border value float shadowMask = lilTooning(NdotL, _ShadowBorder); // basic step float shadowMask2 = lilTooning(NdotL, _ShadowBorder, _ShadowBlur); // smooth border // Scaled variant (multiplied by aascale before saturate) float rimMask = lilTooningScale(aascale, fresnel, _RimBorder, _RimBlur); // Non-saturated variant (returns values outside [0,1] — useful for stacking) float raw = lilTooningNoSaturate(NdotL, 0.5, 0.1); ``` -------------------------------- ### lilToonSetting.BuildShaderSettingString: Generate HLSL Feature Define Block Source: https://context7.com/lilxyzw/liltoon/llms.txt Explains how to generate the HLSL `#define` string from the current `lilToonSetting` state. This is useful for debugging, inspection, or integration with build tools. ```APIDOC ## lilToonSetting.BuildShaderSettingString: Generate HLSL Feature Define Block ### Description Converts the current `lilToonSetting` state into the `#define` string that is injected into shader files. This is useful for inspecting or debugging active features, or for integration with build tools like NDMF. ### Methods - **BuildShaderSettingString(isFile: bool, ref useBaseShadow: out bool, ref useOutlineShadow: out bool)**: Generates the `#define` block. - `isFile`: If true, includes include guards and generates a full header file string. If false, generates a compact string for multi-variant keywords. - `useBaseShadow`: Output parameter, true if SHADOW or BACKLIGHT is enabled. - `useOutlineShadow`: Output parameter, true if OUTLINE_RECEIVE_SHADOW is enabled. ### Usage Example ```csharp // Generate the full header file string (with include guards) string hlslBlock = lilToonSetting.BuildShaderSettingString(isFile: true); Debug.Log(hlslBlock); /* #ifndef LIL_SETTING_INCLUDED #define LIL_SETTING_INCLUDED #define LIL_FEATURE_ANIMATE_MAIN_UV #define LIL_FEATURE_SHADOW #define LIL_FEATURE_EMISSION_1ST ... #endif */ // Generate a compact string for per-shader multi-variant keywords (no include guards) string multiBlock = lilToonSetting.BuildShaderSettingStringMulti(); // Query shadow and backlight usage for conditional pass compilation bool useBaseShadow = false; bool useOutlineShadow = false; string settingStr = lilToonSetting.BuildShaderSettingString(isFile: false, ref useBaseShadow, ref useOutlineShadow); // useBaseShadow == true if SHADOW+RECEIVE_SHADOW or BACKLIGHT is enabled // useOutlineShadow == true if OUTLINE_RECEIVE_SHADOW is enabled ``` ``` -------------------------------- ### Optimize Shaders Before and After Build with lilToon Source: https://context7.com/lilxyzw/liltoon/llms.txt Call these functions automatically via `lilToonAssetPostprocessor` or manually from NDMF plugins. `SetShaderSettingBeforeBuild` optimizes shaders by scanning scene-referenced materials and animation clips. `SetShaderSettingAfterBuild` restores the full feature set. ```csharp // Optimize shaders by scanning all scene-referenced materials and animation clips // Call before building to strip unused features lilToonSetting.SetShaderSettingBeforeBuild(loadBuildScene: true); // Rebuilds shaders with minimal feature set drawn from active scene content // Debug.Log: "[lilToon] PreprocessBuild\n#define LIL_FEATURE_SHADOW\n..." // After build, restore shaders to full feature set lilToonSetting.SetShaderSettingAfterBuild(); // Restores all features so the editor stays fully functional // Advanced: supply specific materials and clips (e.g. from an avatar descriptor) Material[] avatarMaterials = GetAvatarMaterials(); // your helper AnimationClip[] avatarClips = GetAvatarClips(); // your helper lilToonSetting.SetShaderSettingBeforeBuild(avatarMaterials, avatarClips); ``` -------------------------------- ### Manage lilToon Shader Settings Source: https://context7.com/lilxyzw/liltoon/llms.txt Load, modify, and apply project-wide shader feature flags using `lilToonSetting`. Ensure `InitializeShaderSetting` is called before mutating settings. Use `SaveShaderSetting` to persist changes and `ApplyShaderSetting` to recompile shaders. ```csharp // Load, mutate, and apply shader settings lilToonSetting shaderSetting = null; lilToonSetting.InitializeShaderSetting(ref shaderSetting); // Enable only what you need (start from a clean slate) lilToonSetting.TurnOffAllShaderSetting(ref shaderSetting); shaderSetting.LIL_FEATURE_SHADOW = true; shaderSetting.LIL_FEATURE_EMISSION_1ST = true; shaderSetting.LIL_FEATURE_RIMLIGHT = true; shaderSetting.LIL_FEATURE_OUTLINE_RECEIVE_SHADOW = true; shaderSetting.LIL_OPTIMIZE_USE_FORWARDADD = true; // Persist and recompile shaders lilToonSetting.SaveShaderSetting(shaderSetting); lilToonSetting.ApplyShaderSetting(shaderSetting, "[MyTool] Applied settings"); // Output: "[MyTool] Applied settings\n#define LIL_FEATURE_SHADOW\n#define LIL_FEATURE_EMISSION_1ST\n..." // Or turn everything on at once lilToonSetting.TurnOnAllShaderSetting(ref shaderSetting); lilToonSetting.ApplyShaderSetting(shaderSetting); ``` -------------------------------- ### HLSL Shader Functions: lilTooning / lilTooningScale Source: https://context7.com/lilxyzw/liltoon/llms.txt Core toon shading functions for creating step/smooth-step transitions for shadows and rim lights, with options for anti-aliasing. ```APIDOC ## HLSL Shader Functions: lilTooning / lilTooningScale ### Description The fundamental step/smooth-step functions used throughout the shader for shadow borders, rim light edges, and other binary-to-smooth transitions. Anti-aliasing mode 1 uses `fwidth`-based derivatives for screen-space AA; mode 0 uses hard steps. ### Functions #### lilTooning Calculates a hard or AA-smoothed step at a border value. ```hlsl float lilTooning(float value, float border, float blur = 0.0) ``` - **value** (float) - The input value to test. - **border** (float) - The border value. - **blur** (float, optional) - The blur amount for smoothing. Defaults to 0.0. - Returns: A float value representing the step or smoothed step. #### lilTooningScale Similar to `lilTooning` but scaled by `aascale` before saturation. Useful for anti-aliased effects. ```hlsl float lilTooningScale(float aascale, float value, float border, float blur = 0.0) ``` - **aascale** (float) - The scaling factor for anti-aliasing. - **value** (float) - The input value to test. - **border** (float) - The border value. - **blur** (float, optional) - The blur amount for smoothing. Defaults to 0.0. - Returns: A scaled and potentially smoothed float value. #### lilTooningNoSaturate A non-saturating variant that can return values outside the [0,1] range, useful for stacking effects. ```hlsl float lilTooningNoSaturate(float value, float border, float blur = 0.0) ``` - **value** (float) - The input value to test. - **border** (float) - The border value. - **blur** (float, optional) - The blur amount for smoothing. Defaults to 0.0. - Returns: A float value that is not clamped to [0,1]. ### Usage Example ```hlsl // In a custom lilToon shader include: #include "Packages/jp.lilxyzw.liltoon/Assets/lilToon/Shader/Includes/lil_common_functions.hlsl" // Hard or AA-smoothed step at a border value float shadowMask = lilTooning(NdotL, _ShadowBorder); // basic step float shadowMask2 = lilTooning(NdotL, _ShadowBorder, _ShadowBlur); // smooth border // Scaled variant (multiplied by aascale before saturate) float rimMask = lilTooningScale(aascale, fresnel, _RimBorder, _RimBlur); // Non-saturated variant (returns values outside [0,1] — useful for stacking) float raw = lilTooningNoSaturate(NdotL, 0.5, 0.1); ``` ``` -------------------------------- ### lilToonInspector Custom ShaderGUI Entry Point Source: https://context7.com/lilxyzw/liltoon/llms.txt Base class for creating custom material inspectors for lilToon-derived shaders. Override LoadCustomProperties and DrawCustomProperties to add custom UI elements. ```csharp // In your Editor assembly, create a custom inspector for your custom shader using lilToon; using UnityEditor; using UnityEngine; public class MyCustomShaderInspector : lilToonInspector { MaterialProperty _MyCustomProperty; // Called before the inspector renders — load extra properties here protected override void LoadCustomProperties(MaterialProperty[] props, Material material) { isCustomShader = true; _MyCustomProperty = FindProperty("_MyCustomProperty", props, false); } // Called in the "Custom Properties" section of the inspector protected override void DrawCustomProperties(Material material) { if (_MyCustomProperty != null) { m_MaterialEditor.ShaderProperty(_MyCustomProperty, "My Custom Value"); } } } // Assign this editor class name in your .shader file: // CustomEditor "MyCustomShaderInspector" ``` -------------------------------- ### lilMaterialUtils.SetupMaterialWithRenderingMode Source: https://context7.com/lilxyzw/liltoon/llms.txt Changes a material's rendering mode by switching to the appropriate lilToon shader variant and configuring blend state, stencil, and pass settings. This function mimics the behavior of the Material Inspector's rendering mode dropdown. ```APIDOC ## `lilMaterialUtils.SetupMaterialWithRenderingMode` — Change Material Rendering Mode Switches a material to the correct lilToon shader variant and configures all blend state, stencil, and pass settings for the target rendering mode. This is what the Material Inspector calls when you change the dropdown. ```csharp Material mat = AssetDatabase.LoadAssetAtPath("Assets/MyMat.mat"); // Switch to Transparent + outline lilMaterialUtils.SetupMaterialWithRenderingMode( mat, RenderingMode.Transparent, TransparentMode.Normal, isoutl: true, islite: false, istess: false, ismulti: false ); // mat.shader is now "Hidden/lilToonTransparentOutline" // Blend state: SrcBlend=SrcAlpha, DstBlend=OneMinusSrcAlpha, ZWrite=1 // Switch to Fur lilMaterialUtils.SetupMaterialWithRenderingMode( mat, RenderingMode.Fur, TransparentMode.Normal, isoutl: false, islite: false, istess: false, ismulti: false ); // mat.shader is now "Hidden/lilToonFur" // Switch to Gem (auto-configures Cull=0, ZWrite=0) lilMaterialUtils.SetupMaterialWithRenderingMode( mat, RenderingMode.Gem, TransparentMode.Normal, isoutl: false, islite: false, istess: false, ismulti: false ); ``` ``` -------------------------------- ### Apply lilToon Preset to Material Source: https://context7.com/lilxyzw/liltoon/llms.txt Loads a lilToonPreset asset and applies its settings to a material. Records Undo operations. The preset controls outline and tessellation variants. ```csharp // Load a preset asset var preset = AssetDatabase.LoadAssetAtPath("Assets/lilToon/Presets/Skin.asset"); Material mat = AssetDatabase.LoadAssetAtPath("Assets/Characters/Body.mat"); bool ismulti = lilShaderUtils.IsMultiShaderName(mat.shader.name); // Apply preset (records Undo) lilToonPreset.ApplyPreset(mat, preset, ismulti); // Shader, colors (_Color, _ShadowColor, etc.), and float properties are all applied. // outline=-1 → preserves current outline state; outline=1 → forces outline on. ``` -------------------------------- ### lilGetVertexPositionInputs: Vertex Position Transform Helper Source: https://context7.com/lilxyzw/liltoon/llms.txt Transforms an object-space position into world, view, clip, and screen space. Matches the URP GetVertexPositionInputs pattern but works across all lilToon-supported pipelines. Include lil_common_functions.hlsl. ```hlsl #include "Packages/jp.lilxyzw.liltoon/Assets/lilToon/Shader/Includes/lil_common_functions.hlsl" // In a vertex shader float4 posOS = v.vertex; // object space lilVertexPositionInputs posInputs = lilGetVertexPositionInputs(posOS); // posInputs.positionWS — world space float3 // posInputs.positionVS — view space float3 // posInputs.positionCS — clip space float4 (output to SV_POSITION) // posInputs.positionSS — screen space float4 (for screen-space effects) o.positionCS = posInputs.positionCS; o.worldPos = posInputs.positionWS; ``` -------------------------------- ### lilEditorGUI Source: https://context7.com/lilxyzw/liltoon/llms.txt A helper class providing custom inspector widgets such as styled foldouts, separator lines, and web-link buttons, useful for building custom inspectors. ```APIDOC ## lilEditorGUI ### Description Helper class providing styled foldouts, separator lines, web-link buttons, and the collapsible box containers used throughout the lilToon inspector. Useful when building a custom inspector that inherits from `lilToonInspector`. ### Methods #### Foldout Draws a collapsible section header. ```csharp public static bool Foldout(string label, bool foldoutState) ``` - **label** (string) - The label for the foldout. - **foldoutState** (bool) - The current state of the foldout (true for expanded, false for collapsed). - Returns: The updated state of the foldout. #### DrawLine Draws a thin horizontal separator line. ```csharp public static void DrawLine() ``` #### DrawWebButton Draws a clickable web link button. ```csharp public static void DrawWebButton(string label, string url) ``` - **label** (string) - The text displayed on the button. - **url** (string) - The URL to open when the button is clicked. ### Usage Example ```csharp // Draw a collapsible section bool showShadow = EditorPrefs.GetBool("lil_showShadow", true); showShadow = lilEditorGUI.Foldout("Shadow Settings", showShadow); EditorPrefs.SetBool("lil_showShadow", showShadow); if (showShadow) { // ... draw shadow properties } // Draw a thin horizontal separator line lilEditorGUI.DrawLine(); // Draw a clickable web link button lilEditorGUI.DrawWebButton("Documentation", "https://lilxyzw.github.io/lilToon/"); ``` ``` -------------------------------- ### lilLanguageManager Localization Functions Source: https://context7.com/lilxyzw/liltoon/llms.txt Manages localized strings for the inspector UI, supporting multiple languages and custom .po files. Provides functions to retrieve strings, build parameter strings, and select languages. ```csharp // Initialize or refresh language (called automatically on inspector load) lilLanguageManager.UpdateLanguage(); // Retrieve a localized string by key string label = lilLanguageManager.GetLoc("sGradColor"); // Returns "Grad Color" (en-US) or "グラデーションカラー" (ja-JP) // Load a custom language file by GUID lilLanguageManager.LoadCustomLanguage("your-asset-guid-here"); // Build a pipe-separated parameter string used by popup fields string blendModes = lilLanguageManager.BuildParams("Normal", "Add", "Screen", "Multiply"); // "Normal|Add|Screen|Multiply" // Show a language selector dropdown in an editor window lilLanguageManager.SelectLang(); ``` -------------------------------- ### lilToonPreset.ApplyPreset Source: https://context7.com/lilxyzw/liltoon/llms.txt Applies a lilToonPreset asset to a material, swapping shader properties like colors, floats, and textures. It also controls outline and tessellation variants based on preset settings. ```APIDOC ## lilToonPreset.ApplyPreset ### Description Applies a `lilToonPreset` asset (ScriptableObject) to a material, swapping the shader, colors, floats, vectors, and textures as defined in the preset. The preset controls whether to keep or override outline and tessellation variants. ### Method Signature ```csharp public static void ApplyPreset(Material mat, lilToonPreset preset, bool isMultiShaderName) ``` ### Parameters - **mat** (Material) - The material to apply the preset to. - **preset** (lilToonPreset) - The preset asset to apply. - **isMultiShaderName** (bool) - Indicates if the material uses a multi-shader name. ### Usage Example ```csharp // Load a preset asset var preset = AssetDatabase.LoadAssetAtPath("Assets/lilToon/Presets/Skin.asset"); Material mat = AssetDatabase.LoadAssetAtPath("Assets/Characters/Body.mat"); bool ismulti = lilShaderUtils.IsMultiShaderName(mat.shader.name); // Apply preset (records Undo) lilToonPreset.ApplyPreset(mat, preset, ismulti); // Shader, colors (_Color, _ShadowColor, etc.), and float properties are all applied. // outline=-1 → preserves current outline state; outline=1 → forces outline on. ``` ``` -------------------------------- ### Auto-Detect Shader Features from Material Source: https://context7.com/lilxyzw/liltoon/llms.txt Inspect a `Material`'s properties to automatically enable only the features it uses. This method is used by the build-time optimizer to scan scene materials and configure `lilToonSetting` accordingly. ```csharp // Scan a specific material to enable only the features it uses Material mat = AssetDatabase.LoadAssetAtPath("Assets/Characters/MyAvatar.mat"); lilToonSetting shaderSetting = null; lilToonSetting.InitializeShaderSetting(ref shaderSetting); lilToonSetting.TurnOffAllShaderSetting(ref shaderSetting); // Internally checks properties like _UseShadow, _UseEmission, _UseRim, etc. lilToonSetting.SetupShaderSettingFromMaterial(mat, ref shaderSetting); Debug.Log("Shadow enabled: " + shaderSetting.LIL_FEATURE_SHADOW); // true if _UseShadow != 0 Debug.Log("Emission enabled: " + shaderSetting.LIL_FEATURE_EMISSION_1ST); // true if _UseEmission != 0 ``` -------------------------------- ### Shader Compile-Time Feature Macros Source: https://context7.com/lilxyzw/liltoon/llms.txt lilToon shaders use compile-time macros defined in `lil_setting.hlsl` to conditionally compile features. Custom shaders can use these macros to conditionally include their own code. ```APIDOC ## Shader Compile-Time Feature Macros ### Description lilToon shaders use a header (`lil_setting.hlsl` generated by `BuildShaderSettingString`) with `#define` guards to conditionally compile features. In custom shaders that `#include` lilToon's passes, you can check these guards to conditionally compile your own additions. ### Example Usage ```hlsl // lil_setting.hlsl (auto-generated by lilToonSetting.ApplyShaderSetting): #ifndef LIL_SETTING_INCLUDED #define LIL_SETTING_INCLUDED #define LIL_FEATURE_SHADOW #define LIL_FEATURE_RECEIVE_SHADOW #define LIL_FEATURE_EMISSION_1ST #define LIL_FEATURE_RIMLIGHT #define LIL_FEATURE_MATCAP #define LIL_FEATURE_BumpMap #define LIL_OPTIMIZE_USE_FORWARDADD #define LIL_OPTIMIZE_USE_VERTEXLIGHT #endif // In your custom shader HLSL: #ifdef LIL_FEATURE_SHADOW // Shadow-specific code compiled only when the feature is active float shadowAtten = lilTooning(NdotL, _ShadowBorder, _ShadowBlur); #endif #ifdef LIL_FEATURE_RIMLIGHT float3 rim = _RimColor.rgb * pow(1.0 - saturate(dot(normalWS, viewDir)), _RimFresnelPower); #endif ``` ``` -------------------------------- ### lilShaderAPI - Texture Slot Budget Source: https://context7.com/lilxyzw/liltoon/llms.txt Returns whether the current graphics device is limited to 32 texture slots (OpenGL ES3 / Core), which restricts which per-texture features can be enabled. ```APIDOC ## lilShaderAPI ### Description Returns whether the current graphics device is limited to 32 texture slots (OpenGL ES3 / Core), which restricts which per-texture features can be enabled. Used by `TurnOnAllShaderSetting` to avoid enabling texture features that would exceed hardware limits. ### Methods - `IsTextureLimitedAPI()`: Returns `true` if the device is limited to 32 texture slots, `false` otherwise. - `CurrentAPITextureLimit()`: Returns the current texture slot limit for the graphics API. ### Example ```csharp bool limited = lilShaderAPI.IsTextureLimitedAPI(); int limit = lilShaderAPI.CurrentAPITextureLimit(); if (limited) { Debug.LogWarning($"Device only supports {limit} textures. Some features disabled."); // Per-texture features such as LIL_FEATURE_BumpMap, // LIL_FEATURE_MatCapTex etc. will not be enabled by TurnOnAllShaderSetting. } else { Debug.Log($"Full texture budget: {limit} slots available."); // 128 on Vulkan / DX11 / Metal } ``` ``` -------------------------------- ### lilRenderPipelineReader - Detect Active Render Pipeline Source: https://context7.com/lilxyzw/liltoon/llms.txt Queries Unity's graphics settings to return the active render pipeline enum and version. Used internally to switch shader pass configurations; also available for custom tools. ```APIDOC ## lilRenderPipelineReader ### Description Queries Unity's graphics settings to return the active render pipeline enum and version. Used internally to switch shader pass configurations; also available for custom tools. ### Methods - `GetRP()`: Returns the active render pipeline enum. - `GetRPInfos()`: Returns full version information about the active render pipeline. ### Return Values - `GetRP()`: Returns a `lilRenderPipeline` enum value (BRP, URP, HDRP, LWRP). - `GetRPInfos()`: Returns a `PackageVersionInfos` object containing `RP`, `Major`, `Minor`, and `Patch` properties. ### Example ```csharp // Get the pipeline type lilRenderPipeline rp = lilRenderPipelineReader.GetRP(); switch (rp) { case lilRenderPipeline.BRP: Debug.Log("Built-in"); break; case lilRenderPipeline.URP: Debug.Log("Universal"); break; case lilRenderPipeline.HDRP: Debug.Log("High Definition"); break; case lilRenderPipeline.LWRP: Debug.Log("Lightweight (legacy)"); break; } // Get full version information PackageVersionInfos info = lilRenderPipelineReader.GetRPInfos(); Debug.Log($"Pipeline: {info.RP} Version: {info.Major}.{info.Minor}.{info.Patch}"); // "Pipeline: URP Version: 14.0.9" ``` ``` -------------------------------- ### Shader Compile-Time Feature Macros in lilToon Source: https://context7.com/lilxyzw/liltoon/llms.txt lilToon shaders use #define guards in lil_setting.hlsl for conditional compilation. Check these guards in custom shaders to conditionally compile your own additions, ensuring they are stripped by the optimizer. ```hlsl // lil_setting.hlsl (auto-generated by lilToonSetting.ApplyShaderSetting): #ifndef LIL_SETTING_INCLUDED #define LIL_SETTING_INCLUDED #define LIL_FEATURE_SHADOW #define LIL_FEATURE_RECEIVE_SHADOW #define LIL_FEATURE_EMISSION_1ST #define LIL_FEATURE_RIMLIGHT #define LIL_FEATURE_MATCAP #define LIL_FEATURE_BumpMap #define LIL_OPTIMIZE_USE_FORWARDADD #define LIL_OPTIMIZE_USE_VERTEXLIGHT #endif // In your custom shader HLSL: #ifdef LIL_FEATURE_SHADOW // Shadow-specific code compiled only when the feature is active float shadowAtten = lilTooning(NdotL, _ShadowBorder, _ShadowBlur); #endif #ifdef LIL_FEATURE_RIMLIGHT float3 rim = _RimColor.rgb * pow(1.0 - saturate(dot(normalWS, viewDir)), _RimFresnelPower); #endif ``` -------------------------------- ### Change Material Rendering Mode with lilToon Source: https://context7.com/lilxyzw/liltoon/llms.txt Switches a material to the correct lilToon shader variant and configures blend state, stencil, and pass settings for the target rendering mode. This function mimics the Material Inspector's dropdown behavior. ```csharp Material mat = AssetDatabase.LoadAssetAtPath("Assets/MyMat.mat"); // Switch to Transparent + outline lilMaterialUtils.SetupMaterialWithRenderingMode( mat, RenderingMode.Transparent, TransparentMode.Normal, isoutl: true, islite: false, istess: false, ismulti: false ); // mat.shader is now "Hidden/lilToonTransparentOutline" // Blend state: SrcBlend=SrcAlpha, DstBlend=OneMinusSrcAlpha, ZWrite=1 // Switch to Fur lilMaterialUtils.SetupMaterialWithRenderingMode( mat, RenderingMode.Fur, TransparentMode.Normal, isoutl: false, islite: false, istess: false, ismulti: false ); // mat.shader is now "Hidden/lilToonFur" // Switch to Gem (auto-configures Cull=0, ZWrite=0) lilMaterialUtils.SetupMaterialWithRenderingMode( mat, RenderingMode.Gem, TransparentMode.Normal, isoutl: false, islite: false, istess: false, ismulti: false ); ``` -------------------------------- ### Check Texture Slot Budget for Graphics API Source: https://context7.com/lilxyzw/liltoon/llms.txt Determine if the current graphics device has a limited texture slot budget (e.g., 32 for OpenGL ES3). This helps in deciding which per-texture features can be safely enabled. ```csharp bool limited = lilShaderAPI.IsTextureLimitedAPI(); int limit = lilShaderAPI.CurrentAPITextureLimit(); if (limited) { Debug.LogWarning($"Device only supports {limit} textures. Some features disabled."); // Per-texture features such as LIL_FEATURE_BumpMap, // LIL_FEATURE_MatCapTex etc. will not be enabled by TurnOnAllShaderSetting. } else { Debug.Log($"Full texture budget: {limit} slots available."); // 128 on Vulkan / DX11 / Metal } ``` -------------------------------- ### lilEditorGUI Custom Inspector Widgets Source: https://context7.com/lilxyzw/liltoon/llms.txt Provides helper functions for creating custom inspector UI elements like foldouts, separators, and web links. Useful for custom inspectors inheriting from lilToonInspector. ```csharp // Draw a collapsible section bool showShadow = EditorPrefs.GetBool("lil_showShadow", true); showShadow = lilEditorGUI.Foldout("Shadow Settings", showShadow); EditorPrefs.SetBool("lil_showShadow", showShadow); if (showShadow) { // ... draw shadow properties } // Draw a thin horizontal separator line lilEditorGUI.DrawLine(); // Draw a clickable web link button lilEditorGUI.DrawWebButton("Documentation", "https://lilxyzw.github.io/lilToon/"); ``` -------------------------------- ### lilToon2Ramp - Bake Shadow Ramp Texture Source: https://context7.com/lilxyzw/liltoon/llms.txt Bakes a lilToon material's shadow/tone shading configuration into a 2D ramp Texture2D using the hidden `ltsother_bakeramp` shader. ```APIDOC ## lilToon2Ramp ### Description Bakes a lilToon material's shadow/tone shading configuration into a 2D ramp `Texture2D` using the hidden `ltsother_bakeramp` shader. The result can be used as a `_ShadowColorTex` or exported for external use. ### Methods - `Convert(Material mat, int width = 128)`: Converts the material's shadow configuration to a `Texture2D` in memory. - `ConvertAndSave(Material mat, int width = 128, string path = null)`: Converts the material's shadow configuration and saves it as a PNG file. ### Parameters - `mat` (Material): The lilToon material to bake the ramp from. - `width` (int, optional): The desired width of the ramp texture. Defaults to 128. - `path` (string, optional): The custom path to save the PNG file. If null, it saves next to the material with `_ramp.png` appended. ### Example ```csharp Material mat = AssetDatabase.LoadAssetAtPath("Assets/Characters/Body.mat"); // In-memory conversion (128px wide, 16px tall ramp) Texture2D ramp = lilToon2Ramp.Convert(mat, width: 256); // Convert and auto-save as PNG next to the material lilToon2Ramp.ConvertAndSave(mat, width: 128); // Saved to: "Assets/Characters/Body_ramp.png" // Imported with wrapMode=Clamp, CompressedHQ // Custom output path lilToon2Ramp.ConvertAndSave(mat, width: 128, path: "Assets/Textures/MyRamp.png"); ``` ``` -------------------------------- ### lilGetVertexPositionInputs Source: https://context7.com/lilxyzw/liltoon/llms.txt Transforms an object-space position into world, view, clip, and screen space simultaneously. This function matches the URP `GetVertexPositionInputs` pattern but works across all lilToon-supported pipelines. ```APIDOC ## lilGetVertexPositionInputs ### Description Transforms an object-space position into world, view, clip, and screen space simultaneously, matching the URP `GetVertexPositionInputs` pattern but working across all lilToon-supported pipelines. ### Usage ```hlsl #include "Packages/jp.lilxyzw.liltoon/Assets/lilToon/Shader/Includes/lil_common_functions.hlsl" // In a vertex shader float4 posOS = v.vertex; // object space lilVertexPositionInputs posInputs = lilGetVertexPositionInputs(posOS); // posInputs.positionWS — world space float3 // posInputs.positionVS — view space float3 // posInputs.positionCS — clip space float4 (output to SV_POSITION) // posInputs.positionSS — screen space float4 (for screen-space effects) o.positionCS = posInputs.positionCS; o.worldPos = posInputs.positionWS; ``` ``` -------------------------------- ### Bake lilToon Shadow Ramp Texture Source: https://context7.com/lilxyzw/liltoon/llms.txt Generate a 2D ramp texture from a lilToon material's shadow configuration using a hidden baker shader. The resulting texture can be used for shadow colors or exported. ```csharp Material mat = AssetDatabase.LoadAssetAtPath("Assets/Characters/Body.mat"); // In-memory conversion (128px wide, 16px tall ramp) Texture2D ramp = lilToon2Ramp.Convert(mat, width: 256); // Convert and auto-save as PNG next to the material lilToon2Ramp.ConvertAndSave(mat, width: 128); // Saved to: "Assets/Characters/Body_ramp.png" // Imported with wrapMode=Clamp, CompressedHQ // Custom output path lilToon2Ramp.ConvertAndSave(mat, width: 128, path: "Assets/Textures/MyRamp.png"); ``` -------------------------------- ### lilLanguageManager Source: https://context7.com/lilxyzw/liltoon/llms.txt Manages localization for the inspector UI, supporting multiple languages and custom language files. ```APIDOC ## lilLanguageManager ### Description Retrieves localized strings for the inspector UI. Supports en-US, ja-JP, ko-KR, zh-Hans, zh-Hant, and custom `.po` language files. ### Methods #### UpdateLanguage Initializes or refreshes the language settings. Called automatically on inspector load. ```csharp public static void UpdateLanguage() ``` #### GetLoc Retrieves a localized string by its key. ```csharp public static string GetLoc(string key) ``` - **key** (string) - The localization key. - Returns: The localized string. #### LoadCustomLanguage Loads a custom language file by its GUID. ```csharp public static void LoadCustomLanguage(string guid) ``` - **guid** (string) - The GUID of the custom language asset. #### BuildParams Builds a pipe-separated parameter string used by popup fields. ```csharp public static string BuildParams(params string[] values) ``` - **values** (string[]) - An array of strings to join. - Returns: A pipe-separated string. #### SelectLang Shows a language selector dropdown in an editor window. ```csharp public static void SelectLang() ``` ### Usage Example ```csharp // Initialize or refresh language (called automatically on inspector load) lilLanguageManager.UpdateLanguage(); // Retrieve a localized string by key string label = lilLanguageManager.GetLoc("sGradColor"); // Returns "Grad Color" (en-US) or "グラデーションカラー" (ja-JP) // Load a custom language file by GUID lilLanguageManager.LoadCustomLanguage("your-asset-guid-here"); // Build a pipe-separated parameter string used by popup fields string blendModes = lilLanguageManager.BuildParams("Normal", "Add", "Screen", "Multiply"); // "Normal|Add|Screen|Multiply" // Show a language selector dropdown in an editor window lilLanguageManager.SelectLang(); ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.