diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon.shader b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon.shader index ffed3c5cb..7ff2cfa53 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon.shader +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon.shader @@ -89,11 +89,9 @@ Shader "Hidden/VRM10/vrmc_materials_mtoon" #pragma multi_compile_instancing #pragma multi_compile_local __ _ALPHATEST_ON _ALPHABLEND_ON - #pragma multi_compile_local __ _MTOON_NORMALMAP - #pragma multi_compile_local __ _MTOON_SHADINGMAP - #pragma multi_compile_local __ _MTOON_EMISSIVE - #pragma multi_compile_local __ _MTOON_UVANIMATION - #pragma multi_compile_local __ _MTOON_RIM + #pragma multi_compile_local __ _NORMALMAP + #pragma multi_compile_local __ _MTOON_EMISSIVEMAP + #pragma multi_compile_local __ _MTOON_PARAMETERMAP #pragma vertex MToonVertex #pragma fragment MToonFragment @@ -125,12 +123,9 @@ Shader "Hidden/VRM10/vrmc_materials_mtoon" #pragma multi_compile_instancing #pragma multi_compile_local __ _ALPHATEST_ON _ALPHABLEND_ON - #pragma multi_compile_local __ _MTOON_OUTLINEMAP - #pragma multi_compile_local __ _MTOON_NORMALMAP - #pragma multi_compile_local __ _MTOON_SHADINGMAP - #pragma multi_compile_local __ _MTOON_EMISSIVE - #pragma multi_compile_local __ _MTOON_UVANIMATION - #pragma multi_compile_local __ _MTOON_RIM + #pragma multi_compile_local __ _NORMALMAP + #pragma multi_compile_local __ _MTOON_EMISSIVEMAP + #pragma multi_compile_local __ _MTOON_PARAMETERMAP #define MTOON_PASS_OUTLINE @@ -164,11 +159,9 @@ Shader "Hidden/VRM10/vrmc_materials_mtoon" #pragma multi_compile_instancing #pragma multi_compile_local __ _ALPHATEST_ON _ALPHABLEND_ON - #pragma multi_compile_local __ _MTOON_NORMALMAP - #pragma multi_compile_local __ _MTOON_SHADINGMAP - #pragma multi_compile_local __ _MTOON_EMISSIVE - #pragma multi_compile_local __ _MTOON_UVANIMATION - #pragma multi_compile_local __ _MTOON_RIM + #pragma multi_compile_local __ _NORMALMAP + #pragma multi_compile_local __ _MTOON_EMISSIVEMAP + #pragma multi_compile_local __ _MTOON_PARAMETERMAP #pragma vertex MToonVertex #pragma fragment MToonFragment 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 2de74dd5d..885bd51dd 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 @@ -28,36 +28,6 @@ inline bool MToon_IsOutlinePass() #endif } -// Compile-time constant -inline bool MToon_IsUvAnimationOn() -{ -#if defined(_MTOON_UVANIMATION) - return true; -#else - return false; -#endif -} - -// Compile-time constant -inline bool MToon_IsRimOn() -{ -#if defined(_MTOON_RIM) - return true; -#else - return false; -#endif -} - -// Compile-time constant -inline bool MToon_IsEmissiveOn() -{ -#if defined(_MTOON_EMISSIVE) - return true; -#else - return false; -#endif -} - // Compile-time constant inline bool MToon_IsNormalMapOn() { @@ -69,9 +39,9 @@ inline bool MToon_IsNormalMapOn() } // Compile-time constant -inline bool MToon_IsShadingMapOn() +inline bool MToon_IsEmissiveMapOn() { -#if defined(_MTOON_SHADINGMAP) +#if defined(_MTOON_EMISSIVEMAP) return true; #else return false; @@ -79,9 +49,9 @@ inline bool MToon_IsShadingMapOn() } // Compile-time constant -inline bool MToon_IsOutlineMapOn() +inline bool MToon_IsParameterMapOn() { -#if defined(_MTOON_OUTLINEMAP) +#if defined(_MTOON_PARAMETERMAP) return true; #else return false; diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_uv.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_uv.hlsl index c07980ae2..ed1f1556c 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_uv.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_uv.hlsl @@ -6,18 +6,32 @@ #include "./vrmc_materials_mtoon_utility.hlsl" #include "./vrmc_materials_mtoon_input.hlsl" +inline float GetMToonGeometry_Uv_Time(const float2 uvRaw) +{ + if (MToon_IsParameterMapOn()) + { + return UNITY_SAMPLE_TEX2D(_UvAnimMaskTex, uvRaw).b * _Time.y; + } + else + { + return _Time.y; + } +} + inline float2 GetMToonGeometry_Uv(const float2 geometryUv) { // get raw uv with _MainTex_ST const float2 uvRaw = TRANSFORM_TEX(geometryUv, _MainTex); - if (MToon_IsUvAnimationOn()) + if (MToon_IsParameterMapOn()) { - const float uvAnimationCoef = UNITY_SAMPLE_TEX2D(_UvAnimMaskTex, uvRaw).b * _Time.y; - const float2 translate = uvAnimationCoef * float2(_UvAnimScrollXSpeed, _UvAnimScrollYSpeed); - const float rotateRad = uvAnimationCoef * _UvAnimRotationSpeed * PI_2; + const float uvAnimationTime = GetMToonGeometry_Uv_Time(uvRaw); + const float2 translate = uvAnimationTime * float2(_UvAnimScrollXSpeed, _UvAnimScrollYSpeed); + const float rotateRad = uvAnimationTime * _UvAnimRotationSpeed * PI_2; + const float cosRotate = cos(rotateRad); + const float sinRotate = sin(rotateRad); const float2 rotatePivot = float2(0.5, 0.5); - return mul(float2x2(cos(rotateRad), -sin(rotateRad), sin(rotateRad), cos(rotateRad)), uvRaw + translate - rotatePivot) + rotatePivot; + return mul(float2x2(cosRotate, -sinRotate, sinRotate, cosRotate), uvRaw + translate - rotatePivot) + rotatePivot; } else { diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_vertex.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_vertex.hlsl index 21af39c3e..d9c024edc 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_vertex.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_vertex.hlsl @@ -14,7 +14,7 @@ struct VertexPositionInfo inline half MToon_GetOutlineVertex_OutlineWidth(const float2 uv) { - if (MToon_IsOutlineMapOn()) + if (MToon_IsParameterMapOn()) { return _OutlineWidth * UNITY_SAMPLE_TEX2D_LOD(_OutlineWidthTex, uv, 0); } 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 d871bf3c5..d701769fa 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 @@ -19,7 +19,7 @@ struct MToonInput inline half GetMToonLighting_Reflectance_ShadingShift(const MToonInput input) { - if (MToon_IsShadingMapOn()) + if (MToon_IsParameterMapOn()) { return UNITY_SAMPLE_TEX2D(_ShadingShiftTex, input.uv).r * _ShadingShiftTexScale + _ShadingShiftFactor; } @@ -67,11 +67,28 @@ inline half3 GetMToonLighting_GlobalIllumination(const UnityLighting unityLight, inline half3 GetMToonLighting_Emissive(const MToonInput input) { - if (MToon_IsForwardBasePass() && MToon_IsEmissiveOn()) + if (MToon_IsForwardBasePass() && MToon_IsEmissiveMapOn()) { return UNITY_SAMPLE_TEX2D(_EmissionMap, input.uv).rgb * _EmissionColor.rgb; } else + { + return _EmissionColor.rgb; + } +} + +inline half3 GetMToonLighting_Rim_Matcap(const MToonInput input) +{ + if (MToon_IsParameterMapOn()) + { + const half3 worldUpWS = half3(0, 1, 0); + // TODO: use view space axis if abs(dot(viewDir, worldUp)) == 1.0 + const half3 matcapRightAxisWS = normalize(cross(input.viewDirWS, worldUpWS)); + const half3 matcapUpAxisWS = normalize(cross(matcapRightAxisWS, input.viewDirWS)); + const half2 matcapUv = float2(dot(matcapRightAxisWS, input.normalWS), dot(matcapUpAxisWS, input.normalWS)) * 0.5 + 0.5; + return UNITY_SAMPLE_TEX2D(_MatcapTex, matcapUv).rgb; + } + else { return 0; } @@ -79,16 +96,11 @@ inline half3 GetMToonLighting_Emissive(const MToonInput input) inline half3 GetMToonLighting_Rim(const MToonInput input, const half3 lighting) { - if (MToon_IsForwardBasePass() && MToon_IsRimOn()) + if (MToon_IsForwardBasePass()) { - const half3 worldUpWS = half3(0, 1, 0); - // TODO: use view space axis if abs(dot(viewDir, worldUp)) == 1.0 - const half3 matcapRightAxisWS = normalize(cross(input.viewDirWS, worldUpWS)); - const half3 matcapUpAxisWS = normalize(cross(matcapRightAxisWS, input.viewDirWS)); - const half2 matcapUv = float2(dot(matcapRightAxisWS, input.normalWS), dot(matcapUpAxisWS, input.normalWS)) * 0.5 + 0.5; - const half3 matcapFactor = UNITY_SAMPLE_TEX2D(_MatcapTex, matcapUv).rgb; const half3 parametricRimFactor = pow(saturate(1.0 - dot(input.normalWS, input.viewDirWS) + _RimLift), _RimFresnelPower) * _RimColor.rgb; const half3 rimLightingFactor = lerp(half3(1, 1, 1), lighting, _RimLightingMix); + const half3 matcapFactor = GetMToonLighting_Rim_Matcap(input); return (matcapFactor + parametricRimFactor) * UNITY_SAMPLE_TEX2D(_RimTex, input.uv).rgb * rimLightingFactor; } else