shader回顾02 --- 固定管线编程基础

来源:互联网 发布:java重写的作用 编辑:程序博客网 时间:2024/05/23 11:05

固定管线编程是很老的一种shader编程,约束性比较高,但是还是必须要了解的,因为很多功能shader说真的不需要重头到尾部编写,但是必须要看得懂,可以修改。好不多说上代码。

//fix function shader,逐步添加
Shader "myShader/fixShader" {
    //3.属性
    properties{
        //3.外部颜色
        _Color02("Color02" , color) = (1,1,0,1)
        // 5.漫反射
        _diffuseColor("diffuse",color) = (1,0,1,1
        //6.环境光
        _Ambient("Ambient",color) = (1,0,1,1)
        //7.高光
        _Specular("Specular",color) = (0,1,1,1)
        //8.条件高光的范围
        _SpecularRang("SpecularRang",range(0,1)) = 0.5
        //9.自发光
        _Emission("Emission",color) = (0,1,1,1)
        //10.贴图
        _MainTex("MainTex",2d) = ""
    }
    SubShader {
        //4.没有立体感,必须打开光照 on/off 但是此时没有环境光全黑
        lighting on

        //7. 使用高光必须打开separatespecular
        separatespecular on

        //12.渲染顺序
        Tags{"Queue" = "Transparent"}

        //1.至少一个pass通道
        pass{
            //11.透明度
            Blend SrcAlpha OneMinusSrcAlpha
            //2.第一个颜色值
            //color(1,1,0,1)
            //3.外部颜色,注意就是参数在fix function 里面使用[]
            //color[_Color02]
            //5.材质块
            material{
                 //5.漫反射其实可以理解为自己的颜色
                //diffuse(1,1,0,1)
                diffuse[_diffuseColor]
                Ambient[_Ambient]
                Specular[_Specular]
                shininess[_SpecularRang]
                emission[_Emission]
            }

            //10.贴图
            setTexture[_MainTex]
            {
                //透明度有关
                constantColor(1,1,1,0.4)

                //combine 命令 texture代表就是当前的纹理贴图 primary使用上之前的顶点数据 double 就是两倍因为纹理相乘之后更加小了都是float
                combine texture * primary double,texture*constant
            }
            //多张贴图 previous
            setTexture[_MainTex]
            {
                //透明度有关
                constantColor(1,1,1,0.4)

                //combine 命令 texture代表就是当前的纹理贴图 previous 使用之前所有计算包括贴图过后的数据
                combine texture * previous double,texture*constant
            }
        }
    }

}

0 0
原创粉丝点击