Advertisement
tonynogo

Demo 13 - Lava with flow map

Jul 6th, 2017
8,028
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Flow Map" {
  2.     Properties {
  3.         _MainTex ("Base (RGB)", 2D) = "white" {}
  4.         _FlowMap ("Flow Map", 2D) = "grey" {}
  5.         _Speed ("Speed", Range(-1, 1)) = 0.2
  6.     }
  7.  
  8.     SubShader {
  9.         Pass {
  10.             Tags { "RenderType"="Opaque" }
  11.        
  12.             CGPROGRAM
  13.             #pragma vertex vert
  14.             #pragma fragment frag
  15.             #include "UnityCG.cginc"
  16.  
  17.             struct v2f {
  18.                 float4 pos : SV_POSITION;
  19.                 fixed2 uv : TEXCOORD0;
  20.             };
  21.  
  22.             sampler2D _MainTex;
  23.             sampler2D _FlowMap;
  24.             fixed _Speed;
  25.  
  26.             fixed4 _MainTex_ST;
  27.  
  28.             v2f vert(appdata_base IN) {
  29.                 v2f o;
  30.                 o.pos = mul(UNITY_MATRIX_MVP, IN.vertex);
  31.                 o.uv = TRANSFORM_TEX(IN.texcoord, _MainTex);
  32.                 return o;
  33.             }
  34.        
  35.             fixed4 frag(v2f v) : COLOR {
  36.                 fixed4 c;
  37.                 half3 flowVal = (tex2D(_FlowMap, v.uv) * 2 - 1) * _Speed;
  38.  
  39.                 float dif1 = frac(_Time.y * 0.25 + 0.5);
  40.                 float dif2 = frac(_Time.y * 0.25);
  41.  
  42.                 half lerpVal = abs((0.5 - dif1)/0.5);
  43.  
  44.                 half4 col1 = tex2D(_MainTex, v.uv - flowVal.xy * dif1);
  45.                 half4 col2 = tex2D(_MainTex, v.uv - flowVal.xy * dif2);
  46.  
  47.                 c = lerp(col1, col2, lerpVal);
  48.                 return c;
  49.             }
  50.  
  51.             ENDCG
  52.         }
  53.     }
  54.     FallBack "Diffuse"
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement