Hyluss

Untitled

Nov 26th, 2019
285
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2.  
  3. Shader "Custom/SpriteWithMask" {
  4. Properties
  5. {
  6. _MainTex ("Base", 2D) = "white" {}
  7. _MaskTex ("Mask", 2D) = "white" {}
  8. _Color ("Color", Color) = (0.5, 0.5, 0.5, 0.5)
  9. }
  10.  
  11. SubShader
  12. {
  13. Pass
  14. {
  15. // Blend SrcAlpha OneMinusSrcAlpha
  16. // inside SubShader
  17. //Tags { "Queue"="Transparent" "RenderType"="Transparent" "IgnoreProjector"="True" }
  18.  
  19. // inside Pass
  20. //ZWrite Off
  21. Blend SrcAlpha OneMinusSrcAlpha
  22.  
  23. CGPROGRAM
  24. #pragma vertex vert
  25. #pragma fragment frag
  26. #include "UnityCG.cginc"
  27.  
  28. uniform int ArrayLength = 0;
  29. uniform float Array[1023];
  30.  
  31. sampler2D _MainTex;
  32. sampler2D _MaskTex;
  33. float4 _Color;
  34.  
  35. struct v2f
  36. {
  37. float4 pos : SV_POSITION;
  38. float2 uv1 : TEXCOORD0;
  39. float2 uv2 : TEXCOORD1;
  40. };
  41.  
  42. float4 _MainTex_ST;
  43. float4 _MaskTex_ST;
  44.  
  45. v2f vert (appdata_base v)
  46. {
  47. v2f o;
  48. o.pos = UnityObjectToClipPos (v.vertex);
  49. o.uv1 = TRANSFORM_TEX (v.texcoord, _MainTex);
  50. o.uv2 = TRANSFORM_TEX (v.texcoord, _MaskTex);
  51. return o;
  52. }
  53.  
  54. fixed4 frag (v2f i) : COLOR
  55. {
  56.  
  57. fixed4 base = tex2D (_MainTex, i.uv1);
  58. fixed4 mask = tex2D (_MaskTex, i.uv2);
  59.  
  60. if(ArrayLength==0)
  61. {
  62. return base * _Color;
  63. }
  64.  
  65. for (int i=0; i < ArrayLength ; i++)
  66. {
  67. if(Array[i] < 256)
  68. {
  69. if(Array[i] == mask.r)
  70. {
  71. return base;
  72. }
  73. }
  74. else if(Array[i] < 511)
  75. {
  76. if(Array[i] - 256 == mask.g)
  77. {
  78. return base;
  79. }
  80. }
  81. else
  82. {
  83. if(Array[i] - 512 == mask.b)
  84. {
  85. return base;
  86. }
  87. }
  88.  
  89. }
  90.  
  91. return fixed4(1,1,1,0);
  92.  
  93.  
  94.  
  95. // base.w = mask.x * mask.x * mask.x;
  96. // return base * (_Color * 2.0f);
  97. // return mask;
  98. // return half4(0,0,1,1);
  99. }
  100. ENDCG
  101. }
  102. }
  103. FallBack Off
  104. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment