Unity图形学之Shader2.0 Alpha测试
1.渲染管线:
顶点着色器 -> 光栅化 -> 片段着色器 ->Alpha 测试 ->模版测试
->深度测试 ->Blend -> Gbuffer -> frontBuffer -> frameBuffer -> 显示器
2.Alpha 测试:符合条件的 Alpha 像素显示出来,不符合的丢弃掉
3.Shader1.0版本:
Shader "Hidden/AlphaTestShader1.0"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_AlphaCut ("AlphaCut",float) = 0.5
}
SubShader
{
//透明度大于0.5的才显示
AlphaTest Greater 0.5
//全部都显示 表示关闭测试
AlphaTest Always 0.5
//总是不通过测试 不会渲染出来物体
AlphaTest Never 0.5
//变换参数
AlphaTest Greater [_AlphaCut]
Pass {
SetTexture[_MainTex]
{
combine texture
}
}
}
}
4.Shader2.0版本:AlphaTest关键字在Shader2.0中不生效
Shader "Hidden/AlphaTestShader2.0"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
// No culling or depth
//Cull Off ZWrite Off ZTest Always
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
// just invert the colors
//col.rgb = 1 - col.rgb;
if(col.a < 0.5){
return fixed4(0,0,0,0);
}else{
return col;
}
return col;
}
ENDCG
}
}
}
原文地址:https://blog.csdn.net/woshiyuyanjia/article/details/143735328
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!