+ 挤压使模型变形
+ 实现雪
+ 实现体积爆炸效果

## 简介

1. 我们需要定义vert函数的返回结构

struct Input
{
float2 uv_MainTex;
float2 vertColor;
}

2. 从输入中获取顶点颜色，并返回

struct appdata_full {
float4 vertex : POSITION;
float4 tangent : TANGENT;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
float4 texcoord1 : TEXCOORD1;
float4 texcoord2 : TEXCOORD2;
float4 texcoord3 : TEXCOORD3;
fixed4 color : COLOR;
UNITY_VERTEX_INPUT_INSTANCE_ID
};

```void vert(inout appdata_full v, out Input o)
{
o.verColor = v.color;
}```
1. 在Surface中使用

```void surf(Input IN, inout SurfaceOutput o)
{
o.Albedo = IN.vertColor.rgb * _MainTint.rgb; //简单的和主颜色叠加
}```

### 更多

```void vert(inout appdata_full v, out Input o)
{
UNITY_INITALIZE_OUTPUT(Input, o);
o.vertColor = v.color;
}```

```Shader "CookbookShaders/self/vertexAni" {
Properties
{
_MainTex("Base (RGB)", 2D) = "white"{}
_tintAmount("Tint Amount", Range(0,1)) = 0.5
_ColorA("ColorA", Color) = (1, 1, 1, 1)
_ColorB("ColorB", Color) = (1, 1, 1, 1)
_Speed("Wave speed", Range(0.1, 80)) = 5
_Frequency("Wave Frequency", Range(0, 5)) = 2
_Amplitude("Wave Amplitude", Range(-1, 1)) = 1
}

{
Tags {"RenderType" = "Opaque"}
LOD 200

CGPROGRAM

#pragma surface surf Lambert vertex:vert

sampler2D _MainTex;
float4 _ColorA;
float4 _ColorB;
float _tintAmount;
float _Speed;
float _Frequency;
float _Amplitude;
float _OffsetVal;

struct Input
{
float2 uv_MainTex;
float3 vertColor;
};

void vert(inout appdata_full v, out Input o)
{
float time = _Time * _Speed;
float waveValueA = sin(time + v.vertex.x * _Frequency) * _Amplitude;
v.vertex.xyz = float3(v.vertex.x, v.vertex.y + waveValueA, v.vertex.z);
o.vertColor = float3(waveValueA, waveValueA, waveValueA);
o.uv_MainTex = v.texcoord;
}

void surf(Input IN, inout SurfaceOutput o)

{
half4 c = tex2D(_MainTex, IN.uv_MainTex);
float3 tintColor = lerp(_ColorA, _ColorB, IN.vertColor).rgb;
o.Albedo = c.rgb * (tintColor * _tintAmount);
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}```

## Extruding（挤压？修改？）你的模型

```void vert(inout appdata_full v)
{
float3 N = normalize(v.normal);
v.vertex.xyz += N * _Amount;
}```

```sampler2D _ExtrusionTex;
void vert(inout appdata_full v) {
float4 tex = tex2Dlod (_ExtrusionTex, float4(v.texcoord.xy,0,0));
float extrusion = tex.r * 2 - 1;
v.vertex.xyz += v.normal * _Amount * extrusion;
}```

## 实现体积爆炸

```Shader "CookbookShaders/self/explosion" {
Properties {
_RampTex("Color Ramp", 2D) = "white"{}
_RampOffset("Ramp offset", Range(-0.5, 0.5)) = 0
_NoiseTex("Noise Tex", 2D) = "gray" {}
_Period("Period", Range(0, 1)) = 0.5
_Amount("_Amount", Range(0, 1.0)) = 0.1
_ClipRange("ClipRange", Range(0, 1)) = 1
}
Tags { "RenderType"="Opaque" }
LOD 200

CGPROGRAM
#pragma surface surf Lambert vertex:vert nolightmap

// Use shader model 3.0 target, to get nicer looking lighting
//#pragma target 3.0

sampler2D _RampTex;
half _RampOffset;
sampler2D _NoiseTex;
float _Period;
half _Amount;
half _ClipRange;

struct Input {
float2 uv_NoiseTex;
};

void vert(inout appdata_full v)
{
float3 disp = tex2Dlod(_NoiseTex, float4(v.texcoord.xy, 0, 0));
float time = sin(_Time[3] * _Period + disp.r * 10);
v.vertex.xyz += normalize(v.normal) * disp.r * _Amount * time;
}

void surf (Input IN, inout SurfaceOutput o)
{
float3 noise = tex2D(_NoiseTex, IN.uv_NoiseTex);
float n = saturate(noise.r + _RampOffset);
clip(_ClipRange - n);
half4 c = tex2D(_RampTex, float2(n, 0.5));
o.Albedo = c.rgb;
o.Emission = c.rgb * c.a;
}
ENDCG
}
FallBack "Diffuse"
}```