zoukankan      html  css  js  c++  java
  • UnityShader之固定管线命令Combine纹理混合【Shader资料4】

    Combine,纹理混合。

    我们先看圣典上给的解释。

      纹理在基本的顶点光照被计算后被应用。在着色器中通过SetTexture 命令来完成。

      SetTexture 命令在片面程序被使用时不会生效;这种模式下像素操作被完全描述在着色器中。

      

      材质贴图可以用来做老风格的混合器效果。你能在一个通道中使用多个SetTexture 命令 - 所有纹理被顺序的应用,如同绘画程序中的层一样。SetTexture 命令必须放置在通道的末尾

    Texture block combine command 纹理块合并命令

      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定义的颜色

    Modifiers 解释:

    • 上述的公式都均能通过关键字 Double 或是 Quad 将最终颜色调高亮度2倍或4倍。
    • 所有的src属性,除了差值参数都能被标记一个-符号来使最终颜色反相。
    • 所有src属性能通过跟随 alpha 标签来表示只取用alpha通道。

    Texture block constantColor command (纹理块constantColor 命令)

    ConstantColor color
    Defines a constant color that can be used in the combine command.
    定义在combine命令中能被使用的不变颜色

    Texture block matrix command (纹理块matrix命令)

    matrix [MatrixPropertyName]
    Transforms texture coordinates used in this command with the given matrix.
    使用给定矩阵变换纹理坐标 
    这个矩阵纹理坐标,官网没有给明确说明,百度谷歌也没有找到相关的资料,我个人的猜想可能是UV的设置。
    看到这里,我们大概了解了Combine的用法,它的作用就是将颜色或者纹理相互融合的一个指令。
    示例如下:
    示例中的previous 表示上一个SetTexture计算的结果,texture表示当前SetTexture的参数纹理,Primary则是当前光照的颜色。如果你的Shader打开了光照,如若参数中不使用Primary的话也是不会有光照效果的。
    Shader "Examples/Self-Illumination" {
        Properties {
            _MainTex ("Base (RGB) Self-Illumination (A)", 2D) = "white" {}
        }
        SubShader {
            Pass {
                // Set up basic white vertex lighting
                //设置白色顶点光照
                Material {
                    Diffuse (1,1,1,1)//漫反射颜色设置
                    Ambient (1,1,1,1)//环境光反射颜色设置
                }
                Lighting On
    
                // Use texture alpha to blend up to white (= full illumination)
                // 使用纹理Alpha来混合白色(完全发光)
                SetTexture [_MainTex] {
                    constantColor (1,1,1,1)    //自定义颜色
                    combine constant lerp(texture) previous
                }
                // Multiply in texture
                // 和纹理相乘
                SetTexture [_MainTex] {
                    combine previous * texture
                }
            }
        }
    }

    另外,我们也能只针对取透明度进行计算,如下所示:

    缺省情况下,混合公式被同时用于计算纹理的RGB通道和透明度。,如下所示:

    SetTexture [_MainTex] { combine previous * texture, previous + texture }

    逗号后面的previous + texture表示光照和当前图片纹理混合后的透明度,这个时候输出的结果的透明度就不会再是previous * texture的透明度了。
    小时候我把老婆种到地下,长大了我能收获一大堆老婆! 我是威少,我是一名Unity游戏的主程,我为自己带盐,希望此文能给您一点点微不足道的帮助,祝你成功!
  • 相关阅读:
    FAT学习笔记(五)——FAQ
    FAT32学习笔记(五)——fat相关工具
    FAT学习笔记(四)——Dir Entry
    FAT学习笔记(三)--FSInfo
    zabbix介绍
    配置pxe 自动化安装centos6.7
    跳转方式用name方法的话,浏览器返回按钮点击返回时会有BUG
    FormData使用方法详解
    vue中的@click.native
    vue从后台获取数据,并导出EXCEL文件
  • 原文地址:https://www.cnblogs.com/vsirWaiter/p/5992483.html
Copyright © 2011-2022 走看看