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 56fa66bfd..e7efedfdd 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 @@ -1,42 +1,6 @@ #ifndef VRMC_MATERIALS_MTOON_DEFINE_INCLUDED #define VRMC_MATERIALS_MTOON_DEFINE_INCLUDED -// define -static const float PI_2 = 6.28318530718; -static const float EPS_COL = 0.00001; - -inline half3 mtoon_linearstep(const half3 start, const half3 end, const half t) -{ - return min(max((t - start) / (end - start), 0.0), 1.0); -} - -inline bool MToon_IsPerspective() -{ - return unity_OrthoParams.w != 1.0; -} - -inline float3 MToon_GetWorldSpaceNormalizedViewDir(const float3 positionWS) -{ - if (MToon_IsPerspective()) - { - return normalize(_WorldSpaceCameraPos.xyz - positionWS); - } - else - { - return normalize(UNITY_MATRIX_V[2].xyz); - } -} - -inline half3x3 MToon_GetTangentToWorld(const half3 normalWS, const half4 tangentWS) -{ - const half3 normalizedNormalWS = normalize(normalWS); - const half3 normalizedTangentWS = normalize(tangentWS.xyz); - - const half3 normalizedBitangentWS = normalize(tangentWS.w * cross(normalizedNormalWS, normalizedTangentWS)); - - return half3x3(normalizedTangentWS, normalizedBitangentWS, normalizedNormalWS); -} - // Compile-time constant inline bool MToon_IsForwardBasePass() { 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 57b3a88bb..df0ab2460 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 @@ -2,9 +2,8 @@ #define VRMC_MATERIALS_MTOON_FORWARD_FRAGMENT_INCLUDED #include -#include - #include "./vrmc_materials_mtoon_define.hlsl" +#include "./vrmc_materials_mtoon_utility.hlsl" #include "./vrmc_materials_mtoon_input.hlsl" #include "./vrmc_materials_mtoon_attribute.hlsl" #include "./vrmc_materials_mtoon_lighting.hlsl" diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_vertex.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_vertex.hlsl index 2d5c650da..15b597141 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_vertex.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_vertex.hlsl @@ -3,8 +3,7 @@ #include #include - -#include "./vrmc_materials_mtoon_define.hlsl" +#include "./vrmc_materials_mtoon_utility.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_lighting.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting.hlsl index a637bf2bd..d2ce3212d 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting.hlsl @@ -1,7 +1,9 @@ #ifndef VRMC_MATERIALS_MTOON_LIGHTING_INCLUDED #define VRMC_MATERIALS_MTOON_LIGHTING_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" 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_unity_lighting.hlsl index e1764d6af..4e3efe509 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_unity_lighting.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_unity_lighting.hlsl @@ -4,6 +4,7 @@ #include #include #include +#include "./vrmc_materials_mtoon_utility.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_utility.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_utility.hlsl new file mode 100644 index 000000000..98b994edc --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_utility.hlsl @@ -0,0 +1,42 @@ +#ifndef VRMC_MATERIALS_MTOON_UTILITY_INCLUDED +#define VRMC_MATERIALS_MTOON_UTILITY_INCLUDED + +#include + +// define +static const float PI_2 = 6.28318530718; +static const float EPS_COL = 0.00001; + +inline half3 mtoon_linearstep(const half3 start, const half3 end, const half t) +{ + return min(max((t - start) / (end - start), 0.0), 1.0); +} + +inline bool MToon_IsPerspective() +{ + return unity_OrthoParams.w != 1.0; +} + +inline float3 MToon_GetWorldSpaceNormalizedViewDir(const float3 positionWS) +{ + if (MToon_IsPerspective()) + { + return normalize(_WorldSpaceCameraPos.xyz - positionWS); + } + else + { + return normalize(UNITY_MATRIX_V[2].xyz); + } +} + +inline half3x3 MToon_GetTangentToWorld(const half3 normalWS, const half4 tangentWS) +{ + const half3 normalizedNormalWS = normalize(normalWS); + const half3 normalizedTangentWS = normalize(tangentWS.xyz); + + const half3 normalizedBitangentWS = normalize(tangentWS.w * cross(normalizedNormalWS, normalizedTangentWS)); + + return half3x3(normalizedTangentWS, normalizedBitangentWS, normalizedNormalWS); +} + +#endif diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_utility.hlsl.meta b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_utility.hlsl.meta new file mode 100644 index 000000000..c00034f64 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_utility.hlsl.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 79a73f8bac4e45498341e9b6c1ea841e +timeCreated: 1622632833 \ No newline at end of file