From 35b39df95d8650fee92f778c79687d57bd489510 Mon Sep 17 00:00:00 2001 From: notargs Date: Thu, 27 Apr 2023 14:31:14 +0900 Subject: [PATCH] =?UTF-8?q?AdditionalLight=E3=81=8C=E7=A0=B4=E7=B6=BB?= =?UTF-8?q?=E3=81=97=E3=81=A6=E3=81=84=E3=81=9F=E5=95=8F=E9=A1=8C=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...vrmc_materials_mtoon_forward_fragment.hlsl | 2 +- .../vrmc_materials_mtoon_lighting_mtoon.hlsl | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) 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