Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.34 KB | None | 0 0
  1. Shader "Custom/Blur" {
  2. Properties {
  3. _Color ("Main Color", Color) = (1,1,1,1)
  4. _BumpAmt ("Distortion", Range (0,128)) = 10
  5. _MainTex ("Tint Color (RGB)", 2D) = "white" {}
  6. _BumpMap ("Normalmap", 2D) = "bump" {}
  7. _Size ("Size", Range(0, 20)) = 1
  8. }
  9.  
  10. Category {
  11.  
  12. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Opaque" }
  13.  
  14.  
  15. SubShader {
  16.  
  17. GrabPass {
  18. Tags { "LightMode" = "Always" }
  19. }
  20. Pass {
  21. Tags { "LightMode" = "Always" }
  22.  
  23. CGPROGRAM
  24. #pragma vertex vert
  25. #pragma fragment frag
  26. #pragma fragmentoption ARB_precision_hint_fastest
  27. #include "UnityCG.cginc"
  28.  
  29. struct appdata_t {
  30. float4 vertex : POSITION;
  31. float2 texcoord: TEXCOORD0;
  32. };
  33.  
  34. struct v2f {
  35. float4 vertex : POSITION;
  36. float4 uvgrab : TEXCOORD0;
  37. };
  38.  
  39. v2f vert (appdata_t v) {
  40. v2f o;
  41. o.vertex = UnityObjectToClipPos(v.vertex);
  42. #if UNITY_UV_STARTS_AT_TOP
  43. float scale = -1.0;
  44. #else
  45. float scale = 1.0;
  46. #endif
  47. o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
  48. o.uvgrab.zw = o.vertex.zw;
  49. return o;
  50. }
  51.  
  52. sampler2D _GrabTexture;
  53. float4 _GrabTexture_TexelSize;
  54. float _Size;
  55.  
  56. half4 frag( v2f i ) : COLOR {
  57.  
  58. half4 sum = half4(0,0,0,0);
  59. #define GRABPIXEL(weight,kernelx) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x + _GrabTexture_TexelSize.x * kernelx*_Size, i.uvgrab.y, i.uvgrab.z, i.uvgrab.w))) * weight
  60. sum += GRABPIXEL(0.05, -4.0);
  61. sum += GRABPIXEL(0.09, -3.0);
  62. sum += GRABPIXEL(0.12, -2.0);
  63. sum += GRABPIXEL(0.15, -1.0);
  64. sum += GRABPIXEL(0.18, 0.0);
  65. sum += GRABPIXEL(0.15, +1.0);
  66. sum += GRABPIXEL(0.12, +2.0);
  67. sum += GRABPIXEL(0.09, +3.0);
  68. sum += GRABPIXEL(0.05, +4.0);
  69.  
  70. return sum;
  71. }
  72. ENDCG
  73. }
  74.  
  75. GrabPass {
  76. Tags { "LightMode" = "Always" }
  77. }
  78. Pass {
  79. Tags { "LightMode" = "Always" }
  80.  
  81. CGPROGRAM
  82. #pragma vertex vert
  83. #pragma fragment frag
  84. #pragma fragmentoption ARB_precision_hint_fastest
  85. #include "UnityCG.cginc"
  86.  
  87. struct appdata_t {
  88. float4 vertex : POSITION;
  89. float2 texcoord: TEXCOORD0;
  90. };
  91.  
  92. struct v2f {
  93. float4 vertex : POSITION;
  94. float4 uvgrab : TEXCOORD0;
  95. };
  96.  
  97. v2f vert (appdata_t v) {
  98. v2f o;
  99. o.vertex = UnityObjectToClipPos(v.vertex);
  100. #if UNITY_UV_STARTS_AT_TOP
  101. float scale = -1.0;
  102. #else
  103. float scale = 1.0;
  104. #endif
  105. o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
  106. o.uvgrab.zw = o.vertex.zw;
  107. return o;
  108. }
  109.  
  110. sampler2D _GrabTexture;
  111. float4 _GrabTexture_TexelSize;
  112. float _Size;
  113.  
  114. half4 frag( v2f i ) : COLOR {
  115.  
  116. half4 sum = half4(0,0,0,0);
  117. #define GRABPIXEL(weight,kernely) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x, i.uvgrab.y + _GrabTexture_TexelSize.y * kernely*_Size, i.uvgrab.z, i.uvgrab.w))) * weight
  118.  
  119. sum += GRABPIXEL(0.05, -4.0);
  120. sum += GRABPIXEL(0.09, -3.0);
  121. sum += GRABPIXEL(0.12, -2.0);
  122. sum += GRABPIXEL(0.15, -1.0);
  123. sum += GRABPIXEL(0.18, 0.0);
  124. sum += GRABPIXEL(0.15, +1.0);
  125. sum += GRABPIXEL(0.12, +2.0);
  126. sum += GRABPIXEL(0.09, +3.0);
  127. sum += GRABPIXEL(0.05, +4.0);
  128.  
  129. return sum;
  130. }
  131. ENDCG
  132. }
  133.  
  134. GrabPass {
  135. Tags { "LightMode" = "Always" }
  136. }
  137. Pass {
  138. Tags { "LightMode" = "Always" }
  139.  
  140. CGPROGRAM
  141. #pragma vertex vert
  142. #pragma fragment frag
  143. #pragma fragmentoption ARB_precision_hint_fastest
  144. #include "UnityCG.cginc"
  145.  
  146. struct appdata_t {
  147. float4 vertex : POSITION;
  148. float2 texcoord: TEXCOORD0;
  149. };
  150.  
  151. struct v2f {
  152. float4 vertex : POSITION;
  153. float4 uvgrab : TEXCOORD0;
  154. float2 uvbump : TEXCOORD1;
  155. float2 uvmain : TEXCOORD2;
  156. };
  157.  
  158. float _BumpAmt;
  159. float4 _BumpMap_ST;
  160. float4 _MainTex_ST;
  161.  
  162. v2f vert (appdata_t v) {
  163. v2f o;
  164. o.vertex = UnityObjectToClipPos(v.vertex);
  165. #if UNITY_UV_STARTS_AT_TOP
  166. float scale = -1.0;
  167. #else
  168. float scale = 1.0;
  169. #endif
  170. o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
  171. o.uvgrab.zw = o.vertex.zw;
  172. o.uvbump = TRANSFORM_TEX( v.texcoord, _BumpMap );
  173. o.uvmain = TRANSFORM_TEX( v.texcoord, _MainTex );
  174. return o;
  175. }
  176.  
  177. fixed4 _Color;
  178. sampler2D _GrabTexture;
  179. float4 _GrabTexture_TexelSize;
  180. sampler2D _BumpMap;
  181. sampler2D _MainTex;
  182.  
  183. half4 frag( v2f i ) : COLOR {
  184.  
  185. half2 bump = UnpackNormal(tex2D( _BumpMap, i.uvbump )).rg;
  186. float2 offset = bump * _BumpAmt * _GrabTexture_TexelSize.xy;
  187. i.uvgrab.xy = offset * i.uvgrab.z + i.uvgrab.xy;
  188.  
  189. half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
  190. half4 tint = tex2D( _MainTex, i.uvmain ) * _Color;
  191.  
  192. return col * tint;
  193. }
  194. ENDCG
  195. }
  196. }
  197. }
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement