zoukankan      html  css  js  c++  java
  • AlphaTesting

    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) = (.5, .5, .5, .5)
            _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
            _Cutoff ("Base Alpha cutoff", Range (0,.9)) = .5
        }
        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
                }
            }
        }
    } 
    View Code

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

     
  • 相关阅读:
    CentOS+Nginx+PHP+MySQL详细配置(图解)
    linux下MySQL安装登录及操作
    hdu 1059 多重背包
    hdu 1754 单点更新
    poj 3264 RMQ 水题
    hdu 1114 基础完全背包
    hdu 3466 排序01背包
    poj 2923 状压dp+01背包
    hdu 2639 第k大01背包
    hdu 2184 01背包变形
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3868973.html
Copyright © 2011-2022 走看看