GrayscaleEffect.shader 721 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. Shader "Hidden/Grayscale Effect" {
  2. Properties {
  3. _MainTex ("Base (RGB)", 2D) = "white" {}
  4. _RampTex ("Base (RGB)", 2D) = "grayscaleRamp" {}
  5. }
  6. SubShader {
  7. Pass {
  8. ZTest Always Cull Off ZWrite Off
  9. Fog { Mode off }
  10. CGPROGRAM
  11. #pragma vertex vert_img
  12. #pragma fragment frag
  13. #pragma fragmentoption ARB_precision_hint_fastest
  14. #include "UnityCG.cginc"
  15. uniform sampler2D _MainTex;
  16. uniform sampler2D _RampTex;
  17. uniform half _RampOffset;
  18. fixed4 frag (v2f_img i) : COLOR
  19. {
  20. fixed4 original = tex2D(_MainTex, i.uv);
  21. fixed grayscale = Luminance(original.rgb);
  22. half2 remap = half2 (grayscale + _RampOffset, .5);
  23. fixed4 output = tex2D(_RampTex, remap);
  24. output.a = original.a;
  25. return output;
  26. }
  27. ENDCG
  28. }
  29. }
  30. Fallback off
  31. }