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 e7efedfdd..52dc4e9ea 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 @@ -24,4 +24,14 @@ inline bool MToon_IsUvAnimationOn() #endif } +// Compile-time constant +inline bool MToon_IsNormalMapOn() +{ +#if defined(_NORMALMAP) + return true; +#else + return false; +#endif +} + #endif 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 df0ab2460..bf01828ef 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 @@ -6,14 +6,15 @@ #include "./vrmc_materials_mtoon_utility.hlsl" #include "./vrmc_materials_mtoon_input.hlsl" #include "./vrmc_materials_mtoon_attribute.hlsl" -#include "./vrmc_materials_mtoon_lighting.hlsl" -#include "./vrmc_materials_mtoon_uv.hlsl" -#include "./vrmc_materials_mtoon_unity_lighting.hlsl" +#include "./vrmc_materials_mtoon_geometry_uv.hlsl" +#include "./vrmc_materials_mtoon_geometry_normal.hlsl" +#include "./vrmc_materials_mtoon_lighting_unity.hlsl" +#include "./vrmc_materials_mtoon_lighting_mtoon.hlsl" half4 MToonFragment(const Varyings input) : SV_Target { // Get MToon UV (with UVAnimation) - const float2 uv = GetMToonUv(input.uv); + const float2 uv = GetMToonGeometry_Uv(input.uv); // Get LitColor with Alpha const half4 litColor = UNITY_SAMPLE_TEX2D(_MainTex, uv) * _Color; @@ -31,13 +32,8 @@ half4 MToonFragment(const Varyings input) : SV_Target const half alpha = 1.0; #endif - // Get Normal in WorldSpace from Normalmap if available -#if defined(_NORMALMAP) - const half3 normalTS = normalize(UnpackNormalWithScale(UNITY_SAMPLE_TEX2D(_BumpMap, uv), _BumpScale)); - const half3 normalWS = normalize(mul(normalTS, MToon_GetTangentToWorld(input.normalWS, input.tangentWS))); -#else - const half3 normalWS = normalize(input.normalWS); -#endif + // Get Normal + const float3 normalWS = GetMToonGeometry_Normal(input, uv); // Get Unity Lighting const UnityLighting unityLighting = GetUnityLighting(input, normalWS); diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_normal.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_normal.hlsl new file mode 100644 index 000000000..db0304252 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_normal.hlsl @@ -0,0 +1,25 @@ +#ifndef VRMC_MATERIALS_MTOON_GEOMETRY_NORMAL_INCLUDED +#define VRMC_MATERIALS_MTOON_GEOMETRY_NORMAL_INCLUDED + +#include +#include "./vrmc_materials_mtoon_define.hlsl" +#include "./vrmc_materials_mtoon_utility.hlsl" +#include "./vrmc_materials_mtoon_input.hlsl" + +inline float3 GetMToonGeometry_NormalWithoutNormalMap(const half3 normalWS) +{ + return normalize(normalWS); +} + +inline float3 GetMToonGeometry_Normal(const Varyings input, const float2 mtoonUv) +{ +#if defined(_NORMALMAP) + // Get Normal in WorldSpace from Normalmap if available + const half3 normalTS = normalize(UnpackNormalWithScale(UNITY_SAMPLE_TEX2D(_BumpMap, mtoonUv), _BumpScale)); + return normalize(mul(normalTS, MToon_GetTangentToWorld(input.normalWS, input.tangentWS))); +#else + return GetMToonGeometry_NormalWithoutNormalMap(input.normalWS); +#endif +} + +#endif diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_normal.hlsl.meta b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_normal.hlsl.meta new file mode 100644 index 000000000..9e69be004 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_normal.hlsl.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5ddfcfc47ee84eed9365b902bf76ce75 +timeCreated: 1622633324 \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_uv.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_uv.hlsl similarity index 77% rename from Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_uv.hlsl rename to Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_uv.hlsl index 6c92d4139..2c64f5f6e 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_uv.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_uv.hlsl @@ -1,11 +1,12 @@ -#ifndef VRMC_MATERIALS_MTOON_UV_INCLUDED -#define VRMC_MATERIALS_MTOON_UV_INCLUDED +#ifndef VRMC_MATERIALS_MTOON_GEOMETRY_UV_INCLUDED +#define VRMC_MATERIALS_MTOON_GEOMETRY_UV_INCLUDED #include #include "./vrmc_materials_mtoon_define.hlsl" +#include "./vrmc_materials_mtoon_utility.hlsl" #include "./vrmc_materials_mtoon_input.hlsl" -float2 GetMToonUv(const float2 geometryUv) +float2 GetMToonGeometry_Uv(const float2 geometryUv) { // get raw uv with _MainTex_ST const float2 uvRaw = TRANSFORM_TEX(geometryUv, _MainTex); diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_uv.hlsl.meta b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_uv.hlsl.meta similarity index 100% rename from Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_uv.hlsl.meta rename to Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_uv.hlsl.meta diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl similarity index 92% rename from Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting.hlsl rename to Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl index d2ce3212d..f3815e925 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl @@ -1,11 +1,11 @@ -#ifndef VRMC_MATERIALS_MTOON_LIGHTING_INCLUDED -#define VRMC_MATERIALS_MTOON_LIGHTING_INCLUDED +#ifndef VRMC_MATERIALS_MTOON_LIGHTING_MTOON_INCLUDED +#define VRMC_MATERIALS_MTOON_LIGHTING_MTOON_INCLUDED #include #include "./vrmc_materials_mtoon_define.hlsl" #include "./vrmc_materials_mtoon_utility.hlsl" #include "./vrmc_materials_mtoon_input.hlsl" -#include "./vrmc_materials_mtoon_unity_lighting.hlsl" +#include "./vrmc_materials_mtoon_lighting_unity.hlsl" struct MToonInput { diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting.hlsl.meta b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl.meta similarity index 100% rename from Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting.hlsl.meta rename to Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl.meta diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_unity_lighting.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_unity.hlsl similarity index 86% rename from Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_unity_lighting.hlsl rename to Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_unity.hlsl index 4e3efe509..5940d9bba 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_unity_lighting.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_unity.hlsl @@ -1,10 +1,10 @@ -#ifndef VRMC_MATERIALS_MTOON_UNITY_LIGHTING_INCLUDED -#define VRMC_MATERIALS_MTOON_UNITY_LIGHTING_INCLUDED +#ifndef VRMC_MATERIALS_MTOON_LIGHTING_UNITY_INCLUDED +#define VRMC_MATERIALS_MTOON_LIGHTING_UNITY_INCLUDED #include #include #include -#include "./vrmc_materials_mtoon_utility.hlsl" +#include "./vrmc_materials_mtoon_define.hlsl" #include "./vrmc_materials_mtoon_input.hlsl" #include "./vrmc_materials_mtoon_attribute.hlsl" diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_unity_lighting.hlsl.meta b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_unity.hlsl.meta similarity index 100% rename from Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_unity_lighting.hlsl.meta rename to Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_unity.hlsl.meta