Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. //
  2. // KinoGlitch - Video glitch effect
  3. //
  4. // Copyright (C) 2015 Keijiro Takahashi
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy of
  7. // this software and associated documentation files (the "Software"), to deal in
  8. // the Software without restriction, including without limitation the rights to
  9. // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10. // the Software, and to permit persons to whom the Software is furnished to do so,
  11. // subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in all
  14. // copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. Shader "Kino/Glitch/Digital"
  24. {
  25. Properties
  26. {
  27. _MainTex ("-", 2D) = "" {}
  28. _NoiseTex ("-", 2D) = "" {}
  29. _TrashTex ("-", 2D) = "" {}
  30. }
  31.  
  32. CGINCLUDE
  33.  
  34. #include "UnityCG.cginc"
  35.  
  36. sampler2D _MainTex;
  37. sampler2D _NoiseTex;
  38. sampler2D _TrashTex;
  39. float _Intensity;
  40.  
  41. float4 frag(v2f_img i) : SV_Target
  42. {
  43. float4 glitch = tex2D(_NoiseTex, i.uv);
  44.  
  45. float thresh = 1.001 - _Intensity * 1.001;
  46. float w_d = step(thresh, pow(glitch.z, 2.5)); // displacement glitch
  47. float w_f = step(thresh, pow(glitch.w, 2.5)); // frame glitch
  48. float w_c = step(thresh, pow(glitch.z, 3.5)); // color glitch
  49.  
  50. // Displacement.
  51. float2 uv = frac(i.uv + glitch.xy * w_d);
  52. float4 source = tex2D(_MainTex, uv);
  53.  
  54. // Mix with trash frame.
  55. float3 color = lerp(source, tex2D(_TrashTex, uv), w_f).rgb;
  56.  
  57. // Shuffle color components.
  58. float3 neg = saturate(color.grb + (1 - dot(color, 1)) * 0.5);
  59. color = lerp(color, neg, w_c);
  60.  
  61. return float4(color, source.a);
  62. }
  63.  
  64. ENDCG
  65.  
  66. SubShader
  67. {
  68. Pass
  69. {
  70. ZTest Always Cull Off ZWrite Off
  71. CGPROGRAM
  72. #pragma vertex vert_img
  73. #pragma fragment frag
  74. #pragma target 3.0
  75. ENDCG
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement