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. CentOS常用基础命令汇总

    1.关机 (系统的关机.重启以及登出 ) 的命令 shutdown -h now 关闭系统(1) init 0 关闭系统(2) telinit 0 关闭系统(3) shutdown -h hours: ...

  2. angularJS控制器之间的相互通信方式、$broadcast、$emit、$on

    在项目中,我们可能会很经常性的利用到控制器之间的相互通信,在angular中的控制器之间的相互通信有以下几种方式: 1)通过本地数据的存储localstorage,sessionstorage, 2) ...

  3. MEF学习总结(1)---总体架构

    用了很久的MEF框架来做依赖注入,最近想把它的原理和机构总结一下,主要包括如下几个方面: 1. 总体架构 2. .Net Composition Primitive 3. Attribute Mode ...

  4. 阿里云安装 virtio 驱动

    为避免部分服务器.虚拟机或者云主机的操作系统在阿里云控制台 导入镜像 后,使用该自定义镜像创建的 ECS 实例无法启动,您需要在导入镜像前检查是否需要在源服务器中安装 Xen(pv)或 virtio ...

  5. 关于微信js接口调用时,token效期问题

    如果一个应用的不同模块分配两个独立的公众号微官网使用,这时调用JS接口生成的token一定就冲突,原因是,token的有效期为两个小时. 解决方案: 将两个公众号的APPID与SERVERID分给不同 ...

  6. linux下echo命令详解

    linux的echo命令, 在shell编程中极为常用, 在终端下打印变量value的时候也是常常用到的, 因此有必要了解下echo的用法 例如: echo $JAVA_HOME /export/se ...

  7. 不能调用jquery中ready里面定义的函数?

    现象:不能调用jquery中ready里面定义的函数 源码:<script type="text/javascript"> $(document).ready(func ...

  8. WordSmith2013-6-19

    WordSmith Good Evening Ladies and Gentlemen,I’am Jason,I’m pleasured  to be wordsmith tonight. First ...

  9. JavaScript中的跨域详解(二)

    4.AJAX 同源政策规定,AJAX请求只能发给同源的网址,否则就报错. 除了架设服务器代理(浏览器请求同源服务器,再由后者请求外部服务),有三种方法规避这个限制. JSONP WebSocket C ...

  10. JS中的定时器

    在JS中的定时器分两种: 1,setTimeout() 2,setInterval() setTimeout(): 只在指定时间后执行一次: function hello(){ alert('hell ...