SHARE
TWEET

Untitled

a guest Jan 15th, 2020 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Unlit/SimpleLava"
  2. {
  3.     Properties
  4.     {
  5.         _Color("Tint", Color) = (1, 1, 1, .5)
  6.         _Color2("Tint2", Color) = (1, 1, 1, .5)
  7.         _Color3("TopTint", Color) = (1, 1, 1, .5)
  8.        
  9.         _FoamC("Foam", Color) = (1, 1, 1, .5)
  10.         _MainTex("Main Texture", 2D) = "white" {}
  11.     _DistortTex("Dist Texture", 2D) = "white" {}
  12.  
  13.     _Speed("Wave Speed", Range(0,1)) = 0.5
  14.         _Amount("Wave Amount", Range(0,1)) = 0.6
  15.         _Scale("Scale", Range(0,1)) = 0.5
  16.         _Scale2("Scale2", Range(0,1)) = 0.5
  17.         _Height("Wave Height", Range(0,1)) = 0.1
  18.         _Foam("Foamline Thickness", Range(0,10)) = 8
  19.         _Speed2("speed", Range(0,10)) = 8
  20.         _SpeedMain("speed main", Range(0,10)) = 8
  21.         _Offset("Offset", Range(0,10)) = 0.0
  22.         _Strength("Strength Under Lava", Range(0,10)) = 0.0
  23.         _StrengthTop("Strength Top Lava", Range(0,10)) = 0.0
  24.         _Distortion("Distort", Range(0,1)) = 0.0
  25.         _Cutoff("Cutoff top", Range(0,1)) = 0.9
  26.    
  27.     }
  28.         SubShader
  29.     {
  30.         Tags{ "RenderType" = "Opaque"  "Queue" = "Transparent" }
  31.         LOD 100
  32.         //Blend OneMinusDstColor One
  33.         Cull Off
  34.  
  35.         GrabPass{
  36.         Name "BASE"
  37.         Tags{ "LightMode" = "Always" }
  38.     }
  39.         Pass
  40.     {
  41.         CGPROGRAM
  42. #pragma vertex vert
  43. #pragma fragment frag
  44.         // make fog work
  45. #pragma multi_compile_fog
  46.  
  47.             #pragma shader_feature DISTORT
  48.  
  49.             #pragma shader_feature DARK
  50. #include "UnityCG.cginc"
  51.  
  52.         struct appdata
  53.     {
  54.         float4 vertex : POSITION;
  55.         float2 uv : TEXCOORD0;
  56.         float4 color: COLOR;
  57.     };
  58.  
  59.     struct v2f
  60.     {
  61.         float2 uv : TEXCOORD3;
  62.         UNITY_FOG_COORDS(1)
  63.             float4 vertex : SV_POSITION;
  64.         float4 scrPos : TEXCOORD2;//
  65.         float4 worldPos : TEXCOORD4;//
  66.         float4 color :COLOR;
  67.     };
  68.     float4 _Color, _Color2, _Color3, _DarkCol;
  69.     sampler2D _CameraDepthTexture; //Depth Texture
  70.     sampler2D _MainTex, _DarkTex, _DistortTex;//
  71.     float4 _MainTex_ST;
  72.     float _Speed, _Amount, _Height, _Foam, _Scale, _Scale2;//
  73.     float4 _FoamC;
  74.     float _Speed2, _Offset, _Strength, _Distortion, _SpeedMain, _Cutoff, _StrengthTop;
  75.     float _CutoffDark;
  76.  
  77.     v2f vert(appdata v)
  78.     {
  79.         v2f o;
  80.         UNITY_INITIALIZE_OUTPUT(v2f, o);
  81.  
  82.         v.vertex.y += sin(_Time.z * _Speed + (v.vertex.x * v.vertex.z * _Amount)) * _Height * v.color.r;//movement
  83.         o.vertex = UnityObjectToClipPos(v.vertex);
  84.         o.worldPos = mul(unity_ObjectToWorld, v.vertex);
  85.  
  86.         // vertex colors
  87.         o.color = v.color;
  88.  
  89.         o.scrPos = ComputeScreenPos(o.vertex);
  90.         UNITY_TRANSFER_FOG(o,o.vertex);
  91.         return o;
  92.     }
  93.  
  94.     fixed4 frag(v2f i) : SV_Target
  95.     {
  96.         // sample the texture
  97.         // uv distortion scale
  98.         float2 uvDistort = (i.worldPos.xz * _Scale2);
  99.         // moving over time
  100.         uvDistort += (_Time.x * _Speed2) + (i.color.r * 0.5);
  101.         // distortion texture
  102.         fixed4 d = tex2D(_DistortTex, uvDistort) * i.color.r;
  103.  
  104.         // main distorted uv
  105.         float2 uvMain = (i.worldPos.xz * _Scale );
  106.         // plus distortion
  107.         uvMain += (d * i.color.r * _Distortion);
  108.         // plus moving
  109.  
  110.         uvMain += (_Time.x * _SpeedMain + ((i.color.r * 0.4)));
  111.  
  112.     half4 col = tex2D(_MainTex, uvMain);// *i.color.r;// texture times tint;    
  113.  
  114.     col += d;
  115.     col *= (i.color.r + 0.2);
  116.     float cola = smoothstep(_Cutoff, _Cutoff + 0.1, col);
  117.    
  118.     // foamline
  119.     half depth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos))); // depth
  120.     half4 foamLine = 1 - saturate(_Foam* (depth - i.scrPos.w));
  121.  
  122.     // cutoff foamline with distortion texture
  123.     float f = smoothstep(3 * d, (3 * d) + 0.1 , foamLine);
  124.  
  125.     float4 color = (lerp(_Color, _Color2, saturate((col * _Offset)))) * _Strength;
  126.     // multply with no  - Foam
  127.  
  128.  
  129.     color *= (1 - cola);
  130.     color *= (1 - f);
  131.     // foam tinted
  132.     color += (f *_FoamC);
  133.  
  134.     // toptint
  135.     color += cola * _Color3 *_StrengthTop;
  136.  
  137.  
  138.     return   color;
  139.     }
  140.         ENDCG
  141.     }
  142.     }
  143. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top