Advertisement
tonynogo

Demo 78 - Chromatic aberration

Jul 6th, 2017
8,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Chromatic aberration"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Texture", 2D) = "white" {}
  6.  
  7.         [Header(Red)]
  8.         _RedX ("Offset X", Range(-0.5, 0.5)) = 0.0
  9.         _RedY ("Offset Y", Range(-0.5, 0.5)) = 0.0
  10.  
  11.         [Header(Green)]
  12.         _GreenX ("Offset X", Range(-0.5, 0.5)) = 0.0
  13.         _GreenY ("Offset Y", Range(-0.5, 0.5)) = 0.0
  14.  
  15.         [Header(Blue)]
  16.         _BlueX ("Offset X", Range(-0.5, 0.5)) = 0.0
  17.         _BlueY ("Offset Y", Range(-0.5, 0.5)) = 0.0
  18.     }
  19.     SubShader
  20.     {
  21.         Tags { "RenderType"="Opaque" }
  22.  
  23.         Pass
  24.         {
  25.             CGPROGRAM
  26.             #pragma vertex vert_img
  27.             #pragma fragment frag
  28.            
  29.             #include "UnityCG.cginc"
  30.  
  31.             sampler2D _MainTex;
  32.             float _RedX;
  33.             float _RedY;
  34.             float _GreenX;
  35.             float _GreenY;
  36.             float _BlueX;
  37.             float _BlueY;
  38.            
  39.             fixed4 frag (v2f_img i) : SV_Target
  40.             {
  41.                 fixed4 col = fixed4(1, 1, 1, 1);
  42.  
  43.                 float2 red_uv = i.uv + float2(_RedX, _RedY);
  44.                 float2 green_uv = i.uv + float2(_GreenX, _GreenY);
  45.                 float2 blue_uv = i.uv + float2(_BlueX, _BlueY);
  46.  
  47.                 col.r = tex2D(_MainTex, red_uv).r;
  48.                 col.g = tex2D(_MainTex, green_uv).g;
  49.                 col.b = tex2D(_MainTex, blue_uv).b;
  50.  
  51.                 return col;
  52.             }
  53.             ENDCG
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement