赞
踩
_Time是float4类型,
_Time.x表示当前时间 / 20,
_Time.y表示当前时间,
_Time.z表示当前时间 * 2,
_Time.w表示当前时间 * 3;
在二维坐标系做运算,被旋转的点P(x,y),与x轴夹角为A。求绕原点旋转B度后的P1(x1,y1)。
P和P1与原点距离恒定,都是斜边的长度r。
x = r * cos(A); y = r * sin(A);
P1与x轴夹角为A-B。
x1 = r * cos(A - B); y1 = r * sin(A - B);
由三角函数公式可知: cos(A - B) = cos(A) * cos(B) + sin(A) * sin(B), sin(A - B) = sin(A) * cos(B) - cos(A) * sin(B),
则: x1 = r * cos(A) * cos(B) + r * sin(A) * sin(B) = x * cos(B) + y * sin(B);
y1 = r * sin(A) * cos(B) - r * cos(A) * sin(B) = y * cos(B) - x * sin(B);
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
if (col.a < 0.5)
{
return fixed4(0, 0, 0, 0);
}
return col;
}
https://docs.unity3d.com/cn/current/Manual/SL-Stencil.html
Ref 要比较的参考值
Comp 用于比较参考值与当前缓冲区内容的函数。(大于、等于、小于……)
Comp比较函数
Greater | 仅渲染参考值大于缓冲区值的像素。 |
GEqual | 仅渲染参考值大于或等于缓冲区值的像素。 |
Less | 仅渲染参考值小于缓冲区值的像素。 |
LEqual | 仅渲染参考值小于或等于缓冲区值的像素。 |
Equal | 仅渲染参考值等于缓冲区值的像素。 |
NotEqual | 仅渲染参考值不同于缓冲区值的像素。 |
Always | 使模板测试始终通过。 |
Never | 使模板测试始终失败。 |
Pass 通过测试后,如何处理缓冲区内容
Shader "Red" {
SubShader {
Tags { "RenderType"="Opaque" "Queue"="Geometry"}
Pass {
//模板测试代码开始
Stencil {
Ref 2
Comp always
Pass replace
}
//模板测试代码结束
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
struct appdata {
float4 vertex : POSITION;
};
struct v2f {
float4 pos : SV_POSITION;
};
v2f vert(appdata v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
return o;
}
half4 frag(v2f i) : SV_Target {
return half4(1,0,0,1);
}
ENDCG
}
}
}
https://docs.unity3d.com/cn/current/Manual/SL-CullAndDepth.html
Cull Back | Front | Off
控制剔除多边形的哪些面:Back剔除背面,Front剔除正面,Off禁用剔除(创建双面材质)
ZWrite On | Off
是否写入像素到深度缓冲区,写入才可进行深度测试判断。
ZTest Less | Greater | LEqual | GEqual | Equal | NotEqual | Always
如何进行深度测试,默认为LEqual(当前深度值小于等于深度缓冲区值时,通过测试)。
使颜色置灰。
color.rgb = dot(color.rgb, float3(0.299, 0.587,0.114));
根据偏移量Offset,取得当前像素点的Color,及其上下左右像素点的Color。
将五个Color相加,取平均值。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。