Last active
February 25, 2019 08:22
-
-
Save fuqunaga/2534038e578d46c3421d861e375d3fa9 to your computer and use it in GitHub Desktop.
DitherTransparency with BayerMatrix
This file contains hidden or 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 "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
DitherTransparency with BayerMatrix
Reference:
http://light11.hatenadiary.com/entry/2018/01/30/232343
http://fe0km.blog.fc2.com/blog-entry-122.html
https://digitalrune.github.io/DigitalRune-Documentation/html/fa431d48-b457-4c70-a590-d44b0840ab1e.htm