From eb532c4aa678f278d795d0c6d7ccd1c09a24bc0a Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 15 Jul 2021 19:47:22 +0900 Subject: [PATCH] Add Pbr Correct mode. --- .../Resources/VRM10/vrmc_materials_mtoon_define.hlsl | 6 ++++++ .../VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_define.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_define.hlsl index cb983736f..fcd7c8d64 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_define.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_define.hlsl @@ -18,6 +18,12 @@ #define MTOON_IS_FRONT_VFACE(VAL, FRONT, BACK) ((VAL > 0.0) ? (FRONT) : (BACK)) #endif +// Compile-time constant +inline bool MToon_IsPbrCorrectOn() +{ + return false; +} + // Compile-time constant inline bool MToon_IsForwardBasePass() { 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 bee7da2dd..ca7ea9eaa 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 @@ -38,6 +38,12 @@ inline half GetMToonLighting_Shade(const UnityLighting lighting, const MToonInpu 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); + } + if (MToon_IsForwardBasePass()) { const half shadeInput = lerp(-1, 1, mtoon_linearstep(-1, 1, dotNL) * lighting.directLightAttenuation); @@ -52,6 +58,11 @@ inline half GetMToonLighting_Shade(const UnityLighting lighting, const MToonInpu inline half GetMToonLighting_Shadow(const UnityLighting lighting, const half dotNL) { + if (MToon_IsPbrCorrectOn()) + { + return lighting.directLightAttenuation * (min(0, dotNL) + 1); + } + if (MToon_IsForwardBasePass()) { return 1;