Skip to content

Commit

Permalink
Merge pull request #83 from Santarh/alphaToCoverageFix
Browse files Browse the repository at this point in the history
Enable Alpha to Coverage only if Cutout.
  • Loading branch information
Santarh authored Jun 15, 2019
2 parents ff5bd6b + dcf7670 commit a6439a2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions MToon/Resources/Shaders/MToon.shader
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Shader "VRM/MToon"
[HideInInspector] _SrcBlend ("_SrcBlend", Float) = 1.0
[HideInInspector] _DstBlend ("_DstBlend", Float) = 0.0
[HideInInspector] _ZWrite ("_ZWrite", Float) = 1.0
[HideInInspector] _AlphaToMask ("_AlphaToMask", Float) = 0.0
}

// for SM 3.0
Expand All @@ -63,7 +64,7 @@ Shader "VRM/MToon"
ZWrite [_ZWrite]
ZTest LEqual
BlendOp Add, Max
AlphaToMask On
AlphaToMask [_AlphaToMask]

CGPROGRAM
#pragma target 3.0
Expand Down Expand Up @@ -92,7 +93,7 @@ Shader "VRM/MToon"
ZTest LEqual
Offset 1, 1
BlendOp Add, Max
AlphaToMask On
AlphaToMask [_AlphaToMask]

CGPROGRAM
#pragma target 3.0
Expand Down Expand Up @@ -123,7 +124,7 @@ Shader "VRM/MToon"
ZWrite Off
ZTest LEqual
BlendOp Add, Max
AlphaToMask On
AlphaToMask [_AlphaToMask]

CGPROGRAM
#pragma target 3.0
Expand Down
1 change: 1 addition & 0 deletions MToon/Scripts/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static partial class Utils
public const string PropSrcBlend = "_SrcBlend";
public const string PropDstBlend = "_DstBlend";
public const string PropZWrite = "_ZWrite";
public const string PropAlphaToMask = "_AlphaToMask";

public const string KeyNormalMap = "_NORMALMAP";
public const string KeyAlphaTestOn = "_ALPHATEST_ON";
Expand Down
4 changes: 4 additions & 0 deletions MToon/Scripts/UtilsSetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public static void ValidateBlendMode(Material material, RenderMode renderMode, b
material.SetInt(PropSrcBlend, (int) BlendMode.One);
material.SetInt(PropDstBlend, (int) BlendMode.Zero);
material.SetInt(PropZWrite, EnabledIntValue);
material.SetInt(PropAlphaToMask, DisabledIntValue);
SetKeyword(material, KeyAlphaTestOn, false);
SetKeyword(material, KeyAlphaBlendOn, false);
SetKeyword(material, KeyAlphaPremultiplyOn, false);
Expand All @@ -146,6 +147,7 @@ public static void ValidateBlendMode(Material material, RenderMode renderMode, b
material.SetInt(PropSrcBlend, (int) BlendMode.One);
material.SetInt(PropDstBlend, (int) BlendMode.Zero);
material.SetInt(PropZWrite, EnabledIntValue);
material.SetInt(PropAlphaToMask, EnabledIntValue);
SetKeyword(material, KeyAlphaTestOn, true);
SetKeyword(material, KeyAlphaBlendOn, false);
SetKeyword(material, KeyAlphaPremultiplyOn, false);
Expand All @@ -155,6 +157,7 @@ public static void ValidateBlendMode(Material material, RenderMode renderMode, b
material.SetInt(PropSrcBlend, (int) BlendMode.SrcAlpha);
material.SetInt(PropDstBlend, (int) BlendMode.OneMinusSrcAlpha);
material.SetInt(PropZWrite, DisabledIntValue);
material.SetInt(PropAlphaToMask, DisabledIntValue);
SetKeyword(material, KeyAlphaTestOn, false);
SetKeyword(material, KeyAlphaBlendOn, true);
SetKeyword(material, KeyAlphaPremultiplyOn, false);
Expand All @@ -164,6 +167,7 @@ public static void ValidateBlendMode(Material material, RenderMode renderMode, b
material.SetInt(PropSrcBlend, (int) BlendMode.SrcAlpha);
material.SetInt(PropDstBlend, (int) BlendMode.OneMinusSrcAlpha);
material.SetInt(PropZWrite, EnabledIntValue);
material.SetInt(PropAlphaToMask, DisabledIntValue);
SetKeyword(material, KeyAlphaTestOn, false);
SetKeyword(material, KeyAlphaBlendOn, true);
SetKeyword(material, KeyAlphaPremultiplyOn, false);
Expand Down

0 comments on commit a6439a2

Please sign in to comment.