diff --git a/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader b/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader index b872ee783..e4c9fa555 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 "../UTSLighting.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) 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;