用Unity实现建筑切片生长动画

效果展示:

切片生长动画

当前效果需要自己手动写一个shader,效果与unity版本无关,模型没有特别要求

步骤一:
在unity创建一个SurfaceShader类型的shader,命名为ClippingShader,双击进入vs进行编辑,shader内容如下:

Shader "Custom/ClippingShader"
{
    
    
	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


	   [HDR] _CutoffColor("Cutoff Color",Color) = (1,0,0,0)
	}
		SubShader
		{
    
    
			Tags {
    
     "RenderType" = "Opaque" }


			LOD 200

			Cull off

			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;


		   float4 _Plane;
		   float4 _CutoffColor;

			struct Input
			{
    
    
				float2 uv_MainTex;
				float3 worldPos;
				float facing : VFACE;
			};

			half _Glossiness;
			half _Metallic;
			fixed4 _Color;

			void surf(Input IN, inout SurfaceOutputStandard o)
			{
    
    
				float distance = dot(IN.worldPos, _Plane.xyz);
				distance = distance + _Plane.w;

				clip(-distance);

				float facing = IN.facing*0.5 + 0.5;

				// Albedo comes from a texture tinted by color
				fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
				o.Albedo = c.rgb;
				// Metallic and smoothness come from slider variables
				o.Metallic = _Metallic;
				o.Smoothness = _Glossiness;
				o.Alpha = c.a;
			}
			ENDCG
		}
			FallBack "Diffuse"
}

步骤二:

上述shader和脚本写好之后,把需要生长改变的材质赋值成我们自定义的shader,然后新建一个空物体,在空物体上添加我们写好的脚本,赋值好材质,根据空物体的高度决定shader材质是否显示

运行测试,完成!!

工程源文件
点这里

有疑问欢迎vx咨询159-7084-3394

猜你喜欢

转载自blog.csdn.net/weixin_44733991/article/details/121206292