ContrastComposite.shader 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Hidden/ContrastComposite" {
  3. Properties {
  4. _MainTex ("Base (RGB)", 2D) = "" {}
  5. _MainTexBlurred ("Base Blurred (RGB)", 2D) = "" {}
  6. }
  7. // Shader code pasted into all further CGPROGRAM blocks
  8. CGINCLUDE
  9. #include "UnityCG.cginc"
  10. struct v2f {
  11. float4 pos : SV_POSITION;
  12. float2 uv[2] : TEXCOORD0;
  13. };
  14. sampler2D _MainTex;
  15. sampler2D _MainTexBlurred;
  16. float4 _MainTex_TexelSize;
  17. float intensity;
  18. float threshold;
  19. v2f vert( appdata_img v ) {
  20. v2f o;
  21. o.pos = UnityObjectToClipPos(v.vertex);
  22. o.uv[0] = v.texcoord.xy;
  23. o.uv[1] = v.texcoord.xy;
  24. #if UNITY_UV_STARTS_AT_TOP
  25. if (_MainTex_TexelSize.y < 0)
  26. o.uv[0].y = 1-o.uv[0].y;
  27. #endif
  28. return o;
  29. }
  30. half4 frag(v2f i) : SV_Target
  31. {
  32. half4 color = tex2D (_MainTex, i.uv[1]);
  33. half4 blurred = tex2D (_MainTexBlurred, (i.uv[0]));
  34. half4 difference = color - blurred;
  35. half4 signs = sign (difference);
  36. half4 enhancement = saturate (abs(difference) - threshold) * signs * 1.0/(1.0-threshold);
  37. color += enhancement * intensity;
  38. return color;
  39. }
  40. ENDCG
  41. Subshader {
  42. Pass {
  43. ZTest Always Cull Off ZWrite Off
  44. CGPROGRAM
  45. #pragma vertex vert
  46. #pragma fragment frag
  47. ENDCG
  48. }
  49. }
  50. Fallback off
  51. } // shader