Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
lilToon
https://lilxyzw.github.io/lilToon/
Admin
lilToon is a feature-rich shader for avatars, developed for services using avatars.
Tokens:
17,808
Snippets:
156
Trust Score:
9.7
Update:
3 months ago
Context
Chat
Benchmark
45
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### ピクセルシェーダーへの処理挿入 Source: https://lilxyzw.github.io/lilToon/ja_JP/dev/custom_shader.html BEFORE_UNPACK_V2Fキーワードを使用してv2f構造体の展開処理にカスタムコードを挿入する例です。 ```hlsl #define BEFORE_UNPACK_V2F \ fd.uv0 = input.uv0; ``` -------------------------------- ### 頂点シェーダーへの処理挿入 Source: https://lilxyzw.github.io/lilToon/ja_JP/dev/custom_shader.html LIL_CUSTOM_VERTEX_OSマクロを使用して、オブジェクト空間での頂点変形処理を挿入します。 ```hlsl #define LIL_CUSTOM_VERTEX_OS \ float3 customWaveStrength = LIL_SAMPLE_2D_LOD(_CustomVertexWaveMask, sampler_linear_repeat, input.uv0, 0).r * _CustomVertexWaveStrength.xyz; \ positionOS.xyz += sin(LIL_TIME * _CustomVertexWaveSpeed + dot(positionOS.xyz, _CustomVertexWaveScale.xyz)) * customWaveStrength; ``` -------------------------------- ### トランスフォーム関数と行列 Source: https://lilxyzw.github.io/lilToon/ja_JP/dev/utilities.html 座標空間の変換や行列取得に使用する関数および定数。 ```HLSL LIL_MATRIX_M ``` ```HLSL LIL_MATRIX_I_M ``` ```HLSL LIL_MATRIX_V ``` ```HLSL LIL_MATRIX_P ``` ```HLSL LIL_MATRIX_VP ``` ```HLSL float3 lilTransformOStoWS(float4 positionOS) ``` ```HLSL float3 lilTransformOStoWS(float3 positionOS) ``` ```HLSL float3 lilTransformWStoOS(float3 positionWS) ``` ```HLSL float3 lilTransformWStoVS(float3 positionWS) ``` ```HLSL float4 lilTransformWStoCS(float3 positionWS) ``` ```HLSL float4 lilTransformVStoCS(float3 positionVS) ``` ```HLSL float4 lilTransformCStoSS(float4 positionCS) ``` ```HLSL float4 lilTransformCStoSSFrag(float4 positionCS) ``` ```HLSL float3 lilToAbsolutePositionWS(float3 positionRWS) ``` ```HLSL float3 lilTransformDirOStoWS(float3 directionOS, bool doNormalize) ``` ```HLSL float3 lilTransformDirWStoOS(float3 directionWS, bool doNormalize) ``` ```HLSL float3 lilTransformNormalOStoWS(float3 normalOS, bool doNormalize) ``` ```HLSL float3 lilViewDirection(float3 positionWS) ``` ```HLSL float3 lilHeadDirection(float3 positionWS) ``` ```HLSL float2 lilCStoGrabUV(float4 positionCS) ``` -------------------------------- ### カスタムシェーダーの基本構造 Source: https://lilxyzw.github.io/lilToon/ja_JP/dev/custom_shader_format.html lilcontainerファイルの基本的な記述例です。lilPropertiesやlilSubShaderBRPなどの独自タグを使用してシェーダーを構成します。 ```ShaderLab Shader "*LIL_SHADER_NAME*" { Properties { // lilToon標準プロパティが挿入される lilProperties "Default" lilProperties "DefaultOpaque" // カスタムプロパティは直接書くかテキストファイルから読み込む lilProperties "Properties.lilblock" } HLSLINCLUDE ENDHLSL // シェーダー設定挿入のスキップ //lilSkipSettings // SubShader内のTags lilSubShaderTags {"RenderType" = "Opaque" "Queue" = "Geometry"} // 各Pass内でUnityのライブラリをincludeした後に挿入されるテキスト //lilSubShaderInsert "SubShaderInsert.lilblock" // SubShaderをテキストファイルかキーワードから呼び出す lilSubShaderBRP "DefaultMulti" lilSubShaderURP "DefaultMulti" lilSubShaderHDRP "DefaultMulti" //lilSubShaderBRP "BRP.lilblock" //lilSubShaderURP "URP.lilblock" //lilSubShaderHDRP "HDRP.lilblock" // カスタムエディタの指定 CustomEditor "*LIL_EDITOR_NAME*" } ``` -------------------------------- ### マテリアルプロパティの追加 Source: https://lilxyzw.github.io/lilToon/ja_JP/dev/custom_shader.html lilCustomShaderProperties.lilblock内にShaderLabs形式でプロパティを定義します。 ```hlsl //---------------------------------------------------------------------------------------------------------------------- // Custom [lilVec3] _CustomVertexWaveScale ("Vertex Wave Scale", Vector) = (10.0,10.0,10.0,0.0) [lilVec3] _CustomVertexWaveStrength ("Vertex Wave Strength", Vector) = (0.0,0.1,0.0,0.0) _CustomVertexWaveSpeed ("Vertex Wave Speed", float) = 10.0 [NoScaleOffset] _CustomVertexWaveMask ("Vertex Wave Mask", 2D) = "white" {} ``` -------------------------------- ### カスタムプロパティとテクスチャの定義 Source: https://lilxyzw.github.io/lilToon/ja_JP/dev/custom_shader.html custom.hlsl内でマクロを使用して、追加したプロパティやテクスチャをシェーダーに登録します。 ```hlsl #define LIL_CUSTOM_PROPERTIES \ float4 _CustomVertexWaveScale; \ float4 _CustomVertexWaveStrength; \ float _CustomVertexWaveSpeed; #define LIL_CUSTOM_TEXTURES \ TEXTURE2D(_CustomVertexWaveMask); ``` -------------------------------- ### ライティング計算式の実装例 Source: https://lilxyzw.github.io/lilToon/ja_JP/base/lighting.html OpenLitライブラリに基づく、明るさ制限、モノクロ化、Unlit化、およびライト方向のオーバーライド処理の簡略化された実装です。 ```hlsl // 色の計算 RGB = clamp(RGB, _LightMinLimit, _LightMaxLimit); // "明るさの下限" から "明るさの上限" の範囲内に抑える Mono = (RGB.r + RGB.g + RGB.b) / 3.0; // RGBの平均値をとって単色化 RGB = lerp(RGB, Mono, _MonochromeLighting); // "ライトのモノクロ化" の分だけ単色に近づける RGB = lerp(RGB, 1.0, _AsUnlit); // "Unlit化" の分だけ1.0(白)に近づける // 方向の計算 if(_FollowObject) // "オブジェクトの向きに追従" する場合だけ行列計算を行う { _LightDirectionOverride = length(_LightDirectionOverride) * normalize(mul((float3x3)UNITY_MATRIX_M, _LightDirectionOverride)); } Direction = normalize(Direction + _LightDirectionOverride); // 元のライト方向と "ライト方向のオーバーライド" を合成 ``` -------------------------------- ### InsertPassPreの優先順位設定 Source: https://lilxyzw.github.io/lilToon/ja_JP/dev/custom_shader_format.html lilCustomShaderDatas.lilblock内でPassの挿入順序を制御する例です。後に記述したものが優先されます。 ```text InsertPassPre "PrePass.lilblock" InsertPassPre "lite" "PrePassLite.lilblock" InsertPassPre "Multi" "PrePassMulti.lilblock" ``` -------------------------------- ### lilToonMultiで使用されるシェーダーキーワード Source: https://lilxyzw.github.io/lilToon/ja_JP/dev/shader_structure.html Built-inシェーダーのキーワード枯渇を回避し、VRCSDKでの警告を防ぐために使用されるキーワードリストです。 ```text ETC1_EXTERNAL_ALPHA UNITY_UI_ALPHACLIP UNITY_UI_CLIP_RECT EFFECT_HUE_VARIATION _COLORADDSUBDIFF_ON _COLORCOLOR_ON _SUNDISK_NONE GEOM_TYPE_FROND _COLOROVERLAY_ON _REQUIRE_UV2 ANTI_FLICKER _EMISSION GEOM_TYPE_BRANCH _SUNDISK_SIMPLE _NORMALMAP EFFECT_BUMP _GLOSSYREFLECTIONS_OFF _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A _SPECULARHIGHLIGHTS_OFF GEOM_TYPE_MESH _METALLICGLOSSMAP GEOM_TYPE_LEAF _SPECGLOSSMAP _PARALLAXMAP PIXELSNAP_ON _FADING_ON _MAPPING_6_FRAMES_LAYOUT _SUNDISK_HIGH_QUALITY GEOM_TYPE_BRANCH_DETAIL _DETAIL_MULX2 ``` -------------------------------- ### 頂点法線・接線トランスフォーム Source: https://lilxyzw.github.io/lilToon/ja_JP/dev/utilities.html 法線および接線ベクトルの変換用マクロ。 ```HLSL LIL_VERTEX_NORMAL_TANGENT_INPUTS(float3 normalOS, float4 tangentOS, out vertexNormalInput) ``` ```HLSL vertexNormalInput.tangentWS ``` ```HLSL vertexNormalInput.bitangentWS ``` ```HLSL vertexNormalInput.normalWS ``` -------------------------------- ### 頂点座標トランスフォーム Source: https://lilxyzw.github.io/lilToon/ja_JP/dev/utilities.html 頂点入力の座標変換および再計算用マクロ。 ```HLSL LIL_VERTEX_POSITION_INPUTS(float4 positionOS, out vertexInput) ``` ```HLSL LIL_RE_VERTEX_POSITION_INPUTS(vertexInput) ``` ```HLSL vertexInput.positionWS ``` ```HLSL vertexInput.positionVS ``` ```HLSL vertexInput.positionCS ``` ```HLSL vertexInput.positionSS ``` -------------------------------- ### 影色の計算ロジック Source: https://lilxyzw.github.io/lilToon/ja_JP/color/shadow.html 影色がメインカラー、テクスチャ、環境光の影響を受けて算出される過程を示すHLSLコードです。 ```HLSL float4 shadowColorTex = tex2D(_ShadowColorTex, uv); // 影色テクスチャ float3 indirectCol = lerp(mainColor.rgb, shadowColorTex.rgb, shadowColorTex.a); // メインカラーと影色テクスチャをブレンド indirectCol *= _ShadowColor.rgb; // 影色(カラーピッカー)を乗算 indirectCol = lerp(indirectCol, indirectCol * mainColor.rgb, _ShadowMainStrength); // メインカラーを更に乗算することでコントラストを強調 indirectCol = lerp(indirectCol, mainColor.rgb, environmentLight * _ShadowEnvStrength); // 環境光をブレンド ``` -------------------------------- ### lilSubShaderの利用可能なキーワード Source: https://lilxyzw.github.io/lilToon/ja_JP/dev/custom_shader_format.html lilSubShaderBRP/URP/HDRPでファイルパスの代わりに指定できるデフォルトのSubShaderキーワード一覧です。 ```text Default DefaultFakeShadow DefaultFur DefaultGem DefaultRefraction DefaultRefractionBlur DefaultTessellation DefaultLite DefaultMulti DefaultMultiOutline DefaultMultiFur DefaultMultiRefraction DefaultMultiGem DefaultUsePass DefaultUsePassOutline DefaultUsePassFurOnly DefaultUsePassOutlineOnly DefaultUsePassOverlay ``` -------------------------------- ### その他のユーティリティ関数 Source: https://lilxyzw.github.io/lilToon/ja_JP/dev/utilities.html UV計算や色の合成、ノーマルマップ展開などの補助関数。 ```HLSL float2 lilCalcUV(float2 uv, float4 tex_ST, float4 tex_ScrollRotate) ``` ```HLSL float3 lilBlendColor(float3 dstCol, float3 srcCol, float srcA, uint blendMode) ``` ```HLSL float3 lilUnpackNormalScale(float4 normalTex, float scale) ``` ```HLSL float lilTooning() ``` -------------------------------- ### lilPropertiesの利用可能なキーワード Source: https://lilxyzw.github.io/lilToon/ja_JP/dev/custom_shader_format.html lilPropertiesでファイルパスの代わりに指定できるデフォルトのプロパティセットキーワード一覧です。 ```text Default DefaultLite DefaultOpaque DefaultCutout DefaultTransparent DefaultFurCutout DefaultFurTransparent DefaultRefraction DefaultGem DefaultFakeShadow ``` -------------------------------- ### Bug Report Template Source: https://lilxyzw.github.io/lilToon/ja_JP/other/qa.html A template to use when reporting bugs on GitHub to ensure all necessary information is provided. ```text バグ: 再現方法: # 可能であれば Unityバージョン: lilToonバージョン: VRChatのワールド: スクリーンショット: コンソールログ: ``` -------------------------------- ### Define SRP Version in lil_common_macro.hlsl Source: https://lilxyzw.github.io/lilToon/ja_JP/other/qa.html Manually specify the shader library version for older SRP versions where automatic detection fails. ```hlsl #define SHADER_LIBRARY_VERSION_MAJOR 4 #define SHADER_LIBRARY_VERSION_MINOR 8 ```