【Unity Shader】 Alpha测试
生活随笔
收集整理的這篇文章主要介紹了
【Unity Shader】 Alpha测试
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
介紹
Alpha測試:符合條件的像素顯示出來,不符合的丟掉
一、fixed function shader的透明通度測試
ShaderLab: Legacy Alpha Testing
語法
渲染所有的像素(默認)或者…
2. 開啟Alpha測試
設置alpha測試,根據alpha值篩選符合條件的像素進行渲染
Comparison Alpha測試的比較命令
- Greater
Only render pixels whose alpha is greater than AlphaValue. - GEqual
Only render pixels whose alpha is greater than or equal to AlphaValue. - Less
Only render pixels whose alpha value is less than AlphaValue. - LEqual
Only render pixels whose alpha value is less than or equal to from AlphaValue. - Equal
Only render pixels whose alpha value equals AlphaValue. - NotEqual
Only render pixels whose alpha value differs from AlphaValue. - Always
Render all pixels. This is functionally equivalent to AlphaTest Off. - Never
Don’t render any pixels.
開啟alpha測試,只渲染alpha值大于0.5的像素:
Shader "Hidden/alphatest" {Properties{_MainTex ("Texture", 2D) = "white" {}}SubShader{// No culling or depthCull Off ZWrite Off ZTest Always// alphatest// AlphaTest OffAlphaTest Greater 0.5Pass{SetTexture[_MainTex]}} }二、可編程shader的透明度測試
ShaLab的AlphaTest命令在shader2.0中是不起作用的。
由于可編程shader會對紋理采樣,可以直接操作紋理的透明通道值,因此也不需要AlphaTest命令。而fixed function shader不會紋理采樣,只能依靠AlphaTest命令進行Alpha測試。
同樣,開啟alpha測試,只渲染alpha值大于0.5的像素:
Shader "Hidden/alphatest2" {Properties{_MainTex ("Texture", 2D) = "white" {}}SubShader{// No culling or depth//Cull Off ZWrite Off ZTest AlwaysBlend SrcAlpha OneMinusSrcAlphaPass{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);if(col.a < 0.5 ){return fixed4(0,0,0,0);}else{return col;}return col;}ENDCG}} }總結
以上是生活随笔為你收集整理的【Unity Shader】 Alpha测试的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: grpc生成pb.go文件报错githu
- 下一篇: 软件测试DAY3-执行用例