Created
February 6, 2019 18:58
-
-
Save lindsaygcox/46200797e6ec4e54aba22e4c81ab6d84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Custom/Sprite_Dithered" | |
{ | |
Properties | |
{ | |
[PerRendererData] | |
_MainTex("Texture", 2D) = "white" {} | |
_Color("Color", Color) = (1, 1, 1, 1) | |
} | |
SubShader | |
{ | |
Tags | |
{ | |
"RenderType" = "Opaque" | |
"Queue" = "Transparent" | |
"PreviewType" = "Plane" | |
"CanUseSpriteAtlas" = "True" | |
"IgnoreProjector" = "True" | |
} | |
Blend SrcAlpha OneMinusSrcAlpha | |
ZWrite Off | |
Cull Off | |
Lighting Off | |
Pass | |
{ | |
Stencil | |
{ | |
Ref[_MaskValue] | |
Comp LEqual | |
Pass DecrWrap | |
} | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
uniform sampler2D _MainTex; | |
uniform fixed4 _Color; | |
float _DitherScale; | |
sampler2D _DitherTex; | |
struct vertexInput | |
{ | |
fixed4 pos : POSITION; | |
half2 uv : TEXCOORD0; | |
}; | |
struct fragmentInput | |
{ | |
fixed4 pos : POSITION; | |
half2 uv : TEXCOORD0; | |
float4 spos : TEXCOORD1; | |
}; | |
fragmentInput vert(vertexInput input) | |
{ | |
fragmentInput output; | |
output.pos = UnityObjectToClipPos(input.pos); | |
output.uv = input.uv; | |
output.spos = ComputeScreenPos(output.pos); | |
return output; | |
} | |
fixed4 frag(fragmentInput input) : Color | |
{ | |
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 | |
}; | |
float4x4 _RowAccess = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 }; | |
fixed4 output = tex2D(_MainTex, input.uv); | |
clip(_Color.a - thresholdMatrix[fmod(input.pos.x, 4)] * _RowAccess[fmod(input.pos.y, 4)]); | |
return output * fixed4(_Color.r, _Color.g, _Color.b, 1); | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment