Skip to content

Commit

Permalink
Fix #9 Alpha to coverage for unlit cutout shader
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesDeml committed Oct 25, 2019
1 parent 4c4f343 commit 5930906
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Shaders/ConfigurableCutoutUnlit.shader
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Shader "Configurable/Unlit/Cutout"
[HDR] _Color("Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
[Enum(Off,0,On,1)] _AlphaToMask("Alpha to Mask", Int) = 1
[SimpleToggle] _UseVertexColor("Vertex color", Float) = 1.0

[HeaderHelpURL(Rendering, https, github.com supyrb ConfigurableShaders wiki Rendering)]
Expand Down Expand Up @@ -79,9 +80,14 @@ Shader "Configurable/Unlit/Cutout"

fixed4 frag (v2f i) : SV_Target
{
fixed4 image = tex2D(_MainTex, i.texcoord) * i.color;
clip(image.a - _Cutoff);
return image;
fixed4 color = tex2D(_MainTex, i.texcoord) * i.color;

// rescale alpha by partial derivative
color.a = (color.a - _Cutoff) / max(fwidth(color.a), 0.0001) + 0.5;

clip(color.a - _Cutoff);

return color;
}

struct v2fShadow
Expand All @@ -103,8 +109,8 @@ Shader "Configurable/Unlit/Cutout"

float4 fragShadow( v2fShadow i ) : SV_Target
{
fixed4 image = tex2D(_MainTex, i.texcoord);
clip(image.a - _Cutoff);
fixed4 color = tex2D(_MainTex, i.texcoord);
clip(color.a - _Cutoff);
SHADOW_CASTER_FRAGMENT(i)
}

Expand Down Expand Up @@ -134,6 +140,7 @@ Shader "Configurable/Unlit/Cutout"

Pass
{
AlphaToMask [_AlphaToMask]
CGPROGRAM
#pragma target 3.0
#pragma vertex vert
Expand Down

0 comments on commit 5930906

Please sign in to comment.