如图:
改变MeltValue的值即可控制物体消融的程度。
_BurnLength可改变消融边缘的颜色覆盖范围。
代码:
Shader "Custom/10"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_NormalMap("NormalMap",2D)="bump"{}
_NormalScale("NormalScale",float)=1
_MeltTex("MeltTex",2D)="white"{}
_MeltValue("MeltValue",Range(0,1))=0
_BurnTex("BurnTex",2D)="white"{}//边缘颜色贴图
_BurnLength("BurnLength",Range(0,50))=20
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _NormalMap;
sampler2D _MeltTex;
sampler2D _BurnTex;
half _NormalScale;
half _MeltValue;
half _BurnLength;
struct Input
{
float2 uv_MainTex;
float2 uv_NormalMap;
float2 uv_MeltTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Normal = UnpackScaleNormal(tex2D(_NormalMap, IN.uv_NormalMap), _NormalScale);
o.Albedo = c.rgb;
float cutout = tex2D(_MeltTex, IN.uv_MeltTex).r;
clip(cutout - _MeltValue);
float temp = saturate((cutout - _MeltValue)*_BurnLength);
fixed4 burnColor = tex2D(_BurnTex, float2(temp, temp));
fixed4 finalColor = lerp(burnColor, fixed4(0, 0, 0, 0), temp);
o.Emission = finalColor.rgb;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
消融边缘的颜色贴图可用这张,其他贴图就不提供了。