Unity Shader Repository by garsonlab - 3

Unity 2017.2.0f3Unknown LicenseUpdated 1 year agoCreated on January 2nd, 2018
Go to source

Use Unity Version > 5 当前使用Unity版本大于5

[TOCM]

## 1. Forge 雾效

### 1.1

``````    fixed4 frag (v2f i) : COLOR
{
float2 center = float2(_CenterX, _CenterY);//自定义旋转中心点
float2 uv = i.uv.xy - center;//当前点对应中心点的相对坐标
// 旋转矩阵的公式: (cos - sin, sin + cos)顺时针
float cosVal = cos(_RotateSpeed*_Time.y);
float sinVal = sin(_RotateSpeed*_Time.y);
uv = mul(uv, float2x2(cosVal, -sinVal, sinVal, cosVal)) + center;

fixed4 color = tex2D(_MainTex, i.uv.xy)*_Color;
return color;
}
``````

### 2.2 Rect Soft Mask 矩形软裁剪

``````    if (_UseClipRect)
{
//根据世界坐标计算，源自NGUI
float2 factor = float2(0.0,0.0);
float2 tempXY = (i.worldPos.xy - _ClipRect.xy)/float2(_SoftClipLeft, _SoftClipBottom)*step(_ClipRect.xy, i.worldPos.xy);
factor = max(factor,tempXY);
float2 tempZW = (_ClipRect.zw-i.worldPos.xy)/float2(_SoftClipRight, _SoftClipTop)*step(i.worldPos.xy,_ClipRect.zw);
factor = min(factor,tempZW);
color.a *= clamp(min(factor.x,factor.y),0.0,1.0);
}
``````

### 2.3 Custom Soft Mask 自定义形状软裁剪，支持反转

Mask need Component “Rect Mask 2D” in parent, Only one DrawCall. Base on .