Alpha Testing

  The alpha test is a last chance to reject a pixel from being written to the screen.

  

  After the final output color has been calculated, the color can optionally have its alpha value compared to a fixed value. If the test fails, the pixel is not written to the display.

  在最终颜色(pixel-color)被计算后,可以通过Alpha Test来排除顶点。

[Syntax]  

AlphaTest Off
Render all pixels (default).
AlphaTest comparison AlphaValue
Set up the alpha test to only render pixels whose alpha value is within a certain range.

Comparison

  

AlphaValue

  A floating-point number between 0 and 1. This can also be a variable reference to a float or range property, in which case it should be written using the standard square bracket notation ([VariableName]).

[Alpha测试的用途]

  对于半透明的凹形图形,用Alpha测试与Blending配合使用才能产生较好的效果。

  

  左图:ZWrite On,AlphaTest Equal 1.0。由于Alpha均为1,所以无Blending。在此条件下产生出一个锐利的图像。

  中图:ZWrite On,AlphaTest Off。在此条件下,Alpha为0的部分会遮挡住Alpha非零的部分,产生奇怪的图。

  右图:1)ZWrite On,AlphaTest Equal 1.0。此遍渲染非透明物体。

       2)ZWrite Offet,AlphaTest Less 1.0。此遍渲染透明物体。

     右图能够产生较为完美的图像。

  右图的Shader如下:

Shader "Vegetation" {
Properties {
_Color ("Main Color", Color) = (., ., ., .)
_MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
_Cutoff ("Base Alpha cutoff", Range (,.)) = .
}
SubShader {
// Set up basic lighting
Material {
Diffuse [_Color]
Ambient [_Color]
}
Lighting On // Render both front and back facing polygons.
Cull Off // first pass:
// render any pixels that are more than [_Cutoff] opaque
Pass {
AlphaTest Greater [_Cutoff]
SetTexture [_MainTex] {
combine texture * primary, texture
}
} // Second pass:
// render in the semitransparent details.
Pass {
// Dont write to the depth buffer
ZWrite off
// Don't write pixels we have already written.
ZTest Less
// Only render pixels less or equal to the value
AlphaTest LEqual [_Cutoff] // Set up alpha blending
Blend SrcAlpha OneMinusSrcAlpha SetTexture [_MainTex] {
combine texture * primary, texture
}
}
}
}

参考:file://localhost/Applications/Unity/Unity.app/Contents/Documentation/Documentation/Components/SL-AlphaTest.html

 

AlphaTesting的更多相关文章

  1. Unity3D Optimizing Graphics Performance for iOS

    原地址:http://blog.sina.com.cn/s/blog_72b936d801013ptr.html icense Comparisons http://unity3d.com/unity ...

  2. Performance Optimization (2)

    DesktopGood performance is critical to the success of many games. Below are some simple guidelines f ...

  3. 【C++0x】表达式之类型(decltype)

      C++0x引入了新的关键字decltype,它是一个操作符,用来取得表达式的类型,主要在泛型编程中使用.这里,简单介绍一下语法规则. 语法形式:decltype (expression)其中,这里 ...

  4. Unity官网针对IOS开发有比较好的建议

    Unity官网针对IOS开发有比较好的建议,我总结了翻译如下,后面附上原文. 尽量控制定点数量(注意所谓顶点不是建模时的顶点,而是引擎渲染时的顶点.例如,模型一个顶点如果设置了2个法向,那么对引擎来说 ...

  5. 移动平台unity3d优化

    目录(?)[-] Focus on GPUs 着眼于GPU Good practice 优秀的实践 Sharer optimizations 着色器优化 Focus on CPUs 着眼于CPUs G ...

随机推荐

  1. cell的循环利用

    方式1 // 1.先根据cell的标识去缓存池中查找可循环利用的cell UITableViewCell *cell = [tableView dequeueReusableCellWithIdent ...

  2. IMP-00013: 只有 DBA 才能导入由其他 DBA 导出的文件

    IMP-00013: only a DBA can import a file exported by another DBA 处理方法:在给目标环境的用户赋予dba权限,或者细粒度一些,赋予imp_ ...

  3. win10下启动zkui

    zkui是一个开源的zookeeper可视化工具,现在看下我们怎么启动这个工具.首先下载源码(我把它放在E:\workspace): git clone https://github.com/Deem ...

  4. GNU Radio: 自定义 block 实例

    综述 本文通过在GNU Radio 中编写一个block的例子,系统介绍创建一个block的过程.该 block 的功能是可以在GRC中通过滑块(WX GUI Slider)来实时改变信号源(Sign ...

  5. python 怎么和命令行交互

    http://www.cyberciti.biz/faq/python-run-external-command-and-get-output/ http://stackoverflow.com/qu ...

  6. 2、Hive UDF编程实例

    Hive的UDF包括3种:UDF(User-Defined Function).UDAF(User-Defined Aggregate Function)和UDTF(User-Defined Tabl ...

  7. awk:NF-NR-OFS-ORS-RS等参数

    ARGC 命令行参数个数ARGV 命令行参数排列ENVIRON 支持队列中系统环境变量的使用FILENAME awk浏览的文件名FNR 浏览文件的记录数FS 设置输入域分隔符,等价于命令行 -F选项N ...

  8. nested exception is com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1109 > 1024

    MySQL的一个系统参数:max_allowed_packet >mysql -u root -p //root登录 1. 查看系统参数:show VARIABLES like '%max_al ...

  9. "锁"

    “锁”,指的是状态切换,状态未切换完成,加上锁,完成后才打开锁. 下面例子要完成一个点击按钮切换颜色的小示例,先看未加“锁”时候的效果 <!DOCTYPE html> <html l ...

  10. EFCodeFirst使用Nuget更新数据库

    在MVC开发中,习惯于使用EF作为数据库操作,相对于传统的Ado.Net的数据库操作方式,EF大大的节省了我们手写SQL语句的时间,即便是传统的使用代码生成的方式.EF操作数据库目前分为两种大的方式. ...