Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Unlit/SimpleLava"
- {
- Properties
- {
- _Color("Tint", Color) = (1, 1, 1, .5)
- _Color2("Tint2", Color) = (1, 1, 1, .5)
- _Color3("TopTint", Color) = (1, 1, 1, .5)
- _FoamC("Foam", Color) = (1, 1, 1, .5)
- _MainTex("Main Texture", 2D) = "white" {}
- _DistortTex("Dist Texture", 2D) = "white" {}
- _Speed("Wave Speed", Range(0,1)) = 0.5
- _Amount("Wave Amount", Range(0,1)) = 0.6
- _Scale("Scale", Range(0,1)) = 0.5
- _Scale2("Scale2", Range(0,1)) = 0.5
- _Height("Wave Height", Range(0,1)) = 0.1
- _Foam("Foamline Thickness", Range(0,10)) = 8
- _Speed2("speed", Range(0,10)) = 8
- _SpeedMain("speed main", Range(0,10)) = 8
- _Offset("Offset", Range(0,10)) = 0.0
- _Strength("Strength Under Lava", Range(0,10)) = 0.0
- _StrengthTop("Strength Top Lava", Range(0,10)) = 0.0
- _Distortion("Distort", Range(0,1)) = 0.0
- _Cutoff("Cutoff top", Range(0,1)) = 0.9
- }
- SubShader
- {
- Tags{ "RenderType" = "Opaque" "Queue" = "Transparent" }
- LOD 100
- //Blend OneMinusDstColor One
- Cull Off
- GrabPass{
- Name "BASE"
- Tags{ "LightMode" = "Always" }
- }
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- // make fog work
- #pragma multi_compile_fog
- #pragma shader_feature DISTORT
- #pragma shader_feature DARK
- #include "UnityCG.cginc"
- struct appdata
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- float4 color: COLOR;
- };
- struct v2f
- {
- float2 uv : TEXCOORD3;
- UNITY_FOG_COORDS(1)
- float4 vertex : SV_POSITION;
- float4 scrPos : TEXCOORD2;//
- float4 worldPos : TEXCOORD4;//
- float4 color :COLOR;
- };
- float4 _Color, _Color2, _Color3, _DarkCol;
- sampler2D _CameraDepthTexture; //Depth Texture
- sampler2D _MainTex, _DarkTex, _DistortTex;//
- float4 _MainTex_ST;
- float _Speed, _Amount, _Height, _Foam, _Scale, _Scale2;//
- float4 _FoamC;
- float _Speed2, _Offset, _Strength, _Distortion, _SpeedMain, _Cutoff, _StrengthTop;
- float _CutoffDark;
- v2f vert(appdata v)
- {
- v2f o;
- UNITY_INITIALIZE_OUTPUT(v2f, o);
- v.vertex.y += sin(_Time.z * _Speed + (v.vertex.x * v.vertex.z * _Amount)) * _Height * v.color.r;//movement
- o.vertex = UnityObjectToClipPos(v.vertex);
- o.worldPos = mul(unity_ObjectToWorld, v.vertex);
- // vertex colors
- o.color = v.color;
- o.scrPos = ComputeScreenPos(o.vertex);
- UNITY_TRANSFER_FOG(o,o.vertex);
- return o;
- }
- fixed4 frag(v2f i) : SV_Target
- {
- // sample the texture
- // uv distortion scale
- float2 uvDistort = (i.worldPos.xz * _Scale2);
- // moving over time
- uvDistort += (_Time.x * _Speed2) + (i.color.r * 0.5);
- // distortion texture
- fixed4 d = tex2D(_DistortTex, uvDistort) * i.color.r;
- // main distorted uv
- float2 uvMain = (i.worldPos.xz * _Scale );
- // plus distortion
- uvMain += (d * i.color.r * _Distortion);
- // plus moving
- uvMain += (_Time.x * _SpeedMain + ((i.color.r * 0.4)));
- half4 col = tex2D(_MainTex, uvMain);// *i.color.r;// texture times tint;
- col += d;
- col *= (i.color.r + 0.2);
- float cola = smoothstep(_Cutoff, _Cutoff + 0.1, col);
- // foamline
- half depth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos))); // depth
- half4 foamLine = 1 - saturate(_Foam* (depth - i.scrPos.w));
- // cutoff foamline with distortion texture
- float f = smoothstep(3 * d, (3 * d) + 0.1 , foamLine);
- float4 color = (lerp(_Color, _Color2, saturate((col * _Offset)))) * _Strength;
- // multply with no - Foam
- color *= (1 - cola);
- color *= (1 - f);
- // foam tinted
- color += (f *_FoamC);
- // toptint
- color += cola * _Color3 *_StrengthTop;
- return color;
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement