Suppress variants.

This commit is contained in:
Masataka SUMI
2021-06-07 20:33:01 +09:00
parent ccbc53d0d8
commit d700b393ff
5 changed files with 54 additions and 65 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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
{

View File

@@ -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);
}

View File

@@ -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