Don't like ads? PRO users don't see any ads ;-)

ChromaticAberration

By: boofcw on May 2nd, 2012  |  syntax: C  |  size: 1.39 KB  |  hits: 51  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Shader "Hidden/ChromaticAberration"
  2. {
  3.         Properties
  4.         {
  5.                 _MainTex ( "Base (RGB)" , 2D ) = "white" {}
  6.                 _Scale ( "Scale" , Float ) = 1.0
  7.                 _ColorDelta ( "Scale" , Float ) = 0.05
  8.                 _CalculateFromCenter ( "Scale" , Float ) = 1
  9.                 _Falloff ( "_Falloff" , Float ) = 1
  10.                 _FalloffBuffer ( "_Falloff" , Float ) = 0
  11.         }
  12.        
  13.         SubShader
  14.         {
  15.                 Pass
  16.                 {
  17.                         ZTest Always Cull Off ZWrite Off
  18.                         Fog { Mode off }
  19.                                        
  20.                         CGPROGRAM
  21.                         #pragma vertex vert_img
  22.                         #pragma fragment frag
  23.                         #pragma fragmentoption ARB_precision_hint_fastest
  24.                         #include "UnityCG.cginc"
  25.                        
  26.                         uniform sampler2D _MainTex;
  27.                         uniform float _Scale;
  28.                         uniform float _ColorDelta;
  29.                         uniform float _CalculateFromCenter;
  30.                         uniform float _Falloff;
  31.                         uniform float _FalloffBuffer;
  32.                        
  33.                         fixed4 frag ( v2f_img i ) : COLOR
  34.                         {      
  35.                                 half4 c;
  36.                                
  37.                                 float dist = 1;
  38.                                
  39.                                 if( _CalculateFromCenter == 1 )
  40.                                 {
  41.                                         float2 vec = i.uv - ( 0.5 , 0.5 );
  42.                                         dist = length( vec );
  43.                                 }
  44.                                
  45.                                 dist -= _FalloffBuffer;
  46.                                 if( dist < 0 ) dist = 0;
  47.                                
  48.                                 dist *= _Falloff;
  49.                                                
  50.                                 half2 uvR = ( i.uv + 0.0007 * _Scale * dist );
  51.                                 half2 uvB = ( i.uv - 0.0007 * _Scale * dist );
  52.                                
  53.                                 c.r = tex2D( _MainTex , uvR ).r * 1 + _ColorDelta * dist;
  54.                                 c.ga = tex2D( _MainTex , i.uv ).ga;
  55.                                 c.b = tex2D( _MainTex , uvB ).b * 1 - _ColorDelta * dist;
  56.                                
  57.                                 return c;
  58.                         }
  59.                 ENDCG
  60.                 }
  61.         }
  62.         Fallback off
  63. }