Advertisement
Malzar

Melted Shader v2

Dec 27th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Malzar/MeltedV2" {
  2.     Properties {
  3.         //_Height ("Melted point", Float) = 0
  4.         [Header(Melted)]
  5.         _MinHeight("Minimun height",float) = 0
  6.         _Height("Melted height",Range(0.1,2))=0
  7.         _MeltDistance("Meltd distance", float) = 2
  8.         _ColorMelted("Melted Color", Color) = (1,1,1,1)
  9.         [Header(Standar)]
  10.         _Color ("Color", Color) = (1,1,1,1)
  11.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
  12.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
  13.         _Metallic ("Metallic", Range(0,1)) = 0.0
  14.     }
  15.     SubShader {
  16.         Tags { "RenderType"="Opaque" }
  17.         LOD 200
  18.         ZWrite ON
  19.  
  20.         CGPROGRAM
  21.         // Physically based Standard lighting model, and enable shadows on all light types
  22.         #pragma surface surf Standard fullforwardshadows vertex:vert addshadow
  23.  
  24.         // Use shader model 3.0 target, to get nicer looking lighting
  25.         #pragma target 3.0
  26.  
  27.         sampler2D _MainTex;
  28.         half _Glossiness;
  29.         half _Metallic;
  30.         fixed4 _Color;
  31.         fixed4 _ColorMelted;
  32.         half _Height;
  33.         half _MinHeight;
  34.         half _MeltDistance;
  35.  
  36.         struct Input {
  37.             float2 uv_MainTex;
  38.             half percentaje;
  39.             half vMod;
  40.         };
  41.  
  42.         struct appdata{
  43.             float4 vertex :POSITION;
  44.             float3 normal : NORMAL;
  45.             float4 texcoord : TEXCOORD0;
  46.         };
  47.  
  48.  
  49.         float4 getMeltedPosition(float4 objectLocalPosition, float3 objectLocalNormal){
  50.             float4 worldPosition = mul(unity_ObjectToWorld,objectLocalPosition);
  51.             float4 worldNormal = mul(unity_ObjectToWorld,objectLocalNormal);
  52.  
  53.             float meltedPointPasssed=worldPosition.y<_MinHeight;
  54.             worldPosition.y=worldPosition.y*(1-meltedPointPasssed)+ _MinHeight*meltedPointPasssed;
  55.  
  56.             float meltPercentaje = smoothstep(_MinHeight,_MinHeight+_Height,worldPosition.y);
  57.             meltPercentaje = (1-saturate(meltPercentaje))*_MeltDistance;
  58.             worldPosition.xz += normalize(worldNormal.xz)*meltPercentaje;
  59.  
  60.             return(mul(unity_WorldToObject,worldPosition));
  61.         }
  62.  
  63.         void vert(inout appdata v, out Input o){
  64.             UNITY_INITIALIZE_OUTPUT(Input,o);
  65.  
  66.             v.vertex = getMeltedPosition(v.vertex,v.normal);
  67.  
  68.         }
  69.         UNITY_INSTANCING_BUFFER_START(Props)
  70.             // put more per-instance properties here
  71.         UNITY_INSTANCING_BUFFER_END(Props)
  72.  
  73.         void surf (Input IN, inout SurfaceOutputStandard o) {
  74.             // Albedo comes from a texture tinted by color
  75.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
  76.             o.Albedo = c.rgb * (1-IN.vMod) + (_ColorMelted+c.rgb*IN.percentaje)*IN.vMod;
  77.             // Metallic and smoothness come from slider variables
  78.             o.Metallic = _Metallic;
  79.             o.Smoothness = _Glossiness * (1-IN.vMod) + (1-IN.percentaje)*IN.vMod;
  80.             o.Alpha = c.a;
  81.         }
  82.         ENDCG
  83.     }
  84.     FallBack "Diffuse"
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement