UnityShader之固定管线Fixed Function Shader【Shader资料3】

Fixed function shader简介:  属于固定渲染管线 Shader, 基本用于高级Shader在老显卡无法显示时的情况。使用的是ShaderLab语言,语法与微软的FX files 或者NVIDIA的 CgFX类似。

1、使用固定管线来显示单一的颜色

Shader "Custom/1_1color" {
   // 属性
    Properties {
        //定义一个颜色
        _Color ("Main Color", Color) = (1,0.5,0.5,1)
    }
    // 子shader
    SubShader {
        Pass {
            Material {    //Material块是固定管线的核心之一,接下来我们还有SetTexture的使用
                //显示该颜色
                Diffuse [_Color]
            }
            //打开光照开关,即接受光照
            Lighting On //同学们可以把这里的On设置为Off试一试,看下关于接受光照的效果。
        }
    }
}

 结果如下图所示:

2、将一张图片和一个颜色同时渲染

Shader "Custom/1_2show1texture" {
    Properties {
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _Color("Main color",Color) = (1,1,1,1)
    }
    SubShader {
        Pass
        {
            Material
            {
                Diffuse[_Color]
            }
            Lighting on
            SetTexture[_MainTex]
            {
                //combine color部分,alpha部分
                //      材质 * 顶点颜色
                Combine texture * primary,texture * constant  //下一节讲Combine纹理混合的用法
            }
        }
    }
}

表现效果如下:

3、同时渲染两张图片

Shader "Custom/3_3Texture" {
    Properties {
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _MainTex2 ("Tex2 (RGB)", 2D) = "white" {}
        _Color("Main color",Color) = (1,1,1,1)
    }
    SubShader {
        Pass
        {
            Material
            {
                Diffuse[_Color]
            }
            Lighting on
            SetTexture[_MainTex]
            {
                //      第一张材质 * 顶点颜色
                Combine texture * primary
            }
            SetTexture[_MainTex2]
            {
                //      第二张材质 * 之前累积(这里即第一张材质)
                Combine texture * previous  //下一节讲Combine纹理混合的用法
            }
        }
    }
}

表现效果如下:

小时候我把老婆种到地下,长大了我能收获一大堆老婆! 我是威少,我是一名Unity游戏的主程,我为自己带盐,希望此文能给您一点点微不足道的帮助,祝你成功!
原文地址:https://www.cnblogs.com/vsirWaiter/p/5988979.html