EdgeCheck.shader 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Hidden/EdgeCheck"
  3. {
  4. Properties
  5. {
  6. _MainTex ("Texture", 2D) = "white" {}
  7. _WaveTex ("Wave Texture", 2D) = "black" {}
  8. _Color ("Edge Line Color", Color) = (0,1,1,0)
  9. }
  10. SubShader
  11. {
  12. // No culling or depth
  13. Cull Off ZWrite Off ZTest Always
  14. Pass
  15. {
  16. CGPROGRAM
  17. #pragma vertex vert
  18. #pragma fragment frag
  19. #include "UnityCG.cginc"
  20. struct appdata
  21. {
  22. float4 vertex : POSITION;
  23. float2 uv : TEXCOORD0;
  24. };
  25. struct v2f
  26. {
  27. float2 uv : TEXCOORD0;
  28. float4 vertex : SV_POSITION;
  29. float2 texcoord : TEXCOORD1;
  30. float2 texcoord1 : TEXCOORD2;
  31. };
  32. sampler2D _WaveTex;
  33. uniform half4 _WaveTex_ST;
  34. uniform half4 _WaveTex1_ST;
  35. v2f vert (appdata v)
  36. {
  37. v2f o;
  38. o.vertex = UnityObjectToClipPos(v.vertex);
  39. o.uv = v.uv;
  40. o.texcoord = TRANSFORM_TEX(v.uv,_WaveTex);
  41. o.texcoord1 = TRANSFORM_TEX(v.uv,_WaveTex1);
  42. return o;
  43. }
  44. sampler2D _MainTex;
  45. fixed4 _Color;
  46. uniform fixed _Offset;
  47. uniform fixed _delta;
  48. fixed4 frag (v2f i) : SV_Target
  49. {
  50. fixed4 col = tex2D(_MainTex, i.uv);
  51. fixed4 colABlock = tex2D(_MainTex,i.uv+fixed2(_Offset,-_Offset));
  52. fixed col_L = Luminance(col.rgb);
  53. fixed colABlock_L = Luminance(colABlock.rgb);
  54. fixed4 mask = tex2D(_WaveTex,i.texcoord);
  55. fixed4 mask1 = tex2D(_WaveTex,i.texcoord1);
  56. // if(abs(col_L - colABlock_L) > _delta){
  57. // col = _Color * mask.a + col * (1-mask.a);
  58. // }
  59. // col = _Color * mask.r + col * (1-mask.r);
  60. fixed blockValue = 1 - (abs(col_L - colABlock_L) - _delta)*(1/_delta)*2;
  61. blockValue = clamp(blockValue ,0,1);
  62. col = lerp(col,_Color,(1-blockValue)*(mask.a+mask1.a));
  63. col = _Color * mask.r + col * (1-mask.r);
  64. // colABlock = tex2D(_MainTex,i.uv+fixed2(0.0015,0.0015));
  65. // colABlock_L = Luminance(colABlock.rgb);
  66. // if(abs(col_L - colABlock_L) > 0.1){
  67. // col = _Color;
  68. // }
  69. // col = fixed4(colNextBlock_L,colNextBlock_L,colNextBlock_L,0);
  70. // just invert the colors
  71. return col;
  72. }
  73. ENDCG
  74. }
  75. }
  76. }