DitheringFade.shader 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // Made with Amplify Shader Editor
  2. // Available at the Unity Asset Store - http://u3d.as/y3X
  3. Shader "ASESampleShaders/DitheringFade"
  4. {
  5. Properties
  6. {
  7. _Cutoff( "Mask Clip Value", Float ) = 0.74
  8. _Albedo("Albedo", 2D) = "white" {}
  9. [NoScaleOffset]_Normal("Normal", 2D) = "bump" {}
  10. [NoScaleOffset]_Specular("Specular", 2D) = "white" {}
  11. [NoScaleOffset]_Occlusion("Occlusion", 2D) = "white" {}
  12. _StartDitheringFade("Start Dithering Fade", Float) = 0
  13. _EndDitheringFade("End Dithering Fade", Float) = 1
  14. _Float0("Float 0", Float) = 1
  15. _Color0("Color 0", Color) = (0.0518868,0.1491979,1,0.1921569)
  16. [HideInInspector] _texcoord( "", 2D ) = "white" {}
  17. [HideInInspector] __dirty( "", Int ) = 1
  18. }
  19. SubShader
  20. {
  21. Tags{ "RenderType" = "Transparent" "Queue" = "AlphaTest+0" }
  22. Cull Back
  23. ZTest LEqual
  24. CGINCLUDE
  25. #include "UnityShaderVariables.cginc"
  26. #include "UnityPBSLighting.cginc"
  27. #include "Lighting.cginc"
  28. #pragma target 3.0
  29. struct Input
  30. {
  31. float2 uv_texcoord;
  32. float eyeDepth;
  33. float4 screenPosition;
  34. };
  35. uniform sampler2D _Normal;
  36. uniform sampler2D _Albedo;
  37. uniform float4 _Albedo_ST;
  38. uniform half4 _Color0;
  39. uniform float _Float0;
  40. uniform sampler2D _Specular;
  41. uniform sampler2D _Occlusion;
  42. uniform float _StartDitheringFade;
  43. uniform float _EndDitheringFade;
  44. uniform float _Cutoff = 0.74;
  45. inline float Dither8x8Bayer( int x, int y )
  46. {
  47. const float dither[ 64 ] = {
  48. 1, 49, 13, 61, 4, 52, 16, 64,
  49. 33, 17, 45, 29, 36, 20, 48, 32,
  50. 9, 57, 5, 53, 12, 60, 8, 56,
  51. 41, 25, 37, 21, 44, 28, 40, 24,
  52. 3, 51, 15, 63, 2, 50, 14, 62,
  53. 35, 19, 47, 31, 34, 18, 46, 30,
  54. 11, 59, 7, 55, 10, 58, 6, 54,
  55. 43, 27, 39, 23, 42, 26, 38, 22};
  56. int r = y * 8 + x;
  57. return dither[r] / 64; // same # of instructions as pre-dividing due to compiler magic
  58. }
  59. void vertexDataFunc( inout appdata_full v, out Input o )
  60. {
  61. UNITY_INITIALIZE_OUTPUT( Input, o );
  62. o.eyeDepth = -UnityObjectToViewPos( v.vertex.xyz ).z;
  63. float4 ase_screenPos = ComputeScreenPos( UnityObjectToClipPos( v.vertex ) );
  64. o.screenPosition = ase_screenPos;
  65. }
  66. void surf( Input i , inout SurfaceOutputStandardSpecular o )
  67. {
  68. float2 uv0_Albedo = i.uv_texcoord * _Albedo_ST.xy + _Albedo_ST.zw;
  69. o.Normal = UnpackNormal( tex2D( _Normal, uv0_Albedo ) );
  70. half4 temp_output_74_0 = ( tex2D( _Albedo, uv0_Albedo ) * _Color0 * _Color0.a * _Float0 );
  71. o.Albedo = temp_output_74_0.rgb;
  72. o.Specular = tex2D( _Specular, uv0_Albedo ).rgb;
  73. o.Occlusion = tex2D( _Occlusion, uv0_Albedo ).r;
  74. o.Alpha = temp_output_74_0.r;
  75. half temp_output_65_0 = ( _StartDitheringFade + _ProjectionParams.y );
  76. float4 ase_screenPos = i.screenPosition;
  77. half4 ase_screenPosNorm = ase_screenPos / ase_screenPos.w;
  78. ase_screenPosNorm.z = ( UNITY_NEAR_CLIP_VALUE >= 0 ) ? ase_screenPosNorm.z : ase_screenPosNorm.z * 0.5 + 0.5;
  79. half2 clipScreen26 = ase_screenPosNorm.xy * _ScreenParams.xy;
  80. half dither26 = Dither8x8Bayer( fmod(clipScreen26.x, 8), fmod(clipScreen26.y, 8) );
  81. clip( ( ( ( i.eyeDepth + -temp_output_65_0 ) / ( _EndDitheringFade - temp_output_65_0 ) ) - dither26 ) - _Cutoff );
  82. }
  83. ENDCG
  84. CGPROGRAM
  85. #pragma surface surf StandardSpecular keepalpha fullforwardshadows vertex:vertexDataFunc
  86. ENDCG
  87. Pass
  88. {
  89. Name "ShadowCaster"
  90. Tags{ "LightMode" = "ShadowCaster" }
  91. ZWrite On
  92. CGPROGRAM
  93. #pragma vertex vert
  94. #pragma fragment frag
  95. #pragma target 3.0
  96. #pragma multi_compile_shadowcaster
  97. #pragma multi_compile UNITY_PASS_SHADOWCASTER
  98. #pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
  99. #include "HLSLSupport.cginc"
  100. #if ( SHADER_API_D3D11 || SHADER_API_GLCORE || SHADER_API_GLES || SHADER_API_GLES3 || SHADER_API_METAL || SHADER_API_VULKAN )
  101. #define CAN_SKIP_VPOS
  102. #endif
  103. #include "UnityCG.cginc"
  104. #include "Lighting.cginc"
  105. #include "UnityPBSLighting.cginc"
  106. sampler3D _DitherMaskLOD;
  107. struct v2f
  108. {
  109. V2F_SHADOW_CASTER;
  110. float3 customPack1 : TEXCOORD1;
  111. float4 customPack2 : TEXCOORD2;
  112. float3 worldPos : TEXCOORD3;
  113. float4 tSpace0 : TEXCOORD4;
  114. float4 tSpace1 : TEXCOORD5;
  115. float4 tSpace2 : TEXCOORD6;
  116. UNITY_VERTEX_INPUT_INSTANCE_ID
  117. UNITY_VERTEX_OUTPUT_STEREO
  118. };
  119. v2f vert( appdata_full v )
  120. {
  121. v2f o;
  122. UNITY_SETUP_INSTANCE_ID( v );
  123. UNITY_INITIALIZE_OUTPUT( v2f, o );
  124. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( o );
  125. UNITY_TRANSFER_INSTANCE_ID( v, o );
  126. Input customInputData;
  127. vertexDataFunc( v, customInputData );
  128. float3 worldPos = mul( unity_ObjectToWorld, v.vertex ).xyz;
  129. half3 worldNormal = UnityObjectToWorldNormal( v.normal );
  130. half3 worldTangent = UnityObjectToWorldDir( v.tangent.xyz );
  131. half tangentSign = v.tangent.w * unity_WorldTransformParams.w;
  132. half3 worldBinormal = cross( worldNormal, worldTangent ) * tangentSign;
  133. o.tSpace0 = float4( worldTangent.x, worldBinormal.x, worldNormal.x, worldPos.x );
  134. o.tSpace1 = float4( worldTangent.y, worldBinormal.y, worldNormal.y, worldPos.y );
  135. o.tSpace2 = float4( worldTangent.z, worldBinormal.z, worldNormal.z, worldPos.z );
  136. o.customPack1.xy = customInputData.uv_texcoord;
  137. o.customPack1.xy = v.texcoord;
  138. o.customPack1.z = customInputData.eyeDepth;
  139. o.customPack2.xyzw = customInputData.screenPosition;
  140. o.worldPos = worldPos;
  141. TRANSFER_SHADOW_CASTER_NORMALOFFSET( o )
  142. return o;
  143. }
  144. half4 frag( v2f IN
  145. #if !defined( CAN_SKIP_VPOS )
  146. , UNITY_VPOS_TYPE vpos : VPOS
  147. #endif
  148. ) : SV_Target
  149. {
  150. UNITY_SETUP_INSTANCE_ID( IN );
  151. Input surfIN;
  152. UNITY_INITIALIZE_OUTPUT( Input, surfIN );
  153. surfIN.uv_texcoord = IN.customPack1.xy;
  154. surfIN.eyeDepth = IN.customPack1.z;
  155. surfIN.screenPosition = IN.customPack2.xyzw;
  156. float3 worldPos = IN.worldPos;
  157. half3 worldViewDir = normalize( UnityWorldSpaceViewDir( worldPos ) );
  158. SurfaceOutputStandardSpecular o;
  159. UNITY_INITIALIZE_OUTPUT( SurfaceOutputStandardSpecular, o )
  160. surf( surfIN, o );
  161. #if defined( CAN_SKIP_VPOS )
  162. float2 vpos = IN.pos;
  163. #endif
  164. half alphaRef = tex3D( _DitherMaskLOD, float3( vpos.xy * 0.25, o.Alpha * 0.9375 ) ).a;
  165. clip( alphaRef - 0.01 );
  166. SHADOW_CASTER_FRAGMENT( IN )
  167. }
  168. ENDCG
  169. }
  170. }
  171. Fallback "Diffuse"
  172. CustomEditor "ASEMaterialInspector"
  173. }
  174. /*ASEBEGIN
  175. Version=18000
  176. 138;603;1314;779;-420.926;1214.484;1;True;False
  177. Node;AmplifyShaderEditor.CommentaryNode;36;-614.4681,147.5472;Inherit;False;1047.541;403.52;Scale depth from start to end;8;30;65;28;29;34;31;33;15;;1,1,1,1;0;0
  178. Node;AmplifyShaderEditor.CommentaryNode;37;-642.2845,436.0103;Inherit;False;297.1897;243;Correction for near plane clipping;1;19;;1,1,1,1;0;0
  179. Node;AmplifyShaderEditor.ProjectionParams;19;-569.5846,485.3106;Inherit;False;0;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  180. Node;AmplifyShaderEditor.RangedFloatNode;30;-514.3924,366.5423;Float;False;Property;_StartDitheringFade;Start Dithering Fade;5;0;Create;True;0;0;False;0;0;0;0;0;0;1;FLOAT;0
  181. Node;AmplifyShaderEditor.SimpleAddOpNode;65;-292.6006,432.4742;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
  182. Node;AmplifyShaderEditor.SurfaceDepthNode;15;-548.9092,245.6595;Inherit;False;0;1;0;FLOAT3;0,0,0;False;1;FLOAT;0
  183. Node;AmplifyShaderEditor.NegateNode;33;-128.513,305.9936;Inherit;False;1;0;FLOAT;0;False;1;FLOAT;0
  184. Node;AmplifyShaderEditor.RangedFloatNode;31;-94.72766,414.6467;Float;False;Property;_EndDitheringFade;End Dithering Fade;6;0;Create;True;0;0;False;0;1;3.65;0;0;0;1;FLOAT;0
  185. Node;AmplifyShaderEditor.SimpleSubtractOpNode;29;111.6721,444.1465;Inherit;False;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
  186. Node;AmplifyShaderEditor.SimpleAddOpNode;28;32.4718,228.2474;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
  187. Node;AmplifyShaderEditor.TextureCoordinatesNode;47;30.18783,-726.4668;Inherit;False;0;44;2;3;2;SAMPLER2D;;False;0;FLOAT2;1,1;False;1;FLOAT2;0,0;False;5;FLOAT2;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  188. Node;AmplifyShaderEditor.SamplerNode;44;381.7223,-933.9919;Inherit;True;Property;_Albedo;Albedo;1;0;Create;True;0;0;False;0;-1;None;7130c16fd8005b546b111d341310a9a4;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;0,0;False;1;FLOAT2;1,0;False;2;FLOAT;1;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  189. Node;AmplifyShaderEditor.SimpleDivideOpNode;34;282.5719,241.847;Inherit;False;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
  190. Node;AmplifyShaderEditor.SamplerNode;45;384,-496;Inherit;True;Property;_Normal;Normal;2;1;[NoScaleOffset];Create;True;0;0;False;0;-1;None;11f03d9db1a617e40b7ece71f0a84f6f;True;0;True;bump;Auto;True;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;0,0;False;1;FLOAT2;1,0;False;2;FLOAT;1;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;5;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  191. Node;AmplifyShaderEditor.RangedFloatNode;81;1328.11,-1269.861;Float;False;Property;_Float0;Float 0;7;0;Create;True;0;0;False;0;1;5;0;0;0;1;FLOAT;0
  192. Node;AmplifyShaderEditor.DitheringNode;26;480,336;Inherit;False;1;False;3;0;FLOAT;0;False;1;SAMPLER2D;;False;2;FLOAT4;0,0,0,0;False;1;FLOAT;0
  193. Node;AmplifyShaderEditor.SamplerNode;46;384,-304;Inherit;True;Property;_Specular;Specular;3;1;[NoScaleOffset];Create;True;0;0;False;0;-1;None;6618005f6bafebf40b3d09f498401fba;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;0,0;False;1;FLOAT2;1,0;False;2;FLOAT;1;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  194. Node;AmplifyShaderEditor.SamplerNode;48;384,-112;Inherit;True;Property;_Occlusion;Occlusion;4;1;[NoScaleOffset];Create;True;0;0;False;0;-1;None;e477163a653bf6246954b3fea8ea8875;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;0,0;False;1;FLOAT2;1,0;False;2;FLOAT;1;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  195. Node;AmplifyShaderEditor.ColorNode;76;972.1442,-1126.272;Inherit;False;Property;_Color0;Color 0;8;0;Create;True;0;0;False;0;0.0518868,0.1491979,1,0.1921569;0.3632075,0.9630049,1,0.1921569;True;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  196. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;74;1427.267,-993.2541;Inherit;False;4;4;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;COLOR;0
  197. Node;AmplifyShaderEditor.SimpleSubtractOpNode;27;736,256;Inherit;False;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
  198. Node;AmplifyShaderEditor.WireNode;49;847.9045,48.44281;Inherit;False;1;0;FLOAT;0;False;1;FLOAT;0
  199. Node;AmplifyShaderEditor.WireNode;67;912.9339,-221.6186;Inherit;False;1;0;COLOR;0,0,0,0;False;1;COLOR;0
  200. Node;AmplifyShaderEditor.WireNode;51;958.768,-424.4502;Inherit;False;1;0;FLOAT3;0,0,0;False;1;FLOAT3;0
  201. Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;1796.74,-722.613;Half;False;True;-1;2;ASEMaterialInspector;0;0;StandardSpecular;ASESampleShaders/DitheringFade;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;Back;0;False;-1;3;False;-1;False;0;False;-1;0;False;-1;False;0;Custom;0.74;True;True;0;False;Transparent;;AlphaTest;All;14;all;True;True;True;True;0;False;-1;False;0;False;-1;255;False;-1;255;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;False;0;4;10;25;False;0.5;True;0;0;False;-1;0;False;-1;0;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;0;0,0,0,0;VertexOffset;True;False;Cylindrical;False;Relative;0;;0;-1;-1;-1;0;False;0;0;False;-1;-1;0;False;-1;0;0;0;False;0.1;False;-1;0;False;-1;16;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;2;FLOAT3;0,0,0;False;3;FLOAT3;0,0,0;False;4;FLOAT;0;False;5;FLOAT;0;False;6;FLOAT3;0,0,0;False;7;FLOAT3;0,0,0;False;8;FLOAT;0;False;9;FLOAT;0;False;10;FLOAT;0;False;13;FLOAT3;0,0,0;False;11;FLOAT3;0,0,0;False;12;FLOAT3;0,0,0;False;14;FLOAT4;0,0,0,0;False;15;FLOAT3;0,0,0;False;0
  202. WireConnection;65;0;30;0
  203. WireConnection;65;1;19;2
  204. WireConnection;33;0;65;0
  205. WireConnection;29;0;31;0
  206. WireConnection;29;1;65;0
  207. WireConnection;28;0;15;0
  208. WireConnection;28;1;33;0
  209. WireConnection;44;1;47;0
  210. WireConnection;34;0;28;0
  211. WireConnection;34;1;29;0
  212. WireConnection;45;1;47;0
  213. WireConnection;46;1;47;0
  214. WireConnection;48;1;47;0
  215. WireConnection;74;0;44;0
  216. WireConnection;74;1;76;0
  217. WireConnection;74;2;76;4
  218. WireConnection;74;3;81;0
  219. WireConnection;27;0;34;0
  220. WireConnection;27;1;26;0
  221. WireConnection;49;0;48;1
  222. WireConnection;67;0;46;0
  223. WireConnection;51;0;45;0
  224. WireConnection;0;0;74;0
  225. WireConnection;0;1;51;0
  226. WireConnection;0;3;67;0
  227. WireConnection;0;5;49;0
  228. WireConnection;0;9;74;0
  229. WireConnection;0;10;27;0
  230. ASEEND*/
  231. //CHKSM=0FBA00BFA9C3A75513DB095EAAB1804FD9FAC9E7