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. 日志框架--(二)JDK Logging

    前言 从jdk1.4起,JDK开始自带一套日志系统.JDK Logger最大的优点就是不需要任何类库的支持,只要有Java的运行环境就可以使用.相对于其他的日志框架,JDK自带的日志可谓是鸡肋,无论易 ...

  2. CSS内容简单归纳

    具体内容请查阅<CSS参考手册> 一.CSS模块介绍 1.1 CSS1中定义了网页基本属性 字体.颜色.补白.基本选择器等 1.2 CSS2中在CSS1的基础上添加了高级功能 浮动和定位. ...

  3. 关于CSS单位:rem vh vw vmin vmax

    rem(root em) 如果你给body设置了font-size字体大小,那么body的任何子元素的1em就是等于body设置的font-size demo: body {  font-size: ...

  4. Request.UrlReferrer详解

    使用前需要进行判断: if (Request != null && Request.UrlReferrer != null && Request.UrlReferrer ...

  5. js中去掉字符串中的某个指定字符

    假设一个data里面的数据是[tian,12],现在去掉[],代码如下 data=data.replace("[",""); data=data.replace ...

  6. ruby关于require路径

    ruby里面的require说明 require './aaaa' 这种方式,包含的是系统路径 相对路径得用下面的 require_relative "./xxxx" 或者使用这个 ...

  7. linux保存的设置用户/组ID(set-user-ID)的测试

    直接贴代码和结果 // FileName: id.cpp #include <iostream> #include <unistd.h> using namespace std ...

  8. struts2学习(12)struts2验证框架2.自定义验证

    一.例子需求: 对敏感词进行验证: 将struts包中的validators.xml文件拷贝一份到src目录下,在最后面添加自己的验证器: com.cy.validators.SensitiveWor ...

  9. MySQL单表多字段模糊查询解决方法 又折磨半天concat(字段不能为空,如为空则用IFNULL(字段,'');

    SELECT `id`,`weixin_id`,`user_name`,`sex`,`area_id`,`address_near`,`phone`,`create_time`,`import_use ...

  10. python的可变数据类型和不可变类型

    python里面一切皆对象 ython的每个对象都分为可变类型和不可变类型 整形,浮点型,字符串,元组属于不可变类型,列表,字典是可变类型 不可变数据类型 对不可变类型的变量重新赋值,实际上是重新创建 ...