From 45f042d167bb0264d792ea241036cbd2548c1197 Mon Sep 17 00:00:00 2001 From: Thaina Date: Mon, 24 Feb 2025 16:35:44 +0700 Subject: [PATCH] Use SampleSH and set envLightColor as first light --- .../Shaders/UCTS_DoubleShadeWithFeather.cginc | 20 +++++----- .../Legacy/Shaders/UCTS_ShadingGradeMap.cginc | 16 ++++---- ...iversalToonBodyDoubleShadeWithFeather.hlsl | 38 +++++++++---------- .../UniversalToonBodyShadingGradeMap.hlsl | 28 +++++++------- 4 files changed, 51 insertions(+), 51 deletions(-) diff --git a/com.unity.toonshader/Runtime/Legacy/Shaders/UCTS_DoubleShadeWithFeather.cginc b/com.unity.toonshader/Runtime/Legacy/Shaders/UCTS_DoubleShadeWithFeather.cginc index 212560b1b..edcfcd0ba 100644 --- a/com.unity.toonshader/Runtime/Legacy/Shaders/UCTS_DoubleShadeWithFeather.cginc +++ b/com.unity.toonshader/Runtime/Legacy/Shaders/UCTS_DoubleShadeWithFeather.cginc @@ -1,6 +1,6 @@ //Unity Toon Shader/Legacy //nobuyuki@unity3d.com -//toshiyuki@unity3d.com (Intengrated) +//toshiyuki@unity3d.com (Intengrated) // ※Tessellation support // The corresponding code was adapted from Nora's https://github.com/Stereoarts/UnityChanToonShaderVer2_Tess. // @@ -49,7 +49,7 @@ struct VertexOutput { fixed3 DecodeLightProbe( fixed3 N ){ return ShadeSH9(float4(N,1)); } - + VertexOutput vert (VertexInput v) { VertexOutput o = (VertexOutput)0; @@ -88,7 +88,7 @@ struct VertexOutput { float4 frag(VertexOutput i, fixed facing : VFACE) : SV_TARGET { UNITY_SETUP_INSTANCE_ID(i); UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); - + i.normalDir = normalize(i.normalDir); float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir); float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); @@ -132,11 +132,11 @@ struct VertexOutput { float3 customLightDirection = normalize(mul( unity_ObjectToWorld, float4(((float3(1.0,0.0,0.0)*_Offset_X_Axis_BLD*10)+(float3(0.0,1.0,0.0)*_Offset_Y_Axis_BLD*10)+(float3(0.0,0.0,-1.0)*lerp(-1.0,1.0,_Inverse_Z_Axis_BLD))),0)).xyz); float3 lightDirection = normalize(lerp(defaultLightDirection,_WorldSpaceLightPos0.xyz,any(_WorldSpaceLightPos0.xyz))); lightDirection = lerp(lightDirection, customLightDirection, _Is_BLD); - //v.2.0.5: + //v.2.0.5: float3 lightColor = lerp(max(defaultLightColor,_LightColor0.rgb),max(defaultLightColor,saturate(_LightColor0.rgb)),_Is_Filter_LightColor); #elif _IS_PASS_FWDDELTA float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w)); - //v.2.0.5: + //v.2.0.5: float3 addPassLightColor = (0.5*dot(lerp( i.normalDir, normalDirection, _Is_NormalMapToBase ), lightDirection)+0.5) * _LightColor0.rgb * attenuation; float pureIntencity = max(0.001,(0.299*_LightColor0.r + 0.587*_LightColor0.g + 0.114*_LightColor0.b)); float3 lightColor = max(float3(0,0,0), lerp(addPassLightColor, lerp(float3(0,0,0),min(addPassLightColor,addPassLightColor/pureIntencity),_WorldSpaceLightPos0.w),_Is_Filter_LightColor)); @@ -168,7 +168,7 @@ struct VertexOutput { //Composition: 3 Basic Colors as Set_FinalBaseColor float3 Set_FinalBaseColor = lerp(Set_BaseColor,lerp(Set_1st_ShadeColor,Set_2nd_ShadeColor,saturate((1.0 + ( (_HalfLambert_var - (_ShadeColor_Step-_1st2nd_Shades_Feather)) * ((1.0 - _Set_2nd_ShadePosition_var.rgb).r - 1.0) ) / (_ShadeColor_Step - (_ShadeColor_Step-_1st2nd_Shades_Feather))))),Set_FinalShadowMask); // Final Color float4 _Set_HighColorMask_var = tex2D(_Set_HighColorMask, TRANSFORM_TEX(Set_UV0, _Set_HighColorMask)); - float _Specular_var = 0.5*dot(halfDirection,lerp( i.normalDir, normalDirection, _Is_NormalMapToHighColor ))+0.5; // Specular + float _Specular_var = 0.5*dot(halfDirection,lerp( i.normalDir, normalDirection, _Is_NormalMapToHighColor ))+0.5; // Specular float _TweakHighColorMask_var = (saturate((_Set_HighColorMask_var.g+_Tweak_HighColorMaskLevel))*lerp( (1.0 - step(_Specular_var,(1.0 - pow(_HighColor_Power,5)))), pow(_Specular_var,exp2(lerp(11,1,_HighColor_Power))), _Is_SpecularToHighColor )); float4 _HighColor_Tex_var = tex2D(_HighColor_Tex, TRANSFORM_TEX(Set_UV0, _HighColor_Tex)); @@ -218,7 +218,7 @@ struct VertexOutput { float3 viewNormal = (mul(UNITY_MATRIX_V, float4(lerp( i.normalDir, mul( _NormalMapForMatCap_var.rgb, tangentTransform ).rgb, _Is_NormalMapForMatCap ),0))).rgb; float3 NormalBlend_MatcapUV_Detail = viewNormal.rgb * float3(-1,-1,1); float3 NormalBlend_MatcapUV_Base = (mul( UNITY_MATRIX_V, float4(viewDirection,0) ).rgb*float3(-1,-1,1)) + float3(0,0,1); - float3 noSknewViewNormal = NormalBlend_MatcapUV_Base*dot(NormalBlend_MatcapUV_Base, NormalBlend_MatcapUV_Detail)/NormalBlend_MatcapUV_Base.b - NormalBlend_MatcapUV_Detail; + float3 noSknewViewNormal = NormalBlend_MatcapUV_Base*dot(NormalBlend_MatcapUV_Base, NormalBlend_MatcapUV_Detail)/NormalBlend_MatcapUV_Base.b - NormalBlend_MatcapUV_Detail; float2 _ViewNormalAsMatCapUV = (lerp(noSknewViewNormal,viewNormal,_Is_Ortho).rg*0.5)+0.5; //v.2.0.7 float2 _Rot_MatCapUV_var = RotateUV((0.0 + ((_ViewNormalAsMatCapUV - (0.0+_Tweak_MatCapUV)) * (1.0 - 0.0) ) / ((1.0-_Tweak_MatCapUV) - (0.0+_Tweak_MatCapUV))), _Rot_MatCapUV_var_ang, float2(0.5, 0.5), 1.0); @@ -249,14 +249,14 @@ struct VertexOutput { // //v.2.0.6: GI_Intensity with Intensity Multiplier Filter float3 envLightColor = DecodeLightProbe(normalDirection) < float3(1,1,1) ? DecodeLightProbe(normalDirection) : float3(1,1,1); - float envLightIntensity = 0.299*envLightColor.r + 0.587*envLightColor.g + 0.114*envLightColor.b <1 ? (0.299*envLightColor.r + 0.587*envLightColor.g + 0.114*envLightColor.b) : 1; + float envLightIntensity = saturate(0.299*envLightColor.r + 0.587*envLightColor.g + 0.114*envLightColor.b); //v.2.0.7 #ifdef _EMISSIVE_SIMPLE float4 _Emissive_Tex_var = tex2D(_Emissive_Tex,TRANSFORM_TEX(Set_UV0, _Emissive_Tex)); float emissiveMask = _Emissive_Tex_var.a; emissive = _Emissive_Tex_var.rgb * _Emissive_Color.rgb * emissiveMask; #elif _EMISSIVE_ANIMATION - //v.2.0.7 Calculation View Coord UV for Scroll + //v.2.0.7 Calculation View Coord UV for Scroll float3 viewNormal_Emissive = (mul(UNITY_MATRIX_V, float4(i.normalDir,0))).xyz; float3 NormalBlend_Emissive_Detail = viewNormal_Emissive * float3(-1,-1,1); float3 NormalBlend_Emissive_Base = (mul( UNITY_MATRIX_V, float4(viewDirection,0)).xyz*float3(-1,-1,1)) + float3(0,0,1); @@ -322,7 +322,7 @@ struct VertexOutput { float4 _Set_HighColorMask_var = tex2D(_Set_HighColorMask, TRANSFORM_TEX(Set_UV0, _Set_HighColorMask)); - float _Specular_var = 0.5*dot(halfDirection,lerp( i.normalDir, normalDirection, _Is_NormalMapToHighColor ))+0.5; // Specular + float _Specular_var = 0.5*dot(halfDirection,lerp( i.normalDir, normalDirection, _Is_NormalMapToHighColor ))+0.5; // Specular float _TweakHighColorMask_var = (saturate((_Set_HighColorMask_var.g+_Tweak_HighColorMaskLevel))*lerp( (1.0 - step(_Specular_var,(1.0 - pow(_HighColor_Power,5)))), pow(_Specular_var,exp2(lerp(11,1,_HighColor_Power))), _Is_SpecularToHighColor )); float4 _HighColor_Tex_var = tex2D(_HighColor_Tex, TRANSFORM_TEX(Set_UV0, _HighColor_Tex)); diff --git a/com.unity.toonshader/Runtime/Legacy/Shaders/UCTS_ShadingGradeMap.cginc b/com.unity.toonshader/Runtime/Legacy/Shaders/UCTS_ShadingGradeMap.cginc index ab8bc4434..22d96f302 100644 --- a/com.unity.toonshader/Runtime/Legacy/Shaders/UCTS_ShadingGradeMap.cginc +++ b/com.unity.toonshader/Runtime/Legacy/Shaders/UCTS_ShadingGradeMap.cginc @@ -1,6 +1,6 @@ //Unity Toon Shader/Legacy //nobuyuki@unity3d.com -//toshiyuki@unity3d.com (Intengrated) +//toshiyuki@unity3d.com (Intengrated) // ※Tessellation support // The corresponding code was adapted from Nora's https://github.com/Stereoarts/UnityChanToonShaderVer2_Tess. @@ -99,7 +99,7 @@ struct VertexOutput { TRANSFER_VERTEX_TO_FRAGMENT(o) return o; } - + //Tessellation ON #ifdef TESSELLATION_ON #ifdef UNITY_CAN_COMPILE_TESSELLATION @@ -115,7 +115,7 @@ struct VertexOutput { float4 frag(VertexOutput i, fixed facing : VFACE) : SV_TARGET { UNITY_SETUP_INSTANCE_ID(i); UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); - + i.normalDir = normalize(i.normalDir); float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir); float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); @@ -151,11 +151,11 @@ struct VertexOutput { float3 customLightDirection = normalize(mul( unity_ObjectToWorld, float4(((float3(1.0,0.0,0.0)*_Offset_X_Axis_BLD*10)+(float3(0.0,1.0,0.0)*_Offset_Y_Axis_BLD*10)+(float3(0.0,0.0,-1.0)*lerp(-1.0,1.0,_Inverse_Z_Axis_BLD))),0)).xyz); float3 lightDirection = normalize(lerp(defaultLightDirection,_WorldSpaceLightPos0.xyz,any(_WorldSpaceLightPos0.xyz))); lightDirection = lerp(lightDirection, customLightDirection, _Is_BLD); - //v.2.0.5: + //v.2.0.5: float3 lightColor = lerp(max(defaultLightColor,_LightColor0.rgb),max(defaultLightColor,saturate(_LightColor0.rgb)),_Is_Filter_LightColor); #elif _IS_PASS_FWDDELTA float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w)); - //v.2.0.5: + //v.2.0.5: float3 addPassLightColor = (0.5*dot(lerp( i.normalDir, normalDirection, _Is_NormalMapToBase ), lightDirection)+0.5) * _LightColor0.rgb * attenuation; float pureIntencity = max(0.001,(0.299*_LightColor0.r + 0.587*_LightColor0.g + 0.114*_LightColor0.b)); float3 lightColor = max(float3(0,0,0), lerp(addPassLightColor, lerp(float3(0,0,0),min(addPassLightColor,addPassLightColor/pureIntencity),_WorldSpaceLightPos0.w),_Is_Filter_LightColor)); @@ -242,7 +242,7 @@ struct VertexOutput { float3 viewNormal = (mul(UNITY_MATRIX_V, float4(lerp( i.normalDir, mul( _NormalMapForMatCap_var.rgb, tangentTransform ).rgb, _Is_NormalMapForMatCap ),0))).rgb; float3 NormalBlend_MatcapUV_Detail = viewNormal.rgb * float3(-1,-1,1); float3 NormalBlend_MatcapUV_Base = (mul( UNITY_MATRIX_V, float4(viewDirection,0) ).rgb*float3(-1,-1,1)) + float3(0,0,1); - float3 noSknewViewNormal = NormalBlend_MatcapUV_Base*dot(NormalBlend_MatcapUV_Base, NormalBlend_MatcapUV_Detail)/NormalBlend_MatcapUV_Base.b - NormalBlend_MatcapUV_Detail; + float3 noSknewViewNormal = NormalBlend_MatcapUV_Base*dot(NormalBlend_MatcapUV_Base, NormalBlend_MatcapUV_Detail)/NormalBlend_MatcapUV_Base.b - NormalBlend_MatcapUV_Detail; float2 _ViewNormalAsMatCapUV = (lerp(noSknewViewNormal,viewNormal,_Is_Ortho).rg*0.5)+0.5; // //v.2.0.7 @@ -295,7 +295,7 @@ struct VertexOutput { float emissiveMask = _Emissive_Tex_var.a; emissive = _Emissive_Tex_var.rgb * _Emissive_Color.rgb * emissiveMask; #elif _EMISSIVE_ANIMATION - //v.2.0.7 Calculation View Coord UV for Scroll + //v.2.0.7 Calculation View Coord UV for Scroll float3 viewNormal_Emissive = (mul(UNITY_MATRIX_V, float4(i.normalDir,0))).xyz; float3 NormalBlend_Emissive_Detail = viewNormal_Emissive * float3(-1,-1,1); float3 NormalBlend_Emissive_Base = (mul( UNITY_MATRIX_V, float4(viewDirection,0)).xyz*float3(-1,-1,1)) + float3(0,0,1); @@ -329,7 +329,7 @@ struct VertexOutput { // //v.2.0.6: GI_Intensity with Intensity Multiplier Filter float3 envLightColor = DecodeLightProbe(normalDirection) < float3(1,1,1) ? DecodeLightProbe(normalDirection) : float3(1,1,1); - float envLightIntensity = 0.299*envLightColor.r + 0.587*envLightColor.g + 0.114*envLightColor.b <1 ? (0.299*envLightColor.r + 0.587*envLightColor.g + 0.114*envLightColor.b) : 1; + float envLightIntensity = saturate(0.299*envLightColor.r + 0.587*envLightColor.g + 0.114*envLightColor.b); //Final Composition finalColor = saturate(finalColor) + (envLightColor*envLightIntensity*_GI_Intensity*smoothstep(1,0,envLightIntensity/2)) + emissive; diff --git a/com.unity.toonshader/Runtime/UniversalRP/Shaders/UniversalToonBodyDoubleShadeWithFeather.hlsl b/com.unity.toonshader/Runtime/UniversalRP/Shaders/UniversalToonBodyDoubleShadeWithFeather.hlsl index 80d8768e3..64ca5785a 100644 --- a/com.unity.toonshader/Runtime/UniversalRP/Shaders/UniversalToonBodyDoubleShadeWithFeather.hlsl +++ b/com.unity.toonshader/Runtime/UniversalRP/Shaders/UniversalToonBodyDoubleShadeWithFeather.hlsl @@ -1,6 +1,6 @@ //Unity Toon Shader/Universal //nobuyuki@unity3d.com -//toshiyuki@unity3d.com (Universal RP/HDRP) +//toshiyuki@unity3d.com (Universal RP/HDRP) @@ -47,7 +47,7 @@ # endif input.uv = i.uv0; input.positionCS = i.pos; -# if defined(_ADDITIONAL_LIGHTS_VERTEX) || (VERSION_LOWER(12, 0)) +# if defined(_ADDITIONAL_LIGHTS_VERTEX) || (VERSION_LOWER(12, 0)) input.fogFactorAndVertexLight = i.fogFactorAndVertexLight; # else @@ -70,9 +70,9 @@ # endif # else //ifdef _NORMALMAP input.normalWS = half3(i.normalDir); - #if (VERSION_LOWER(12, 0)) + #if (VERSION_LOWER(12, 0)) input.viewDirWS = half3(viewDirection); - #endif // #if (VERSION_LOWER(12, 0)) + #endif // #if (VERSION_LOWER(12, 0)) # endif InitializeInputData(input, surfaceData.normalTS, inputData); @@ -106,7 +106,7 @@ #endif //v.2.0.4 -#if defined(_IS_CLIPPING_MODE) +#if defined(_IS_CLIPPING_MODE) //DoubleShadeWithFeather_Clipping float4 _ClippingMask_var = SAMPLE_TEXTURE2D(_ClippingMask, sampler_MainTex, TRANSFORM_TEX(Set_UV0, _MainTex)); float Set_Clipping = saturate((lerp( _ClippingMask_var.r, (1.0 - _ClippingMask_var.r), _Inverse_Clipping )+_Clipping_Level)); @@ -142,7 +142,7 @@ float3 customLightDirection = normalize(mul( GetObjectToWorldMatrix(), float4(((float3(1.0,0.0,0.0)*_Offset_X_Axis_BLD*10)+(float3(0.0,1.0,0.0)*_Offset_Y_Axis_BLD*10)+(float3(0.0,0.0,-1.0)*lerp(-1.0,1.0,_Inverse_Z_Axis_BLD))),0)).xyz); float3 lightDirection = normalize(lerp(defaultLightDirection, mainLight.direction.xyz,any(mainLight.direction.xyz))); lightDirection = lerp(lightDirection, customLightDirection, _Is_BLD); - //v.2.0.5: + //v.2.0.5: half3 originalLightColor = mainLightColor.rgb; @@ -179,7 +179,7 @@ float4 _Set_HighColorMask_var = tex2D(_Set_HighColorMask, TRANSFORM_TEX(Set_UV0, _Set_HighColorMask)); - float _Specular_var = 0.5*dot(halfDirection,lerp( i.normalDir, normalDirection, _Is_NormalMapToHighColor ))+0.5; // Specular + float _Specular_var = 0.5*dot(halfDirection,lerp( i.normalDir, normalDirection, _Is_NormalMapToHighColor ))+0.5; // Specular float _TweakHighColorMask_var = (saturate((_Set_HighColorMask_var.g+_Tweak_HighColorMaskLevel))*lerp( (1.0 - step(_Specular_var,(1.0 - pow(abs(_HighColor_Power),5)))), pow(abs(_Specular_var),exp2(lerp(11,1,_HighColor_Power))), _Is_SpecularToHighColor )); float4 _HighColor_Tex_var = tex2D(_HighColor_Tex, TRANSFORM_TEX(Set_UV0, _HighColor_Tex)); @@ -231,7 +231,7 @@ float3 viewNormal = (mul(UNITY_MATRIX_V, float4(lerp( i.normalDir, mul( _NormalMapForMatCap_var.rgb, tangentTransform ).rgb, _Is_NormalMapForMatCap ),0))).rgb; float3 NormalBlend_MatcapUV_Detail = viewNormal.rgb * float3(-1,-1,1); float3 NormalBlend_MatcapUV_Base = (mul( UNITY_MATRIX_V, float4(viewDirection,0) ).rgb*float3(-1,-1,1)) + float3(0,0,1); - float3 noSknewViewNormal = NormalBlend_MatcapUV_Base*dot(NormalBlend_MatcapUV_Base, NormalBlend_MatcapUV_Detail)/NormalBlend_MatcapUV_Base.b - NormalBlend_MatcapUV_Detail; + float3 noSknewViewNormal = NormalBlend_MatcapUV_Base*dot(NormalBlend_MatcapUV_Base, NormalBlend_MatcapUV_Detail)/NormalBlend_MatcapUV_Base.b - NormalBlend_MatcapUV_Detail; float2 _ViewNormalAsMatCapUV = (lerp(noSknewViewNormal,viewNormal,_Is_Ortho).rg*0.5)+0.5; //v.2.0.7 float2 _Rot_MatCapUV_var = RotateUV((0.0 + ((_ViewNormalAsMatCapUV - (0.0+_Tweak_MatCapUV)) * (1.0 - 0.0) ) / ((1.0-_Tweak_MatCapUV) - (0.0+_Tweak_MatCapUV))), _Rot_MatCapUV_var_ang, float2(0.5, 0.5), 1.0); @@ -264,12 +264,12 @@ // //v.2.0.6: GI_Intensity with Intensity Multiplier Filter - float3 envLightColor = envColor.rgb; + float3 envLightColor = envColor.rgb + SampleSH(normalDirection); - float envLightIntensity = 0.299*envLightColor.r + 0.587*envLightColor.g + 0.114*envLightColor.b <1 ? (0.299*envLightColor.r + 0.587*envLightColor.g + 0.114*envLightColor.b) : 1; + float envLightIntensity = saturate(0.299*envLightColor.r + 0.587*envLightColor.g + 0.114*envLightColor.b); - float3 pointLightColor = 0; + float3 pointLightColor = envLightColor*envLightIntensity*_GI_Intensity*smoothstep(1,0,envLightIntensity/2); #ifdef _ADDITIONAL_LIGHTS int pixelLightCount = GetAdditionalLightsCount(); @@ -295,7 +295,7 @@ float3 lightDirection = additionalLight.direction; - //v.2.0.5: + //v.2.0.5: float3 addPassLightColor = (0.5*dot(lerp(i.normalDir, normalDirection, _Is_NormalMapToBase), lightDirection) + 0.5) * additionalLightColor.rgb; float pureIntencity = max(0.001, (0.299*additionalLightColor.r + 0.587*additionalLightColor.g + 0.114*additionalLightColor.b)); float3 lightColor = max(float3(0.0,0.0,0.0), lerp(addPassLightColor, lerp(float3(0.0,0.0,0.0), min(addPassLightColor, addPassLightColor / pureIntencity), notDirectional), _Is_Filter_LightColor)); @@ -332,7 +332,7 @@ float4 _Set_HighColorMask_var = tex2D(_Set_HighColorMask, TRANSFORM_TEX(Set_UV0, _Set_HighColorMask)); - float _Specular_var = 0.5*dot(halfDirection, lerp(i.normalDir, normalDirection, _Is_NormalMapToHighColor)) + 0.5; // Specular + float _Specular_var = 0.5*dot(halfDirection, lerp(i.normalDir, normalDirection, _Is_NormalMapToHighColor)) + 0.5; // Specular float _TweakHighColorMask_var = (saturate((_Set_HighColorMask_var.g + _Tweak_HighColorMaskLevel))*lerp((1.0 - step(_Specular_var, (1.0 - pow(_HighColor_Power, 5)))), pow(_Specular_var, exp2(lerp(11, 1, _HighColor_Power))), _Is_SpecularToHighColor)); float4 _HighColor_Tex_var = tex2D(_HighColor_Tex, TRANSFORM_TEX(Set_UV0, _HighColor_Tex)); @@ -379,7 +379,7 @@ float3 lightDirection = additionalLight.direction; - //v.2.0.5: + //v.2.0.5: float3 addPassLightColor = (0.5*dot(lerp(i.normalDir, normalDirection, _Is_NormalMapToBase), lightDirection) + 0.5) * additionalLightColor.rgb; float pureIntencity = max(0.001, (0.299*additionalLightColor.r + 0.587*additionalLightColor.g + 0.114*additionalLightColor.b)); float3 lightColor = max(float3(0.0,0.0,0.0), lerp(addPassLightColor, lerp(float3(0.0,0.0,0.0), min(addPassLightColor, addPassLightColor / pureIntencity), notDirectional), _Is_Filter_LightColor)); @@ -416,7 +416,7 @@ float4 _Set_HighColorMask_var = tex2D(_Set_HighColorMask, TRANSFORM_TEX(Set_UV0, _Set_HighColorMask)); - float _Specular_var = 0.5*dot(halfDirection, lerp(i.normalDir, normalDirection, _Is_NormalMapToHighColor)) + 0.5; // Specular + float _Specular_var = 0.5*dot(halfDirection, lerp(i.normalDir, normalDirection, _Is_NormalMapToHighColor)) + 0.5; // Specular float _TweakHighColorMask_var = (saturate((_Set_HighColorMask_var.g + _Tweak_HighColorMaskLevel))*lerp((1.0 - step(_Specular_var, (1.0 - pow(_HighColor_Power, 5)))), pow(_Specular_var, exp2(lerp(11, 1, _HighColor_Power))), _Is_SpecularToHighColor)); float4 _HighColor_Tex_var = tex2D(_HighColor_Tex, TRANSFORM_TEX(Set_UV0, _HighColor_Tex)); @@ -432,7 +432,7 @@ // pointLightColor += lightColor; } UTS_LIGHT_LOOP_END - + #endif @@ -442,7 +442,7 @@ float emissiveMask = _Emissive_Tex_var.a; emissive = _Emissive_Tex_var.rgb * _Emissive_Color.rgb * emissiveMask; #elif _EMISSIVE_ANIMATION - //v.2.0.7 Calculation View Coord UV for Scroll + //v.2.0.7 Calculation View Coord UV for Scroll float3 viewNormal_Emissive = (mul(UNITY_MATRIX_V, float4(i.normalDir,0))).xyz; float3 NormalBlend_Emissive_Detail = viewNormal_Emissive * float3(-1,-1,1); float3 NormalBlend_Emissive_Base = (mul( UNITY_MATRIX_V, float4(viewDirection,0)).xyz*float3(-1,-1,1)) + float3(0,0,1); @@ -474,8 +474,8 @@ emissive = emissive_Color.rgb * _Emissive_Tex_var.rgb * emissiveMask; #endif - //Final Composition#if - finalColor = SATURATE_IF_SDR(finalColor) + (envLightColor*envLightIntensity*_GI_Intensity*smoothstep(1,0,envLightIntensity/2)) + emissive; + //Final Composition#if + finalColor = SATURATE_IF_SDR(finalColor) + emissive; finalColor += pointLightColor; diff --git a/com.unity.toonshader/Runtime/UniversalRP/Shaders/UniversalToonBodyShadingGradeMap.hlsl b/com.unity.toonshader/Runtime/UniversalRP/Shaders/UniversalToonBodyShadingGradeMap.hlsl index 98eea9122..061b934fa 100644 --- a/com.unity.toonshader/Runtime/UniversalRP/Shaders/UniversalToonBodyShadingGradeMap.hlsl +++ b/com.unity.toonshader/Runtime/UniversalRP/Shaders/UniversalToonBodyShadingGradeMap.hlsl @@ -1,6 +1,6 @@ //Unity Toon Shader/Universal //nobuyuki@unity3d.com -//toshiyuki@unity3d.com (Universal RP/HDRP) +//toshiyuki@unity3d.com (Universal RP/HDRP) @@ -44,7 +44,7 @@ # endif input.uv = i.uv0; input.positionCS = i.pos; -# if defined(_ADDITIONAL_LIGHTS_VERTEX) || (VERSION_LOWER(12, 0)) +# if defined(_ADDITIONAL_LIGHTS_VERTEX) || (VERSION_LOWER(12, 0)) input.fogFactorAndVertexLight = i.fogFactorAndVertexLight; # else @@ -130,7 +130,7 @@ float3 customLightDirection = normalize(mul( GetObjectToWorldMatrix(), float4(((float3(1.0,0.0,0.0)*_Offset_X_Axis_BLD*10)+(float3(0.0,1.0,0.0)*_Offset_Y_Axis_BLD*10)+(float3(0.0,0.0,-1.0)*lerp(-1.0,1.0,_Inverse_Z_Axis_BLD))),0)).xyz); float3 lightDirection = normalize(lerp(defaultLightDirection, mainLight.direction.xyz,any(mainLight.direction.xyz))); lightDirection = lerp(lightDirection, customLightDirection, _Is_BLD); - //v.2.0.5: + //v.2.0.5: half3 originalLightColor = mainLightColor.rgb; @@ -235,7 +235,7 @@ float3 viewNormal = (mul(UNITY_MATRIX_V, float4(lerp( i.normalDir, mul( _NormalMapForMatCap_var.rgb, tangentTransform ).rgb, _Is_NormalMapForMatCap ),0))).rgb; float3 NormalBlend_MatcapUV_Detail = viewNormal.rgb * float3(-1,-1,1); float3 NormalBlend_MatcapUV_Base = (mul( UNITY_MATRIX_V, float4(viewDirection,0) ).rgb*float3(-1,-1,1)) + float3(0,0,1); - float3 noSknewViewNormal = NormalBlend_MatcapUV_Base*dot(NormalBlend_MatcapUV_Base, NormalBlend_MatcapUV_Detail)/NormalBlend_MatcapUV_Base.b - NormalBlend_MatcapUV_Detail; + float3 noSknewViewNormal = NormalBlend_MatcapUV_Base*dot(NormalBlend_MatcapUV_Base, NormalBlend_MatcapUV_Detail)/NormalBlend_MatcapUV_Base.b - NormalBlend_MatcapUV_Detail; float2 _ViewNormalAsMatCapUV = (lerp(noSknewViewNormal,viewNormal,_Is_Ortho).rg*0.5)+0.5; // //v.2.0.7 @@ -253,7 +253,7 @@ float4 _Set_MatcapMask_var = tex2D(_Set_MatcapMask, TRANSFORM_TEX(Set_UV0, _Set_MatcapMask)); - // + // //MatcapMask float _Tweak_MatcapMaskLevel_var = saturate(lerp(_Set_MatcapMask_var.g, (1.0 - _Set_MatcapMask_var.g), _Inverse_MatcapMask) + _Tweak_MatcapMaskLevel); float3 _Is_LightColor_MatCap_var = lerp( (_MatCap_Sampler_var.rgb*_MatCapColor.rgb), ((_MatCap_Sampler_var.rgb*_MatCapColor.rgb)*Set_LightColor), _Is_LightColor_MatCap ); @@ -293,7 +293,7 @@ float emissiveMask = _Emissive_Tex_var.a; emissive = _Emissive_Tex_var.rgb * _Emissive_Color.rgb * emissiveMask; #elif _EMISSIVE_ANIMATION - //v.2.0.7 Calculation View Coord UV for Scroll + //v.2.0.7 Calculation View Coord UV for Scroll float3 viewNormal_Emissive = (mul(UNITY_MATRIX_V, float4(i.normalDir,0))).xyz; float3 NormalBlend_Emissive_Detail = viewNormal_Emissive * float3(-1,-1,1); float3 NormalBlend_Emissive_Base = (mul( UNITY_MATRIX_V, float4(viewDirection,0)).xyz*float3(-1,-1,1)) + float3(0,0,1); @@ -329,7 +329,7 @@ float3 envLightColor = envColor.rgb; - float envLightIntensity = 0.299*envLightColor.r + 0.587*envLightColor.g + 0.114*envLightColor.b <1 ? (0.299*envLightColor.r + 0.587*envLightColor.g + 0.114*envLightColor.b) : 1; + float envLightIntensity = saturate(0.299*envLightColor.r + 0.587*envLightColor.g + 0.114*envLightColor.b); @@ -355,7 +355,7 @@ ); float3 lightDirection = additionalLight.direction; - //v.2.0.5: + //v.2.0.5: float3 addPassLightColor = (0.5*dot(lerp(i.normalDir, normalDirection, _Is_NormalMapToBase), lightDirection) + 0.5) * additionalLightColor.rgb; float pureIntencity = max(0.001, (0.299*additionalLightColor.r + 0.587*additionalLightColor.g + 0.114*additionalLightColor.b)); float3 lightColor = max(float3(0.0,0.0,0.0), lerp(addPassLightColor, lerp(float3(0.0,0.0,0.0), min(addPassLightColor, addPassLightColor / pureIntencity), notDirectional), _Is_Filter_LightColor)); @@ -415,7 +415,7 @@ //v.2.0.6: Add HighColor if _Is_Filter_HiCutPointLightColor is False float4 _Set_HighColorMask_var = tex2D(_Set_HighColorMask, TRANSFORM_TEX(Set_UV0, _Set_HighColorMask)); - float _Specular_var = 0.5*dot(halfDirection, lerp(i.normalDir, normalDirection, _Is_NormalMapToHighColor)) + 0.5; // Specular + float _Specular_var = 0.5*dot(halfDirection, lerp(i.normalDir, normalDirection, _Is_NormalMapToHighColor)) + 0.5; // Specular float _TweakHighColorMask_var = (saturate((_Set_HighColorMask_var.g + _Tweak_HighColorMaskLevel))*lerp((1.0 - step(_Specular_var, (1.0 - pow(abs(_HighColor_Power), 5)))), pow(abs(_Specular_var), exp2(lerp(11, 1, _HighColor_Power))), _Is_SpecularToHighColor)); float4 _HighColor_Tex_var = tex2D(_HighColor_Tex, TRANSFORM_TEX(Set_UV0, _HighColor_Tex)); @@ -432,7 +432,7 @@ } #endif // USE_FORWARD_PLUS // determine main light inorder to apply light culling properly - + // when the loop counter start from negative value, MAINLIGHT_IS_MAINLIGHT = -1, some compiler doesn't work well. // for (int iLight = MAINLIGHT_IS_MAINLIGHT; iLight < pixelLightCount ; ++iLight) UTS_LIGHT_LOOP_BEGIN(pixelLightCount - MAINLIGHT_IS_MAINLIGHT) @@ -458,7 +458,7 @@ float3 lightDirection = additionalLight.direction; - //v.2.0.5: + //v.2.0.5: float3 addPassLightColor = (0.5*dot(lerp(i.normalDir, normalDirection, _Is_NormalMapToBase), lightDirection) + 0.5) * additionalLightColor.rgb; float pureIntencity = max(0.001, (0.299*additionalLightColor.r + 0.587*additionalLightColor.g + 0.114*additionalLightColor.b)); float3 lightColor = max(float3(0.0,0.0,0.0), lerp(addPassLightColor, lerp(float3(0.0,0.0,0.0), min(addPassLightColor, addPassLightColor / pureIntencity), notDirectional), _Is_Filter_LightColor)); @@ -510,9 +510,9 @@ // //Composition: 3 Basic Colors as finalColor - // float3 finalColor = + // float3 finalColor = // lerp( - // Set_BaseColor, + // Set_BaseColor, // lerp( // Set_1st_ShadeColor, // Set_2nd_ShadeColor, @@ -537,7 +537,7 @@ //v.2.0.6: Add HighColor if _Is_Filter_HiCutPointLightColor is False float4 _Set_HighColorMask_var = tex2D(_Set_HighColorMask, TRANSFORM_TEX(Set_UV0, _Set_HighColorMask)); - float _Specular_var = 0.5*dot(halfDirection, lerp(i.normalDir, normalDirection, _Is_NormalMapToHighColor)) + 0.5; // Specular + float _Specular_var = 0.5*dot(halfDirection, lerp(i.normalDir, normalDirection, _Is_NormalMapToHighColor)) + 0.5; // Specular float _TweakHighColorMask_var = (saturate((_Set_HighColorMask_var.g + _Tweak_HighColorMaskLevel))*lerp((1.0 - step(_Specular_var, (1.0 - pow(abs(_HighColor_Power), 5)))), pow(abs(_Specular_var), exp2(lerp(11, 1, _HighColor_Power))), _Is_SpecularToHighColor)); float4 _HighColor_Tex_var = tex2D(_HighColor_Tex, TRANSFORM_TEX(Set_UV0, _HighColor_Tex));