EdgeDetectX.shader 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Hidden/Edge Detect X" {
  3. Properties {
  4. _MainTex ("Base (RGB)", 2D) = "white" {}
  5. _Treshold ("Treshold", Float) = 0.2
  6. }
  7. SubShader {
  8. Pass {
  9. ZTest Always Cull Off ZWrite Off
  10. Fog { Mode off }
  11. CGPROGRAM
  12. #pragma vertex vert
  13. #pragma fragment frag
  14. #pragma fragmentoption ARB_precision_hint_fastest
  15. #include "UnityCG.cginc"
  16. uniform sampler2D _MainTex;
  17. uniform float4 _MainTex_TexelSize;
  18. uniform float _Treshold;
  19. struct v2f {
  20. float4 pos : POSITION;
  21. float2 uv[3] : TEXCOORD0;
  22. };
  23. v2f vert( appdata_img v )
  24. {
  25. v2f o;
  26. o.pos = UnityObjectToClipPos (v.vertex);
  27. float2 uv = MultiplyUV( UNITY_MATRIX_TEXTURE0, v.texcoord );
  28. o.uv[0] = uv;
  29. o.uv[1] = uv + float2(-_MainTex_TexelSize.x, -_MainTex_TexelSize.y);
  30. o.uv[2] = uv + float2(+_MainTex_TexelSize.x, -_MainTex_TexelSize.y);
  31. return o;
  32. }
  33. half4 frag (v2f i) : COLOR
  34. {
  35. half4 original = tex2D(_MainTex, i.uv[0]);
  36. // a very simple cross gradient filter
  37. half3 p1 = original.rgb;
  38. half3 p2 = tex2D( _MainTex, i.uv[1] ).rgb;
  39. half3 p3 = tex2D( _MainTex, i.uv[2] ).rgb;
  40. half3 diff = p1 * 2 - p2 - p3;
  41. half len = dot(diff,diff);
  42. if( len >= _Treshold )
  43. original.rgb = 0;
  44. return original;
  45. }
  46. ENDCG
  47. }
  48. }
  49. Fallback off
  50. }