Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Custom/shd-watercol-post"
- {
- Properties
- {
- _MainTex ("Texture", 2D) = "white" {}
- _DispTex ("Texture", 2D) = "white" {}
- _PaintTex ("Texture", 2D) = "white" {}
- _PaperTex ("Texture", 2D) = "white" {}
- _GrowInk ("Grow ink", Range(0.0, 1.0)) = 1.0
- _RadiusInk ("Radius ink", Float) = 0.2
- }
- SubShader
- {
- // No culling or depth
- Cull Off ZWrite Off ZTest Always
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- struct appdata
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- };
- struct v2f
- {
- float2 uv : TEXCOORD0;
- float4 vertex : SV_POSITION;
- };
- v2f vert (appdata v)
- {
- v2f o;
- o.vertex = UnityObjectToClipPos(v.vertex);
- o.uv = v.uv;
- return o;
- }
- sampler2D _MainTex;
- sampler2D _DispTex;
- sampler2D _PaintTex;
- sampler2D _PaperTex;
- float _GrowInk;
- float _RadiusInk;
- fixed intensity(fixed3 a)
- {
- return a.r * 0.3 + a.g * 0.59 + a.b * 0.11;
- }
- fixed3 blended(fixed3 a, fixed3 b, fixed disp)
- {
- fixed ai = intensity(a);
- fixed bi = intensity(b);
- fixed alpha = (ai > bi) ? (0.35 + 0.5 * disp) : 1.075;
- fixed3 c = alpha * a + (1.0 - alpha) * b;
- return c;
- }
- fixed3 rgbmin(fixed3 c)
- {
- return max(c, 0.275);
- }
- fixed4 brush(fixed2 uv)
- {
- // må bruka noko slags verdsposisjon istf uv/skjerm for ser rart ut i rørelse!
- // akkurat no kan ting ikkje bli heilt svarte om det er lite ljos, fiks!
- fixed ratio = _ScreenParams.y / _ScreenParams.x;
- fixed factor = (_ScreenParams.x / 1920.0);
- fixed2 uv2 = fixed2(uv.x, uv.y * ratio) * 3.0;
- fixed2 uv3 = fixed2(uv.x, uv.y * ratio) * 3.0;
- fixed disp = tex2D(_DispTex, uv2 * 0.5).r;
- fixed paint = tex2D(_PaintTex, uv2 * 1.75).r;
- fixed paper = tex2D(_PaperTex, uv3 * 4.0 * factor).r;
- //float depth = clamp(tex2D(_CameraDepthTexture, uv).r - 0.15, 0.0, 0.5) * 2.2;
- //float offs = _Offset + pow(min(depth, 2.0), 21.0);
- fixed4 col = tex2D(_MainTex, uv);
- float offs = 12.0 - disp * paint * paper;
- fixed2 o = fixed2(offs / _ScreenParams.x, offs / _ScreenParams.y);
- o *= disp * 0.5;
- fixed2 curve2 = fixed2(0.35, 0.5) + paint * 0.4;
- fixed fy = -0.5;
- fixed3 a = tex2D(_MainTex, uv + fixed2(0.0, o.y * curve2.y)).rgb;
- fixed3 b = tex2D(_MainTex, uv + fixed2(o.x * curve2.x, o.y * curve2.y * fy)).rgb;
- fixed3 c = tex2D(_MainTex, uv + fixed2(o.x * curve2.x, -o.y * curve2.y * fy)).rgb;
- fixed3 d = tex2D(_MainTex, uv + fixed2(0.0, -o.y * curve2.y)).rgb;
- fixed3 e = tex2D(_MainTex, uv + fixed2(-o.x * curve2.x, -o.y * curve2.y * fy)).rgb;
- fixed3 f = tex2D(_MainTex, uv + fixed2(-o.x * curve2.x, o.y * curve2.y * fy)).rgb;
- fixed3 corr = col.rgb * fixed3(1.2, 0.85, 1.0);
- //disp = paint * 2.5;
- disp *= 1.6;
- col.rgb = blended(col.rgb, a, disp * 1.5);
- col.rgb = blended(col.rgb, b, disp * 0.25);
- col.rgb = blended(col.rgb, c, disp * 0.5);
- col.rgb = blended(col.rgb, d, disp);
- col.rgb = blended(col.rgb, e, disp * 0.5);
- col.rgb = blended(col.rgb, f, disp);
- col.rgb = rgbmin(col.rgb);
- a.rgb = rgbmin(a.rgb);
- b.rgb = rgbmin(b.rgb);
- c.rgb = rgbmin(c.rgb);
- d.rgb = rgbmin(d.rgb);
- e.rgb = rgbmin(e.rgb);
- f.rgb = rgbmin(f.rgb);
- col *= paper * 1.15;
- return col;
- }
- fixed4 frag (v2f i) : SV_Target
- {
- //fixed4 col = tex2D(_MainTex, i.uv);
- fixed4 col = brush(i.uv);
- return col;
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement