<Shader>第一段Shader程序

来源:互联网 发布:4g网络设计思路 编辑:程序博客网 时间:2024/06/02 04:18

第一段OpenGL代码

Shader "Shader/Shader_001" {

    properties{
        _Color("Main Color",color) = (1,1,1,1)     
    }

    SubShader{
        pass {
            color [_Color] //顶点的颜色
        }
    }
}

在Shader 程序中,Properties 和 FallBack 是可有可无的,但是SubShaders 在程序片段中是必须有的,但是没有Properties 我们讲无法为Shader定制属性,没有FallBack的时候,当任何一个SubShaders都无效的时候,我们的着色将失败。

下面为一个完整的Shader ,可以设置物体的材质,和透明度

Shader "Shader/Shader_002" {

    properties{
        _Color("Main Color",color) = (1,0.5,0.5,1)
        _Ambient("Main Ambien",color) = (0.3,0.3,0.3,0.3)
        _Specular("Main Specular",color) = (0.3,0.3,0.3,0.3)
        _Shininess("Main shininess",range(0,8)) = 8
        _Emission("Main Color",color) = (1,1,1,1)
        _Constantcolor("main constantcolor",color) = (1,1,1,1)
        _Texture("Main Texture",2d) = ""
        _Texture1("sceond tetxure",2d) = ""
    }

    SubShader
    {
        Tags { "Queue" = "Transparent" }
        pass 
        {
            blend SrcAlpha OneMinusSrcAlpha
            material 
            {
                diffuse [_Color]
                ambient    [_Ambient]  //环境光
                specular[_Specular] //高光
                shininess [_Shininess]     //高光反射的强度 到底有多强
                emission [_Emission]  //自发光
            }
            lighting on
            separatespecular on  //像镜子一样的独立的高光

            settexture[_Texture]
            {
                combine texture * primary  double
            }

            settexture[_Texture1]
            {
                constantcolor [_Constantcolor]
                combine texture * previous doubletexture * constant
            }
        }
    }
}

0 0
原创粉丝点击