【Unity Shader】 Alpha测试
生活随笔
收集整理的這篇文章主要介紹了
【Unity Shader】 Alpha测试
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
介紹
Alpha測(cè)試:符合條件的像素顯示出來(lái),不符合的丟掉
一、fixed function shader的透明通度測(cè)試
ShaderLab: Legacy Alpha Testing
語(yǔ)法
渲染所有的像素(默認(rèn))或者…
2. 開(kāi)啟Alpha測(cè)試
設(shè)置alpha測(cè)試,根據(jù)alpha值篩選符合條件的像素進(jìn)行渲染
Comparison Alpha測(cè)試的比較命令
- 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.
開(kāi)啟alpha測(cè)試,只渲染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的透明度測(cè)試
ShaLab的AlphaTest命令在shader2.0中是不起作用的。
由于可編程shader會(huì)對(duì)紋理采樣,可以直接操作紋理的透明通道值,因此也不需要AlphaTest命令。而fixed function shader不會(huì)紋理采樣,只能依靠AlphaTest命令進(jìn)行Alpha測(cè)試。
同樣,開(kāi)啟alpha測(cè)試,只渲染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}} }總結(jié)
以上是生活随笔為你收集整理的【Unity Shader】 Alpha测试的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: grpc生成pb.go文件报错githu
- 下一篇: 软件测试DAY3-执行用例