From 6dd0fb4fd9a7bf746dbe7d822e051fd3d6e368c3 Mon Sep 17 00:00:00 2001 From: notargs Date: Thu, 11 May 2023 16:54:20 +0900 Subject: [PATCH] =?UTF-8?q?MTOON=5FLIGHT=5FDESCRIPTION=E3=82=92=E5=AE=9A?= =?UTF-8?q?=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vrmc_materials_mtoon_lighting_unity.hlsl | 42 ++++--------------- .../vrmc_materials_mtoon_render_pipeline.hlsl | 27 ++++++++++++ 2 files changed, 35 insertions(+), 34 deletions(-) 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 93b142124..acf7e7953 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 @@ -17,30 +17,7 @@ struct UnityLighting UnityLighting GetUnityLighting(const Varyings input, const half3 normalWS) { -#ifdef MTOON_URP - #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 mainLight = GetMainLight(shadowCoord, input.positionWS, shadowMask); - - const half3 lightDir = mainLight.direction; - const half3 lightColor = mainLight.color.rgb; - - float atten = mainLight.shadowAttenuation; - -#else - UNITY_LIGHT_ATTENUATION(atten, input, input.positionWS); - - const half3 lightDir = normalize(UnityWorldSpaceLightDir(input.positionWS)); - const half3 lightColor = _LightColor0.rgb; - -#endif + MTOON_LIGHT_DESCRIPTION(input, atten, lightDir, lightColor); if (MToon_IsForwardBasePass()) { @@ -57,16 +34,13 @@ UnityLighting GetUnityLighting(const Varyings input, const half3 normalWS) output.directLightAttenuation = atten; return output; } - else - { - UnityLighting output; - output.indirectLight = 0; - output.indirectLightEqualized = 0; - output.directLightColor = lightColor; - output.directLightDirection = lightDir; - output.directLightAttenuation = atten; - return output; - } + UnityLighting output; + output.indirectLight = 0; + output.indirectLightEqualized = 0; + output.directLightColor = lightColor; + output.directLightDirection = lightDir; + output.directLightAttenuation = atten; + return output; } #ifdef MTOON_URP diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_render_pipeline.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_render_pipeline.hlsl index 2c6c714ea..97f38d328 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_render_pipeline.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_render_pipeline.hlsl @@ -48,6 +48,33 @@ UNITY_LIGHTING_COORDS(6,7) #endif +// Light +#ifdef MTOON_URP + +#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) +#define MTOON_SHADOW_COORD input.shadowCoord +#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) +#define MTOON_SHADOW_COORD TransformWorldToShadowCoord(input.positionWS) +#else +#define MTOON_SHADOW_COORD float4(0, 0, 0, 0) +#endif + +#define MTOON_LIGHT_DESCRIPTION(input, atten, lightDir, lightColor) \ + half4 shadowMask = SAMPLE_SHADOWMASK(input.lightmapUV); \ + Light mainLight = GetMainLight(MTOON_SHADOW_COORD, input.positionWS, shadowMask); \ + const half3 lightDir = mainLight.direction; \ + const half3 lightColor = mainLight.color.rgb; \ + const float atten = mainLight.shadowAttenuation; + +#else + +#define MTOON_LIGHT_DESCRIPTION(input, atten, lightDir, lightColor) \ + UNITY_LIGHT_ATTENUATION(atten, input, input.positionWS); \ + const half3 lightDir = normalize(UnityWorldSpaceLightDir(input.positionWS)); \ + const half3 lightColor = _LightColor0.rgb; + +#endif + // Transform inline float3 MToon_TransformObjectToWorldNormal(float3 normalOS) {