这个操作的核心原理就是:让alpha分量小于某个阈值的像素透明
核心代码是
10.1 一个简单的demo
先来看效果:
源码:
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
Shader "Unlit/t2"
{
Properties
{
_Color("Color",Color) = (1,1,1,1)
_MainTex("Texture", 2D) = "white" {}
}
SubShader
{
Tags {"Queue" = "Transparent" }
LOD 100
Pass
{
ZWrite Off
CGPROGRAM
#pragma vertex vertex
#pragma fragment fragment
// make fog work
// #pragma multi_compile_fog
#include "UnityCG.cginc"
struct fromCpu
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : POSITION;
float4 color: COLOR0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _Color;
v2f vertex(fromCpu v)
{
v2f o;
v.vertex.y = 3*sin(v.vertex.x + _Time.y*20)+ 3 * sin(v.vertex.z+_Time.y*20);
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.color = fixed4(0,0,v.vertex.y, v.vertex.y);
return o;
}
fixed4 fragment(v2f i) : SV_Target
{
fixed4 c = i.color;
clip(c.a - 0.3);
return c;
}
ENDCG
}
}
}