From f970da6f3a60c88875bfcb68d765de00dbb2ada3 Mon Sep 17 00:00:00 2001 From: notargs Date: Wed, 26 Apr 2023 17:47:44 +0900 Subject: [PATCH] =?UTF-8?q?AdditionalLight=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...vrmc_materials_mtoon_forward_fragment.hlsl | 9 +++++++ .../vrmc_materials_mtoon_lighting_unity.hlsl | 25 +++++++++++++++++++ 2 files changed, 34 insertions(+) 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 639874e0d..7685dff24 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 @@ -55,6 +55,15 @@ half4 MToonFragment(const FragmentInput fragmentInput) : SV_Target mtoonInput.alpha = alpha; half4 col = GetMToonLighting(unityLighting, mtoonInput); + #ifdef _ADDITIONAL_LIGHTS + uint pixelLightCount = GetAdditionalLightsCount(); + for (uint lightIndex = 0u; lightIndex < pixelLightCount; ++lightIndex) + { + UnityLighting additionalUnityLighting = GetAdditionalUnityLighting(input, normalWS, lightIndex); + col.rgb += GetMToonLighting(additionalUnityLighting, mtoonInput).rgb; + } + #endif + // Apply Fog #ifdef MTOON_URP float fogCoord = input.fogFactorAndVertexLight.x; diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_unity.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_unity.hlsl index 8e30886cd..0151a8166 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_unity.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_unity.hlsl @@ -77,4 +77,29 @@ UnityLighting GetUnityLighting(const Varyings input, const half3 normalWS) } } +#ifdef MTOON_URP +UnityLighting GetAdditionalUnityLighting(const Varyings input, const half3 normalWS, int lightIndex) +{ + // TODO: Duplicate in GetUnityLighting + #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) + float4 shadowCoord = input.shadowCoord; + #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) + float4 shadowCoord = TransformWorldToShadowCoord(input.positionWS); + #else + float4 shadowCoord = float4(0, 0, 0, 0); + #endif + + half4 shadowMask = SAMPLE_SHADOWMASK(input.lightmapUV); + Light light = GetAdditionalLight(lightIndex, input.positionWS, shadowMask); + + UnityLighting output; + output.indirectLight = 0; + output.indirectLightEqualized = 0; + output.directLightColor = light.color; + output.directLightDirection = light.direction; + output.directLightAttenuation = light.shadowAttenuation * light.distanceAttenuation; + return output; +} +#endif + #endif