Unity3d Shader(三) Pass(Blending)带贴图的透明玻璃等

Blending is used to make transparent objects.

混合被用于制作透明物体。

Blend

When graphics are rendered, after all shaders have executed and all textures have been applied, the pixels are written to the screen. How they are combined with what is already there is controlled by the Blend command.

当图像被渲染时,所有着色器被执行以后,所有贴图被应用后,像素将被写到屏幕。他们是如何通过Blend命令的控制和已有的图像合并呢?

Syntax 语法

Blend Off
Turn off blending  关闭混合
Blend  SrcFactor DstFactor
Configure & enable blending. The generated color is multiplied by the  SrcFactor. The color already on screen is multiplied by  DstFactor and the two are added together.
配置并启动混合。产生的颜色被乘以SrcFactor. 已存在于屏幕的颜色乘以DstFactor,并且两者将被叠加在一起。
Blend  SrcFactor DstFactorSrcFactorA DstFactorA
Same as above, but use different factors for blending the alpha channel.
同上,但是使用不同的要素来混合alpha通道
BlendOp  Min | Max | Sub | RevSub
Instead of adding blended colors together, do a different operation on them.
不是添加混合颜色在一起,而是对它们做不同的操作。

Properties 属性

All following properties are valid for both SrcFactor & DstFactor. Source refers to the calculated color, Destination is the color already on the screen.

以下所有属性对SrcFactor或DstFactor都可用。Source指的是被计算的颜色,Destination是已经在屏幕上的颜色。

One The value of one - use this to let either the source or the destination color come through fully.
值为1,使用此设置来让源或是目标颜色完全的通过。
Zero The value zero - use this to remove either the source or the destination values.
值为0,使用此设置来删除源或目标值。
SrcColor The value of this stage is multiplied by the source color value.
此阶段的值是乘以源颜色的值。
SrcAlpha The value of this stage is multiplied by the source alpha value.
此阶段的值是乘以源alpha的值。
DstColor The value of this stage is multiplied by frame buffer source color value.
此阶段的值是乘以帧缓冲区源颜色的值。
DstAlpha The value of this stage is multiplied by frame buffer source alpha value.
此阶段的值是乘以帧缓冲区源alpha的值。
OneMinusSrcColor The value of this stage is multiplied by (1 - source color).
此阶段的值是乘以(1 - source color)
OneMinusSrcAlpha The value of this stage is multiplied by (1 - source alpha).
此阶段的值是乘以(1 - source alpha)
OneMinusDstColor The value of this stage is multiplied by (1 - destination color).
此阶段的值是乘以(1 - destination color)
OneMinusDstAlpha The value of this stage is multiplied by (1 - destination alpha).
此阶段的值是乘以(1 - destination alpha)

Details 细节

Below are the most common blend types:

以下是最常见的混合类型:

Blend SrcAlpha OneMinusSrcAlpha // Alpha blending Blend One One // Additive Blend One OneMinusDstColor // Soft Additive Blend DstColor Zero // Multiplicative Blend DstColor SrcColor // 2x Multiplicative

Example 示例

Here is a small example shader that adds a texture to whatever is on the screen already:

这里是一个着色器的小例子,添加一个纹理,无论是否已在屏幕上:

 

Shader "Simple Additive" {
    Properties {
        _MainTex ("Texture to blend", 2D) = "black" {}
    }
    SubShader {
        Tags { "Queue" = "Transparent" }
        Pass {
            Blend One One
            SetTexture [_MainTex] { combine texture }
        }
    }
}

And a more complex one, Glass. This is a two-pass shader:

更复杂的一个例子,玻璃。这是一个two-pass着色器:

  1. The first pass renders a lit, alpha-blended texture on to the screen. The alpha channel decides the transparency.
    第一个pass渲染光照、alpha混合纹理到屏幕上。Alpha通道决定的透明度。
  2. The second pass renders a reflection cubemap on top of the alpha-blended window, using additive transparency.
    第二个pass渲染在alpha混合窗口顶部一个反射立方体贴图,使用附加透明度。

 

 

Shader "Custom/e9" {
 // 此效果可用于玻璃上面的附加文字,图案,比如透明显示器 //
 Properties{
  _Color ("Main Color", Color) = (1,1,1,1)
  _MainTex ("Base (RGB) Transparency(A)", 2D) = "white" {}
  _Reflections ("Base (RGB) Gloss(A)", Cube) = "skybox" {TexGen CubeReflect}
  
 }
 
 SubShader{
  Tags {"Queue" = "Transparent"}
  Pass{
   // 混合透明,让物体透明 //
   Blend SrcAlpha OneMinusSrcAlpha
   // 主要颜色 //
   Material{
    Diffuse [_Color]
   }
   Lighting On
   // 材质 //
   SetTexture [_MainTex] {
    combine texture * primary double, texture * primary
   }
  }
  
  Pass{
   // 镜面反射透明 //
   Blend One One
   // 主颜色可不加 //
   Material{
    Diffuse [_Color]
   }
   Lighting On
   // 反射天空色 //
   SetTexture [_Reflections]{
    combine texture
    Matrix [_Reflection]
   }
  }
 }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值