From 95b1e93160a862c18dbecf7e6781eb1534415638 Mon Sep 17 00:00:00 2001 From: sin Date: Tue, 3 Feb 2026 20:47:19 +0900 Subject: [PATCH 1/4] add ToonShading --- .../Runtime/Shaders/URP/ToonShading.hlsl | 25 +++++++++++++++++++ .../Runtime/Shaders/URP/ToonShading.hlsl.meta | 7 ++++++ 2 files changed, 32 insertions(+) create mode 100644 com.unity.toonshader/Runtime/Shaders/URP/ToonShading.hlsl create mode 100644 com.unity.toonshader/Runtime/Shaders/URP/ToonShading.hlsl.meta diff --git a/com.unity.toonshader/Runtime/Shaders/URP/ToonShading.hlsl b/com.unity.toonshader/Runtime/Shaders/URP/ToonShading.hlsl new file mode 100644 index 000000000..d1f23a0b4 --- /dev/null +++ b/com.unity.toonshader/Runtime/Shaders/URP/ToonShading.hlsl @@ -0,0 +1,25 @@ +#pragma once + + +float3 ThreeColorsLinearShading( + float3 baseColor, + float3 firstColor, + float3 secondColor, + float3 baseTo1stStart, // t=0: use base, t=1: transition + float3 baseTo1stFeather, + float3 firstToSecondStart, //t=0: use base, t=1: transition + float3 firstToSecondFeather, + float dotNL) // dot(N.L) +{ + const float t = saturate(1 - dotNL); //t = 0: light, t=1: dark shaded + + const float invBaseTo1stStart = 1 - baseTo1stStart; + const float invBaseTo2ndStart = 1 - firstToSecondStart; + + const float s1 = smoothstep(invBaseTo1stStart, invBaseTo1stStart + baseTo1stFeather,t); + const float s2 = smoothstep(invBaseTo2ndStart, invBaseTo2ndStart + firstToSecondFeather,t); + + float3 c01 = lerp(baseColor,firstColor, s1); + float3 c12 = lerp(c01, secondColor, s2); + return c12; +} \ No newline at end of file diff --git a/com.unity.toonshader/Runtime/Shaders/URP/ToonShading.hlsl.meta b/com.unity.toonshader/Runtime/Shaders/URP/ToonShading.hlsl.meta new file mode 100644 index 000000000..13590fcd8 --- /dev/null +++ b/com.unity.toonshader/Runtime/Shaders/URP/ToonShading.hlsl.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 2facb488425c31c42b7af0a397b270a6 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From 28041b91453abbf92c339a1d03a1d8e3c2a16802 Mon Sep 17 00:00:00 2001 From: sin Date: Tue, 3 Feb 2026 20:50:11 +0900 Subject: [PATCH 2/4] use ToonShading.hlsl --- .../Runtime/Shaders/URP/ToonURP_3Das2D.shader | 27 +------------------ 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader b/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader index b872ee783..f37f9c36f 100644 --- a/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader +++ b/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader @@ -53,7 +53,6 @@ Shader "Toon/Toon 3D as 2D (URP)"{ _OutlineFar ("Outline Far", Float ) = 100 _Outline_UseNormalMap ("Outline: Use Outline Normal Map", Integer ) = 0 _Outline_NormalMap ("Outline Normal Map", 2D) = "bump" {} - [HideInInspector] _ToonMaterialVersion ("Toon Material Version", Integer ) = 0 } @@ -169,6 +168,7 @@ Shader "Toon/Toon 3D as 2D (URP)"{ #include "ObjectTransform.hlsl" #include "ShapeLight2D.hlsl" + #include "ToonShading.hlsl" //_HDREmulationScale declaration #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/ShapeLightVariables.hlsl" @@ -193,31 +193,6 @@ Shader "Toon/Toon 3D as 2D (URP)"{ return o; } - - float3 ThreeColorsLinearShading( - float3 baseColor, - float3 firstColor, - float3 secondColor, - float3 baseTo1stStart, // t=0: use base, t=1: transition - float3 baseTo1stFeather, - float3 firstToSecondStart, //t=0: use base, t=1: transition - float3 firstToSecondFeather, - float dotNL) // dot(N.L) - { - const float t = saturate(1 - dotNL); //t = 0: light, t=1: dark shaded - - const float invBaseTo1stStart = 1 - baseTo1stStart; - const float invBaseTo2ndStart = 1 - firstToSecondStart; - - const float s1 = smoothstep(invBaseTo1stStart, invBaseTo1stStart + baseTo1stFeather,t); - const float s2 = smoothstep(invBaseTo2ndStart, invBaseTo2ndStart + firstToSecondFeather,t); - - float3 c01 = lerp(baseColor,firstColor, s1); - float3 c12 = lerp(c01, secondColor, s2); - return c12; - } - - half4 CombinedShapeLightAndToon(ShapeLightResult shapeLightResult, SurfaceData2D surfaceData, in float2 uv, in float3 tangentWS, in float3 bitangentWS, in float3 normalWS, in float3 positionWS) From c0a2dbeaa9a94f1e383860013227e0407ed4c6d2 Mon Sep 17 00:00:00 2001 From: sin Date: Tue, 3 Feb 2026 21:07:06 +0900 Subject: [PATCH 3/4] test --- .../Runtime/Shaders/UTSLighting.hlsl | 25 +++++++++++++++++++ ...iversalToonBodyDoubleShadeWithFeather.hlsl | 24 +++++++++++------- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/com.unity.toonshader/Runtime/Shaders/UTSLighting.hlsl b/com.unity.toonshader/Runtime/Shaders/UTSLighting.hlsl index 5c8feb723..d62bf809b 100644 --- a/com.unity.toonshader/Runtime/Shaders/UTSLighting.hlsl +++ b/com.unity.toonshader/Runtime/Shaders/UTSLighting.hlsl @@ -6,4 +6,29 @@ inline float Intensity(float3 lightColor) return 0.299 * lightColor.r + 0.587 * lightColor.g + 0.114 * lightColor.b; } +//---------------------------------------------------------------------------------------------------------------------- + +float3 ThreeColorsLinearShading( + float3 baseColor, + float3 firstColor, + float3 secondColor, + float3 baseTo1stStart, // t=0: use base, t=1: transition + float3 baseTo1stFeather, + float3 firstToSecondStart, //t=0: use base, t=1: transition + float3 firstToSecondFeather, + float dotNL) // dot(N.L) +{ + const float t = saturate(1 - dotNL); //t = 0: light, t=1: dark shaded + + const float invBaseTo1stStart = 1 - baseTo1stStart; + const float invBaseTo2ndStart = 1 - firstToSecondStart; + + const float s1 = smoothstep(invBaseTo1stStart, invBaseTo1stStart + baseTo1stFeather,t); + const float s2 = smoothstep(invBaseTo2ndStart, invBaseTo2ndStart + firstToSecondFeather,t); + + float3 c01 = lerp(baseColor,firstColor, s1); + float3 c12 = lerp(c01, secondColor, s2); + return c12; +} + #endif // UTS_LIGHTING_INCLUDED diff --git a/com.unity.toonshader/Runtime/UniversalRP/Shaders/UniversalToonBodyDoubleShadeWithFeather.hlsl b/com.unity.toonshader/Runtime/UniversalRP/Shaders/UniversalToonBodyDoubleShadeWithFeather.hlsl index 8bb590c2a..7e429b3ff 100644 --- a/com.unity.toonshader/Runtime/UniversalRP/Shaders/UniversalToonBodyDoubleShadeWithFeather.hlsl +++ b/com.unity.toonshader/Runtime/UniversalRP/Shaders/UniversalToonBodyDoubleShadeWithFeather.hlsl @@ -1,4 +1,3 @@ - #include "../../Shaders/UTSLighting.hlsl" void ToonShading( @@ -25,14 +24,21 @@ void ToonShading( float halfLambert = 0.5 * dot(lerp(vertexNormalWS, perturbedNormalWS, _Is_NormalMapToBase), lightDirection) + 0.5; //[TODO-sin: 2026-1-27] It looks like we only need one channel of firstShadePosTex - float Set_FinalShadowMask = saturate( - 1.0 + (lerp(halfLambert, halfLambert * saturate(tweakShadows), _Set_SystemShadowsToBase) - - baseStepMinusFeather) * ((1.0 - firstShadePosTex.rgb).r - 1.0) / (baseColorStep - baseStepMinusFeather)); - // - //Composition: 3 Basic Colors as Set_FinalBaseColor - float3 finalColor = lerp(Set_BaseColor, lerp(Set_1st_ShadeColor, Set_2nd_ShadeColor, - saturate(( 1.0 + (halfLambert - firstStepMinusFeather) * ((1.0 - secondShadePosTex.rgb).r - 1.0) - / (shadeColorStep - firstStepMinusFeather)))), Set_FinalShadowMask); + // float Set_FinalShadowMask = saturate( + // 1.0 + (lerp(halfLambert, halfLambert * saturate(tweakShadows), _Set_SystemShadowsToBase) + // - baseStepMinusFeather) * ((1.0 - firstShadePosTex.rgb).r - 1.0) / (baseColorStep - baseStepMinusFeather)); + + + const float dotNL = dot( perturbedNormalWS, lightDirection); + const float dotNL_01 = 0.5 * dotNL + 0.5; + float shadowFactor = lerp(1,tweakShadows,saturate(dotNL)); + + float3 finalColor = ThreeColorsLinearShading(Set_BaseColor, Set_1st_ShadeColor, Set_2nd_ShadeColor, + baseColorStep, _BaseShade_Feather, shadeColorStep, + _1st2nd_Shades_Feather, dotNL_01 * shadowFactor); + + float Set_FinalShadowMask = dotNL_01 * shadowFactor * firstShadePosTex.r; +/// float specular = 0.5 * dot(halfDirection, lerp(vertexNormalWS, perturbedNormalWS, _Is_NormalMapToHighColor)) + 0.5; From 55c0d11a4456f154f1d7afe4b8a876172318ef68 Mon Sep 17 00:00:00 2001 From: sin Date: Thu, 19 Feb 2026 22:59:39 +0900 Subject: [PATCH 4/4] remove hlsl --- .../Runtime/Shaders/URP/ToonShading.hlsl | 25 ------------------- .../Runtime/Shaders/URP/ToonShading.hlsl.meta | 7 ------ .../Runtime/Shaders/URP/ToonURP_3Das2D.shader | 2 +- 3 files changed, 1 insertion(+), 33 deletions(-) delete mode 100644 com.unity.toonshader/Runtime/Shaders/URP/ToonShading.hlsl delete mode 100644 com.unity.toonshader/Runtime/Shaders/URP/ToonShading.hlsl.meta diff --git a/com.unity.toonshader/Runtime/Shaders/URP/ToonShading.hlsl b/com.unity.toonshader/Runtime/Shaders/URP/ToonShading.hlsl deleted file mode 100644 index d1f23a0b4..000000000 --- a/com.unity.toonshader/Runtime/Shaders/URP/ToonShading.hlsl +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - - -float3 ThreeColorsLinearShading( - float3 baseColor, - float3 firstColor, - float3 secondColor, - float3 baseTo1stStart, // t=0: use base, t=1: transition - float3 baseTo1stFeather, - float3 firstToSecondStart, //t=0: use base, t=1: transition - float3 firstToSecondFeather, - float dotNL) // dot(N.L) -{ - const float t = saturate(1 - dotNL); //t = 0: light, t=1: dark shaded - - const float invBaseTo1stStart = 1 - baseTo1stStart; - const float invBaseTo2ndStart = 1 - firstToSecondStart; - - const float s1 = smoothstep(invBaseTo1stStart, invBaseTo1stStart + baseTo1stFeather,t); - const float s2 = smoothstep(invBaseTo2ndStart, invBaseTo2ndStart + firstToSecondFeather,t); - - float3 c01 = lerp(baseColor,firstColor, s1); - float3 c12 = lerp(c01, secondColor, s2); - return c12; -} \ No newline at end of file diff --git a/com.unity.toonshader/Runtime/Shaders/URP/ToonShading.hlsl.meta b/com.unity.toonshader/Runtime/Shaders/URP/ToonShading.hlsl.meta deleted file mode 100644 index 13590fcd8..000000000 --- a/com.unity.toonshader/Runtime/Shaders/URP/ToonShading.hlsl.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 2facb488425c31c42b7af0a397b270a6 -ShaderIncludeImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader b/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader index f37f9c36f..e4c9fa555 100644 --- a/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader +++ b/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader @@ -168,7 +168,7 @@ Shader "Toon/Toon 3D as 2D (URP)"{ #include "ObjectTransform.hlsl" #include "ShapeLight2D.hlsl" - #include "ToonShading.hlsl" + #include "../UTSLighting.hlsl" //_HDREmulationScale declaration #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/ShapeLightVariables.hlsl"