DitheringFadeADON.shader 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Made with Amplify Shader Editor
  2. // Available at the Unity Asset Store - http://u3d.as/y3X
  3. Shader "ADON/DitheringFadeADON"
  4. {
  5. Properties
  6. {
  7. _Cutoff( "Mask Clip Value", Float ) = 0.69
  8. [NoScaleOffset]_Normal("Normal", 2D) = "bump" {}
  9. [NoScaleOffset]_Specular("Specular", 2D) = "bump" {}
  10. [NoScaleOffset]_Occlusion("Occlusion", 2D) = "white" {}
  11. _StartDitheringFade("Start Dithering Fade", Float) = 0
  12. _EndDitheringFade("End Dithering Fade", Float) = 1
  13. _Color0("Color 0", Color) = (0,0.4995098,1,0)
  14. [HideInInspector] _texcoord( "", 2D ) = "white" {}
  15. [HideInInspector] __dirty( "", Int ) = 1
  16. }
  17. SubShader
  18. {
  19. Tags{ "RenderType" = "TransparentCutout" "Queue" = "AlphaTest+0" }
  20. Cull Back
  21. CGPROGRAM
  22. #include "UnityShaderVariables.cginc"
  23. #pragma target 3.0
  24. #pragma exclude_renderers xboxseries playstation
  25. #pragma surface surf StandardSpecular keepalpha addshadow fullforwardshadows vertex:vertexDataFunc
  26. struct Input
  27. {
  28. float2 uv_texcoord;
  29. float eyeDepth;
  30. float4 screenPosition;
  31. };
  32. uniform sampler2D _Normal;
  33. uniform half4 _Color0;
  34. uniform sampler2D _Specular;
  35. uniform sampler2D _Occlusion;
  36. uniform float _StartDitheringFade;
  37. uniform float _EndDitheringFade;
  38. uniform float _Cutoff = 0.69;
  39. inline float Dither8x8Bayer( int x, int y )
  40. {
  41. const float dither[ 64 ] = {
  42. 1, 49, 13, 61, 4, 52, 16, 64,
  43. 33, 17, 45, 29, 36, 20, 48, 32,
  44. 9, 57, 5, 53, 12, 60, 8, 56,
  45. 41, 25, 37, 21, 44, 28, 40, 24,
  46. 3, 51, 15, 63, 2, 50, 14, 62,
  47. 35, 19, 47, 31, 34, 18, 46, 30,
  48. 11, 59, 7, 55, 10, 58, 6, 54,
  49. 43, 27, 39, 23, 42, 26, 38, 22};
  50. int r = y * 8 + x;
  51. return dither[r] / 64; // same # of instructions as pre-dividing due to compiler magic
  52. }
  53. void vertexDataFunc( inout appdata_full v, out Input o )
  54. {
  55. UNITY_INITIALIZE_OUTPUT( Input, o );
  56. o.eyeDepth = -UnityObjectToViewPos( v.vertex.xyz ).z;
  57. float4 ase_screenPos = ComputeScreenPos( UnityObjectToClipPos( v.vertex ) );
  58. o.screenPosition = ase_screenPos;
  59. }
  60. void surf( Input i , inout SurfaceOutputStandardSpecular o )
  61. {
  62. float2 uv_Normal45 = i.uv_texcoord;
  63. o.Normal = UnpackNormal( tex2D( _Normal, uv_Normal45 ) );
  64. o.Albedo = _Color0.rgb;
  65. float2 uv_Specular46 = i.uv_texcoord;
  66. o.Specular = UnpackNormal( tex2D( _Specular, uv_Specular46 ) );
  67. float2 uv_Occlusion48 = i.uv_texcoord;
  68. o.Occlusion = tex2D( _Occlusion, uv_Occlusion48 ).r;
  69. o.Alpha = 1;
  70. half temp_output_65_0 = ( _StartDitheringFade + _ProjectionParams.y );
  71. float4 ase_screenPos = i.screenPosition;
  72. half4 ase_screenPosNorm = ase_screenPos / ase_screenPos.w;
  73. ase_screenPosNorm.z = ( UNITY_NEAR_CLIP_VALUE >= 0 ) ? ase_screenPosNorm.z : ase_screenPosNorm.z * 0.5 + 0.5;
  74. half2 clipScreen26 = ase_screenPosNorm.xy * _ScreenParams.xy;
  75. half dither26 = Dither8x8Bayer( fmod(clipScreen26.x, 8), fmod(clipScreen26.y, 8) );
  76. clip( ( ( ( i.eyeDepth + -temp_output_65_0 ) / ( _EndDitheringFade - temp_output_65_0 ) ) - dither26 ) - _Cutoff );
  77. }
  78. ENDCG
  79. }
  80. Fallback "Diffuse"
  81. CustomEditor "ASEMaterialInspector"
  82. }
  83. /*ASEBEGIN
  84. Version=18909
  85. 139;237;1473;735;441.1366;634.6578;1.309449;True;True
  86. Node;AmplifyShaderEditor.CommentaryNode;36;-622.9761,91.39496;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
  87. Node;AmplifyShaderEditor.CommentaryNode;37;-609.7847,546.5101;Inherit;False;297.1897;243;Correction for near plane clipping;1;19;;1,1,1,1;0;0
  88. Node;AmplifyShaderEditor.ProjectionParams;19;-537.0848,595.81;Inherit;False;0;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  89. Node;AmplifyShaderEditor.RangedFloatNode;30;-584.0002,374.09;Float;False;Property;_StartDitheringFade;Start Dithering Fade;5;0;Create;True;0;0;0;False;0;False;0;0;0;0;0;1;FLOAT;0
  90. Node;AmplifyShaderEditor.SimpleAddOpNode;65;-298.5083,377.6221;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
  91. Node;AmplifyShaderEditor.RangedFloatNode;31;-117.5356,335.0947;Float;False;Property;_EndDitheringFade;End Dithering Fade;6;0;Create;True;0;0;0;False;0;False;1;1;0;0;0;1;FLOAT;0
  92. Node;AmplifyShaderEditor.SurfaceDepthNode;15;-557.4172,189.5072;Inherit;False;0;1;0;FLOAT3;0,0,0;False;1;FLOAT;0
  93. Node;AmplifyShaderEditor.NegateNode;33;-107.1209,253.7414;Inherit;False;1;0;FLOAT;0;False;1;FLOAT;0
  94. Node;AmplifyShaderEditor.SimpleAddOpNode;28;101.9639,194.1952;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
  95. Node;AmplifyShaderEditor.SimpleSubtractOpNode;29;99.26421,348.9946;Inherit;False;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
  96. Node;AmplifyShaderEditor.SamplerNode;48;384,-112;Inherit;True;Property;_Occlusion;Occlusion;4;1;[NoScaleOffset];Create;True;0;0;0;False;0;False;-1;None;None;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;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;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  97. Node;AmplifyShaderEditor.DitheringNode;26;480,336;Inherit;False;1;False;4;0;FLOAT;0;False;1;SAMPLER2D;;False;2;FLOAT4;0,0,0,0;False;3;SAMPLERSTATE;;False;1;FLOAT;0
  98. Node;AmplifyShaderEditor.SamplerNode;45;384,-496;Inherit;True;Property;_Normal;Normal;2;1;[NoScaleOffset];Create;True;0;0;0;False;0;False;-1;None;6e6d9f14a659da64eb94fbf51c769431;True;0;True;bump;Auto;True;Object;-1;Auto;Texture2D;8;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;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  99. Node;AmplifyShaderEditor.SamplerNode;46;384,-304;Inherit;True;Property;_Specular;Specular;3;1;[NoScaleOffset];Create;True;0;0;0;False;0;False;-1;None;1e959a38ba2a5b341830e7a0ffd5f2cb;True;0;True;bump;Auto;True;Object;-1;Auto;Texture2D;8;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;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  100. Node;AmplifyShaderEditor.SimpleDivideOpNode;34;285.764,250.6948;Inherit;False;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
  101. Node;AmplifyShaderEditor.ColorNode;68;918.0718,-347.8884;Inherit;False;Property;_Color0;Color 0;7;0;Create;True;0;0;0;False;0;False;0,0.4995098,1,0;0,0.7788601,1,1;True;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  102. Node;AmplifyShaderEditor.SamplerNode;44;384,-688;Inherit;True;Property;_Albedo;Albedo;1;0;Create;True;0;0;0;False;0;False;-1;None;None;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;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;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  103. Node;AmplifyShaderEditor.SimpleSubtractOpNode;27;736,256;Inherit;False;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
  104. Node;AmplifyShaderEditor.WireNode;51;857.5114,-90.67801;Inherit;False;1;0;FLOAT3;0,0,0;False;1;FLOAT3;0
  105. Node;AmplifyShaderEditor.WireNode;49;847.9045,48.44281;Inherit;False;1;0;FLOAT;0;False;1;FLOAT;0
  106. Node;AmplifyShaderEditor.WireNode;67;852.93,-28.48083;Inherit;False;1;0;FLOAT3;0,0,0;False;1;FLOAT3;0
  107. Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;999.2003,-69.70003;Half;False;True;-1;2;ASEMaterialInspector;0;0;StandardSpecular;ADON/DitheringFadeADON;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;Masked;0.69;True;True;0;False;TransparentCutout;;AlphaTest;All;14;d3d9;d3d11_9x;d3d11;glcore;gles;gles3;metal;vulkan;xbox360;xboxone;ps4;psp2;n3ds;wiiu;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;False;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
  108. WireConnection;65;0;30;0
  109. WireConnection;65;1;19;2
  110. WireConnection;33;0;65;0
  111. WireConnection;28;0;15;0
  112. WireConnection;28;1;33;0
  113. WireConnection;29;0;31;0
  114. WireConnection;29;1;65;0
  115. WireConnection;34;0;28;0
  116. WireConnection;34;1;29;0
  117. WireConnection;27;0;34;0
  118. WireConnection;27;1;26;0
  119. WireConnection;51;0;45;0
  120. WireConnection;49;0;48;1
  121. WireConnection;67;0;46;0
  122. WireConnection;0;0;68;0
  123. WireConnection;0;1;51;0
  124. WireConnection;0;3;67;0
  125. WireConnection;0;5;49;0
  126. WireConnection;0;10;27;0
  127. ASEEND*/
  128. //CHKSM=837E896EB3A0D76337E35CA446025FAC62FF6EAC