diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_fragment.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_fragment.hlsl index 8711d82f2..220c1ab42 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_fragment.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_fragment.hlsl @@ -61,7 +61,7 @@ half4 MToonFragment(const FragmentInput fragmentInput) : SV_Target for (uint lightIndex = 0u; lightIndex < pixelLightCount; ++lightIndex) { UnityLighting additionalUnityLighting = GetAdditionalUnityLighting(input, normalWS, lightIndex); - col.rgb += GetMToonLighting(additionalUnityLighting, mtoonInput).rgb; + col.rgb += GetMToonURPAdditionalLighting(additionalUnityLighting, mtoonInput).rgb; } #endif #endif diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl index d60367a02..24e32dbfb 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl @@ -211,4 +211,48 @@ half4 GetMToonLighting(const UnityLighting unityLight, const MToonInput input) } } +#ifdef MTOON_URP + +inline half GetMToonURPAdditionalLighting_Shadow(const UnityLighting lighting, const half dotNL) +{ + if (MToon_IsPbrCorrectOn()) + { + return lighting.directLightAttenuation.x * step(0, dotNL); + } + + return lighting.directLightAttenuation.x * 0.5 * (min(0, dotNL) + 1); +} + +inline half GetMToonURPAdditionalLighting_Shade(const UnityLighting lighting, const MToonInput input, const half dotNL) +{ + const half shadeShift = GetMToonLighting_Reflectance_ShadingShift(input); + const half shadeToony = _ShadingToonyFactor; + + if (MToon_IsPbrCorrectOn()) + { + const half shadeInput = dotNL; + return mtoon_linearstep(-1.0 + shadeToony, +1.0 - shadeToony, shadeInput + shadeShift); + } + + const half shadeInput = dotNL; + return mtoon_linearstep(-1.0 + shadeToony, +1.0 - shadeToony, shadeInput + shadeShift); +} + +half4 GetMToonURPAdditionalLighting(const UnityLighting unityLight, const MToonInput input) +{ + const half dotNL = GetMToonLighting_DotNL(unityLight, input); + const half shade = GetMToonURPAdditionalLighting_Shade(unityLight, input, dotNL); + const half shadow = GetMToonURPAdditionalLighting_Shadow(unityLight, dotNL); + + const half3 direct = GetMToonLighting_DirectLighting(unityLight, input, shade, shadow); + const half3 lighting = direct; + + const half3 baseCol = lighting; + + return half4(baseCol, input.alpha); +} + +#endif + + #endif