ChromaticAberrationShader.shader 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Hidden/ChromaticAberrationShader" {
  3. Properties {
  4. _MainTex ("Base (RGB)", 2D) = "" {}
  5. }
  6. // Shader code pasted into all further CGPROGRAM blocks
  7. CGINCLUDE
  8. #include "UnityCG.cginc"
  9. struct v2f {
  10. float4 pos : POSITION;
  11. float2 uv : TEXCOORD0;
  12. };
  13. // the color should come from a half rezolution buffer
  14. // and target a quarter resolution buffer
  15. sampler2D _MainTex;
  16. float4 _MainTex_TexelSize;
  17. float chromaticAberrationIntensity;
  18. v2f vert( appdata_img v ) {
  19. v2f o;
  20. o.pos = UnityObjectToClipPos(v.vertex);
  21. #ifdef SHADER_API_D3D9
  22. if (_MainTex_TexelSize.y < 0)
  23. v.texcoord.y = 1.0 - v.texcoord.y ;
  24. #endif
  25. o.uv = v.texcoord.xy;
  26. return o;
  27. }
  28. half4 fragSimpleCopy(v2f i) : COLOR {
  29. return tex2D(_MainTex, i.uv.xy);
  30. }
  31. half4 frag(v2f i) : COLOR {
  32. half2 coords = i.uv;
  33. half2 uv = i.uv;
  34. coords = (coords - 0.5) * 2.0;
  35. half coordDot = dot (coords,coords);
  36. float2 uvG = uv - _MainTex_TexelSize.xy * chromaticAberrationIntensity * coords * coordDot;
  37. half4 color = tex2D (_MainTex, uv);
  38. #if SHADER_API_D3D9
  39. // Work around Cg's code generation bug for D3D9 pixel shaders :(
  40. color.g = color.g * 0.0001 + tex2D (_MainTex, uvG).g;
  41. #else
  42. color.g = tex2D (_MainTex, uvG).g;
  43. #endif
  44. return color;
  45. }
  46. ENDCG
  47. Subshader {
  48. Pass {
  49. ZTest Always Cull Off ZWrite Off
  50. Fog { Mode off }
  51. CGPROGRAM
  52. #pragma vertex vert
  53. #pragma fragment fragSimpleCopy
  54. ENDCG
  55. }
  56. Pass {
  57. ZTest Always Cull Off ZWrite Off
  58. Fog { Mode off }
  59. CGPROGRAM
  60. #pragma vertex vert
  61. #pragma fragment frag
  62. ENDCG
  63. }
  64. }
  65. Fallback off
  66. } // shader