Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring mtoon 1.0 alpha #1034

Merged
merged 1 commit into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.