纹理在基本的顶点光照被计算后被应用。在着色器中通过SetTexture 命令来完成。
该文章出自
【狗刨学习网】
SetTexture 命令在片面程序被使用时不会生效;这种模式下像素操作被完全描述在着色器中。
材质贴图可以用来做老风格的混合器效果。你能在一个通道中使用多个SetTexture 命令 - 所有纹理被顺序的应用,如同绘画程序中的层一样。SetTexture 命令必须放置在通道的末尾。
纹理块控制纹理如何被应用。在纹理块中能执行3种命令:合并,矩阵和不变色。
combine src1 * src2 将源1和源2的元素相乘。结果会比单独输出任何一个都要暗
combine src1 + src2
将将源1和源2的元素相加。结果会比单独输出任何一个都要亮
combine src1 - src2
源1 减去 源2
combine src1 +- src2 先相加,然后减去0.5(添加了一个符号)
combine src1 lerp (src2) src3
使用源2的透明度通道值在源3和源1中进行差值,注意差值是反向的:当透明度值是1是使用源1,透明度为0时使用源3
combine src1 * src2 + src3
源1和源2的透明度相乘,然后加上源3
combine src1 * src2 +- src3
源1和源2的透明度相乘,然后和源3做符号加
combine src1 * src2 - src3
源1和源2的透明度相乘,然后和源3相减所有源属性都可以是previous, constant, primary or texture其中的一个。- Previous is the the result of the previous SetTexture.
上一次SetTexture的结果 - Primary is the color from the lighting calculation or the vertex color if it is bound.
来自光照计算的颜色或是当它绑定时的顶点颜色 - Texture is the color of the texture specified by [_TextureName] in the SetTexture (see above).
在SetTexture中被定义的纹理的颜色 - Constant is the color specified in ConstantColor.
被ConstantColor定义的颜色
- Previous is the the result of the previous SetTexture.
Modifiers 解释:
- 上述的公式都均能通过关键字 Double 或是 Quad 将最终颜色调高亮度2倍或4倍。
- 所有的src属性,除了差值参数都能被标记一个-符号来使最终颜色反相。
- 所有src属性能通过跟随 alpha 标签来表示只取用alpha通道。
Texture block constantColor command (纹理块constantColor 命令) ConstantColor color
定义在combine命令中能被使用的不变颜色 Texture block matrix command (纹理块matrix命令) matrix[MatrixPropertyName]
使用给定矩阵变换纹理坐标 Details 细节
较老的显卡对纹理使用分层的方案。纹理在每一层后被应用一次颜色的修改。对每一个纹理,一般来说纹理都是和上一次操作的结果混合。
注意,在“真正的固定功能”设备(OpenGL, OpenGL ES 1.1, Wii),每个SetTexture阶段的值被限制为0..1范围。其他地方(Direct3D, OpenGL ES 2.0)该范围可能或不可能更高。这可能会影响SetTexture阶段,可能产生的值高于1.0。
Separate Alpha & Color computation 分离的透明度和颜色混合
缺省情况下,混合公式被同时用于计算纹理的RGB通道和透明度。同时,你也能指定只针对透明度进行计算,如下:
SetTexture[_MainTex]{ combine previous * texture, previous + texture }
如上所述,我们对RGB的颜色做乘然后对透明度相加
Specular highlights 反射高光
默认情况下primary颜色是漫反射,阴影色和高光颜色(在光线计算中定义)的加和。如果你将通道设置中的SeparateSpecular 打开,高光色会在混合计算后被加入,而不是之前。这是内置顶点着色器的默认行为。
Graphics hardware support 图形硬件支持
一些旧的显示卡不能支持某些纹理混合模式,不同的卡有不同数目的SetTexture阶段可用。着色器作者应该为他们想支持的卡分开写SubShaders 。
支持像素着色器1.1版本的图形卡(...)支持所有的混合器模式并且可以拥有至少4级渲染阶段。下表简述了硬件支持。
示例
这个小例子使用了两张纹理。首先设置第一个混合器只使用_MainTex,然后使用_BlendTex的Alpha通道来淡入_BlendTex的RGB颜色。
Alpha控制自发光
把顶点光照着色器的所有的光照属性放入: