Skip to content

Instantly share code, notes, and snippets.

@fuqunaga
Last active February 25, 2019 08:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fuqunaga/2534038e578d46c3421d861e375d3fa9 to your computer and use it in GitHub Desktop.
Save fuqunaga/2534038e578d46c3421d861e375d3fa9 to your computer and use it in GitHub Desktop.
DitherTransparency with BayerMatrix
Shader "Unlit/DitherTransparency"
{
Properties
{
_Color("Color", Color) = (1,1,1,1)
_Alpha("Alpha", Range(0,1))=1
}
SubShader
{
Tags { "RenderType"="Opaque" }
Blend Off
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float4 _Color;
float _Alpha;
float4 vert (float4 v : POSITION) : SV_POSITION
{
return UnityObjectToClipPos(v);
}
fixed4 frag (UNITY_VPOS_TYPE screenPos : VPOS) : SV_Target
{
#if 1
float4x4 thresholdMatrix =
{
1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
};
float2 pos = screenPos % 4;
#else
float2x2 thresholdMatrix =
{
0.2, 0.8,
0.6, 0.4
};
float2 pos = screenPos % 2;
#endif
float dither = thresholdMatrix[pos.x][pos.y];
clip(_Alpha - dither);
return _Color;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment