Advertisement
Guest User

Untitled

a guest
Jan 28th, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.57 KB | None | 0 0
  1. Shader "Custom/shd-watercol-post"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Texture", 2D) = "white" {}
  6.         _DispTex ("Texture", 2D) = "white" {}
  7.         _PaintTex ("Texture", 2D) = "white" {}
  8.         _PaperTex ("Texture", 2D) = "white" {}
  9.         _GrowInk ("Grow ink", Range(0.0, 1.0)) = 1.0
  10.         _RadiusInk ("Radius ink", Float) = 0.2
  11.     }
  12.     SubShader
  13.     {
  14.         // No culling or depth
  15.         Cull Off ZWrite Off ZTest Always
  16.  
  17.         Pass
  18.         {
  19.             CGPROGRAM
  20.             #pragma vertex vert
  21.             #pragma fragment frag
  22.            
  23.             #include "UnityCG.cginc"
  24.  
  25.             struct appdata
  26.             {
  27.                 float4 vertex : POSITION;
  28.                 float2 uv : TEXCOORD0;
  29.             };
  30.  
  31.             struct v2f
  32.             {
  33.                 float2 uv : TEXCOORD0;
  34.                 float4 vertex : SV_POSITION;
  35.             };
  36.  
  37.             v2f vert (appdata v)
  38.             {
  39.                 v2f o;
  40.                 o.vertex = UnityObjectToClipPos(v.vertex);
  41.                 o.uv = v.uv;
  42.                 return o;
  43.             }
  44.            
  45.             sampler2D _MainTex;
  46.             sampler2D _DispTex;
  47.             sampler2D _PaintTex;
  48.             sampler2D _PaperTex;
  49.             float _GrowInk;
  50.             float _RadiusInk;
  51.  
  52.             fixed intensity(fixed3 a)
  53.             {
  54.                 return a.r * 0.3 + a.g * 0.59 + a.b * 0.11;
  55.             }
  56.  
  57.             fixed3 blended(fixed3 a, fixed3 b, fixed disp)
  58.             {
  59.                 fixed ai = intensity(a);
  60.                 fixed bi = intensity(b);
  61.  
  62.                 fixed alpha = (ai > bi) ? (0.35 + 0.5 * disp) : 1.075;
  63.                 fixed3 c = alpha * a + (1.0 - alpha) * b;
  64.  
  65.                 return c;
  66.             }
  67.  
  68.             fixed3 rgbmin(fixed3 c)
  69.             {
  70.                 return max(c, 0.275);
  71.             }
  72.  
  73.             fixed4 brush(fixed2 uv)
  74.             {
  75.                 // må bruka noko slags verdsposisjon istf uv/skjerm for ser rart ut i rørelse!
  76.  
  77.                 // akkurat no kan ting ikkje bli heilt svarte om det er lite ljos, fiks!
  78.  
  79.                 fixed ratio = _ScreenParams.y / _ScreenParams.x;
  80.                 fixed factor = (_ScreenParams.x / 1920.0);
  81.                 fixed2 uv2 = fixed2(uv.x, uv.y * ratio) * 3.0;
  82.                 fixed2 uv3 = fixed2(uv.x, uv.y * ratio) * 3.0;
  83.  
  84.                 fixed disp = tex2D(_DispTex, uv2 * 0.5).r;
  85.                 fixed paint = tex2D(_PaintTex, uv2 * 1.75).r;
  86.                 fixed paper = tex2D(_PaperTex, uv3 * 4.0 * factor).r;
  87.  
  88.                 //float depth = clamp(tex2D(_CameraDepthTexture, uv).r - 0.15, 0.0, 0.5) * 2.2;
  89.                 //float offs = _Offset + pow(min(depth, 2.0), 21.0);
  90.  
  91.                 fixed4 col = tex2D(_MainTex, uv);
  92.                 float offs = 12.0 - disp * paint * paper;
  93.                 fixed2 o = fixed2(offs / _ScreenParams.x, offs / _ScreenParams.y);
  94.  
  95.                 o *= disp * 0.5;
  96.  
  97.                 fixed2 curve2 = fixed2(0.35, 0.5) + paint * 0.4;
  98.                 fixed fy = -0.5;
  99.  
  100.                 fixed3 a = tex2D(_MainTex, uv + fixed2(0.0, o.y * curve2.y)).rgb;
  101.                 fixed3 b = tex2D(_MainTex, uv + fixed2(o.x * curve2.x, o.y * curve2.y * fy)).rgb;
  102.                 fixed3 c = tex2D(_MainTex, uv + fixed2(o.x * curve2.x, -o.y * curve2.y * fy)).rgb;
  103.                 fixed3 d = tex2D(_MainTex, uv + fixed2(0.0, -o.y * curve2.y)).rgb;
  104.                 fixed3 e = tex2D(_MainTex, uv + fixed2(-o.x * curve2.x, -o.y * curve2.y * fy)).rgb;
  105.                 fixed3 f = tex2D(_MainTex, uv + fixed2(-o.x * curve2.x, o.y * curve2.y * fy)).rgb;
  106.  
  107.                 fixed3 corr = col.rgb * fixed3(1.2, 0.85, 1.0);
  108.  
  109.                 //disp = paint * 2.5;
  110.                 disp *= 1.6;
  111.  
  112.                 col.rgb = blended(col.rgb, a, disp * 1.5);
  113.                 col.rgb = blended(col.rgb, b, disp * 0.25);
  114.                 col.rgb = blended(col.rgb, c, disp * 0.5);
  115.                 col.rgb = blended(col.rgb, d, disp);
  116.                 col.rgb = blended(col.rgb, e, disp * 0.5);
  117.                 col.rgb = blended(col.rgb, f, disp);
  118.  
  119.                 col.rgb = rgbmin(col.rgb);
  120.                 a.rgb = rgbmin(a.rgb);
  121.                 b.rgb = rgbmin(b.rgb);
  122.                 c.rgb = rgbmin(c.rgb);
  123.                 d.rgb = rgbmin(d.rgb);
  124.                 e.rgb = rgbmin(e.rgb);
  125.                 f.rgb = rgbmin(f.rgb);
  126.  
  127.                 col *= paper * 1.15;
  128.  
  129.                 return col;
  130.             }
  131.  
  132.             fixed4 frag (v2f i) : SV_Target
  133.             {
  134.                 //fixed4 col = tex2D(_MainTex, i.uv);
  135.                 fixed4 col = brush(i.uv);
  136.                 return col;
  137.             }
  138.             ENDCG
  139.         }
  140.     }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement