Advertisement
Draco18s

Dvornik/Distort

Jun 29th, 2016
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Dvornik/Distort" {
  2.     Properties{
  3.         _Refraction("Refraction", Range(-10.00, 10.0)) = 0
  4.         _MainTex("Sprite Texture", 2D) = "white" {}
  5.         _DistortTex("Distort",2D) = "white" {}
  6.     }
  7.  
  8.     SubShader{
  9.  
  10.         Tags{ "RenderType" = "Transparent" "Queue" = "Overlay" }
  11.         LOD 100
  12.  
  13.         GrabPass{
  14.  
  15.         }
  16.  
  17.         CGPROGRAM
  18.             #pragma surface surf NoLighting
  19.             #pragma vertex vert
  20.  
  21.             fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten) {
  22.                 fixed4 c;
  23.                 c.rgb = s.Albedo;
  24.                 c.a = s.Alpha;
  25.                 return c;
  26.             }
  27.  
  28.             sampler2D _GrabTexture;
  29.             sampler2D _MainTex;
  30.             sampler2D _DistortTex;
  31.             float _Refraction;
  32.  
  33.             float4 _DistortTex_TexelSize;
  34.  
  35.             struct Input {
  36.                 float2 uv_MainTex;
  37.                 float2 uv_DistortTex;
  38.                 float3 color;
  39.                 float4 grabScreenPos;
  40.                 INTERNAL_DATA
  41.             };
  42.  
  43.             void vert(inout appdata_full v, out Input o) {
  44.                 UNITY_INITIALIZE_OUTPUT(Input,o);
  45.                 o.color = v.color;
  46.                 float4 clipPos = mul(UNITY_MATRIX_MVP, v.vertex);
  47.                 o.grabScreenPos = ComputeGrabScreenPos(clipPos);
  48.             }
  49.  
  50.             void surf(Input IN, inout SurfaceOutput o) {
  51.                 float4 main = tex2D(_MainTex, IN.uv_MainTex);
  52.                 float4 dist = tex2D(_DistortTex, IN.uv_DistortTex);
  53.                 float3 distort = float3(dist.r - 0.5, dist.g - 0.5, dist.b - 0.5);
  54.                 float2 offset = distort * _Refraction * _DistortTex_TexelSize.xy;
  55.                 //float4 bgColor = tex2Dproj(_GrabTexture, IN.screenPos);
  56.                 IN.grabScreenPos.xy = offset + IN.grabScreenPos.xy;
  57.                 float4 refrColor = tex2Dproj(_GrabTexture, IN.grabScreenPos);
  58.                 float alph = (main.a-0.5)*2;
  59.                 //if (alph <= 0) {
  60.                     //o.Emission = refrColor.rgb;
  61.                     o.Emission = main.rgb * main.a * main.a + (1 - main.a) * refrColor.rgb;
  62.                 /*}
  63.                 else {
  64.                     o.Emission = main.rgb * alph + (1-alph) * refrColor.rgb;
  65.                 }*/
  66.                 o.Alpha = alph;
  67.             }
  68.         ENDCG
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement