InvertShader.shader 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. Shader "Custom/InvertShader"
  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. #pragma multi_compile_instancing
  17. #include "UnityCG.cginc"
  18. struct appdata
  19. {
  20. float4 vertex : POSITION;
  21. float2 uv : TEXCOORD0;
  22. UNITY_VERTEX_INPUT_INSTANCE_ID
  23. };
  24. struct v2f
  25. {
  26. float2 uv : TEXCOORD0;
  27. float4 vertex : SV_POSITION;
  28. UNITY_VERTEX_OUTPUT_STEREO
  29. };
  30. v2f vert(appdata v)
  31. {
  32. v2f o;
  33. UNITY_SETUP_INSTANCE_ID(v);
  34. UNITY_INITIALIZE_OUTPUT(v2f, o); //Insert
  35. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); //Insert
  36. o.vertex = UnityObjectToClipPos(v.vertex);
  37. o.uv = v.uv;
  38. return o;
  39. }
  40. //sampler2D _MainTex;
  41. UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex); //Insert
  42. fixed4 frag(v2f i) : SV_Target
  43. {
  44. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); //Insert
  45. fixed4 col = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, i.uv); //Insert
  46. // just invert the colors
  47. col.rgb = 1 - col.rgb;
  48. return col;
  49. }
  50. ENDCG
  51. }
  52. }
  53. }