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. Linux安装vsftpd总结

    我使用的是CentOS6安装的vsftpd,转载请注明出处,以下是我的记录: #查看是否已经安装了vsfptd vsftpd -v #安装 yum -y install vsftpd #创建:chro ...

  2. Proteus 仿真运算放大器出现 GMIN 问题

    Proteus 仿真运算放大器出现 GMIN 问题 为了仿真一个反相运算放大器,在仿真时出现 GMIN 问题,将 后面的 4.7UF 去掉就可以正常仿真. 初步检查是因为输入频率太低,输入时我用的是 ...

  3. nginx 通过proxy_next_upstream实现容灾和重复处理问题

    ngx_http_proxy_module 模块中包括proxy_next_upstream指令 语法: proxy_next_upstream error | timeout | invalid_h ...

  4. linux查找目录下的所有文件中是否含有某个字符串 (转)

    查找目录下的所有文件中是否含有某个字符串 find .|xargs grep -ri "IBM" 查找目录下的所有文件中是否含有某个字符串,并且只打印出文件名 find .|xar ...

  5. Oracle分组函数实例

    分组函数也叫聚合函数.如果在查询只想要查分组函数,那么跟平时的查询语句并无不同: SQL ,,,,) ; SUM(T.PRIZENUM) AVG(T.PRIZENUM) --------------- ...

  6. RK3288 添加WiFi&BT模块AP6212

    CPU:RK3288 系统:Android 5.1 注:系统中自带的模块没有AP6212,相近的只有AP6210,设置为AP6210,直接添加固件也可以正常使用. 此文是手动添加AP6212的例程. ...

  7. Go的List操作上的一个小“坑”

    转自http://sharecore.net/blog/2014/01/09/the-trap-in-golang-list/ 一直想不清楚一个问题,简单设计的东西到底是“坑多”还是“坑少”呢? 复杂 ...

  8. Ajax下载

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  9. znpc改版前后网址修改办法

    znpc改版前后网址修改办法把原网址中的http://bbs.znpc.net/viewthread.php?替换为http://bbs.znpc.net/forum.php?mod=viewthre ...

  10. JDK 8 - Method Reference 分析

    Java SE 8 在 Java 语言层面上新增了 lambda expression 的功能,使得 Java 具备了函数式语言的能力 - 可以将函数作为方法参数传递,即 code as data. ...