refactoring about alpha

This commit is contained in:
Masataka SUMI 2021-06-14 20:05:12 +09:00
parent 30d013b0e2
commit 66e3e3b84c
4 changed files with 54 additions and 11 deletions

View File

@ -41,6 +41,26 @@ inline bool MToon_IsOutlinePass()
#endif
}
// Compile-time constant
inline bool MToon_IsAlphaTestOn()
{
#if defined(_ALPHATEST_ON)
return true;
#else
return false;
#endif
}
// Compile-time constant
inline bool MToon_IsAlphaBlendOn()
{
#if defined(_ALPHABLEND_ON)
return true;
#else
return false;
#endif
}
// Compile-time constant
inline bool MToon_IsNormalMapOn()
{

View File

@ -7,6 +7,7 @@
#include "./vrmc_materials_mtoon_input.hlsl"
#include "./vrmc_materials_mtoon_attribute.hlsl"
#include "./vrmc_materials_mtoon_geometry_uv.hlsl"
#include "./vrmc_materials_mtoon_geometry_alpha.hlsl"
#include "./vrmc_materials_mtoon_geometry_normal.hlsl"
#include "./vrmc_materials_mtoon_lighting_unity.hlsl"
#include "./vrmc_materials_mtoon_lighting_mtoon.hlsl"
@ -27,17 +28,7 @@ half4 MToonFragment(const FragmentInput fragmentInput) : SV_Target
const half4 litColor = UNITY_SAMPLE_TEX2D(_MainTex, uv) * _Color;
// Alpha Test
#if defined(_ALPHATEST_ON)
const half rawAlpha = litColor.a;
const half tmpAlpha = (rawAlpha - _Cutoff) / max(fwidth(rawAlpha), 0.00001) + 0.5; // Alpha to Coverage
clip(tmpAlpha - _Cutoff);
const half alpha = 1.0;
#elif defined(_ALPHABLEND_ON)
const half alpha = litColor.a;
clip(alpha - EPS_COL);
#else
const half alpha = 1.0;
#endif
const half alpha = GetMToonGeometry_Alpha(litColor);
// Get Normal
const float3 normalWS = GetMToonGeometry_Normal(input, fragmentInput.facing, uv);

View File

@ -0,0 +1,29 @@
#ifndef VRMC_MATERIALS_MTOON_GEOMETRY_ALPHA_INCLUDED
#define VRMC_MATERIALS_MTOON_GEOMETRY_ALPHA_INCLUDED
#include "./vrmc_materials_mtoon_define.hlsl"
#include "./vrmc_materials_mtoon_utility.hlsl"
#include "./vrmc_materials_mtoon_input.hlsl"
inline half GetMToonGeometry_Alpha(half4 litColor)
{
if (MToon_IsAlphaTestOn())
{
const half rawAlpha = litColor.a;
const half tmpAlpha = (rawAlpha - _Cutoff) / max(fwidth(rawAlpha), 0.00001) + 0.5; // Alpha to Coverage
clip(tmpAlpha - _Cutoff);
return 1.0;
}
else if (MToon_IsAlphaBlendOn())
{
const half alpha = litColor.a;
clip(alpha - EPS_COL);
return alpha;
}
else
{
return 1.0;
}
}
#endif

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 87aa2d8d38194c35a6531b8f5e3da7aa
timeCreated: 1623668534