SwapChannelData.shader 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. Shader "Hidden/TriLib/SwapChannelData"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Texture", 2D) = "white" {}
  6. }
  7. SubShader
  8. {
  9. // No culling or depth
  10. Cull Off ZWrite Off ZTest Always
  11. Pass
  12. {
  13. CGPROGRAM
  14. #pragma vertex vert
  15. #pragma fragment frag
  16. #include "UnityCG.cginc"
  17. struct appdata
  18. {
  19. float4 vertex : POSITION;
  20. float2 uv : TEXCOORD0;
  21. };
  22. struct v2f
  23. {
  24. float2 uv : TEXCOORD0;
  25. float4 vertex : SV_POSITION;
  26. };
  27. v2f vert (appdata v)
  28. {
  29. v2f o;
  30. o.vertex = UnityObjectToClipPos(v.vertex);
  31. o.uv = v.uv;
  32. return o;
  33. }
  34. sampler2D _MainTex;
  35. int _ChannelIndexA;
  36. int _ChannelIndexB;
  37. fixed4 frag (v2f i) : SV_Target
  38. {
  39. fixed4 col = tex2D(_MainTex, i.uv);
  40. fixed a = col[_ChannelIndexA];
  41. fixed b = col[_ChannelIndexB];
  42. switch (_ChannelIndexA) {
  43. case 0:
  44. col.x = b;
  45. break;
  46. case 1:
  47. col.y = b;
  48. break;
  49. case 2:
  50. col.z = b;
  51. break;
  52. case 3:
  53. col.w = b;
  54. break;
  55. }
  56. switch (_ChannelIndexB) {
  57. case 0:
  58. col.x = a;
  59. break;
  60. case 1:
  61. col.y = a;
  62. break;
  63. case 2:
  64. col.z = a;
  65. break;
  66. case 3:
  67. col.w = a;
  68. break;
  69. }
  70. return col;
  71. }
  72. ENDCG
  73. }
  74. }
  75. }