shader开发_5.Surface shader官方例子(注释版本)

来源:互联网 发布:网络凶杀2 编辑:程序博客网 时间:2024/06/06 18:28

上一章unity 默认生成了一个 surface shader 这里来了解一下它

先上 unity 默认 surface shader 例子

Shader "Custom/myshader01" {          //shader的路径名称Properties {                   //资源属性代码块_Color ("Color", Color) = (1,1,1,1)  //定义一个纯白不透明_MainTex ("Albedo (RGB)", 2D) = "white" {} //2D贴图(可在面板进行赋值)_Glossiness ("Smoothness", Range(0,1)) = 0.5 //【光泽度】Range 表示一个范围 后面的=表示默认值_Metallic ("Metallic", Range(0,1)) = 0.0      //【金属强度】Range 表示一个范围 后面的=表示默认值}SubShader {                                       //SubShader的路径名称                                            Tags { "RenderType"="Opaque" }//标签,通过设置的标签决定什么时候渲染(这里表明在渲染不透明物体时渲染)                LOD 200 //  与unity Quality Settings  关联 如果Quality Settings指定小于当前设定 这此shader不可用                            CGPROGRAM                          //CG语言标记开始// Physically based Standard lighting model, and enable shadows on all light types#pragma surface surf Standard fullforwardshadows  //编译指令  surf 自定义函数 关照模型 [阴影类型]// Use shader model 3.0 target, to get nicer looking lighting#pragma target 3.0                                  //编译平台sampler2D _MainTex;     //如果你要在CG中使用Properties的定义 需要在这里声明                           struct Input {           //此结构提承载计算中的信息传递float2 uv_MainTex; //纹理坐标 (其实是引用的 Properties的_MainTex 名字之所以不同,是因为纹理坐标必须要以 uv开头  )};//同理 这里是上面声明的定义half _Glossiness;half _Metallic;fixed4 _Color;void surf (Input IN, inout SurfaceOutputStandard o) {  // //inout 表示此参数既可以输入 又可以输出    //inout SurfaceOutputStandard o  unity surface shader预定义的结构体// Albedo comes from a texture tinted by color   fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; //<span lang="zh-CN" style="font-family:'Microsoft YaHei'"><em>根据</em></span><span lang="en-US" style="font-family:corbel"><em>Uv</em></span><span lang="zh-CN" style="font-family:'Microsoft YaHei'"><em>进行采样</em></span><span lang="en-US" style="font-family:corbel"><em> </em></span>o.Albedo = c.rgb;                                                                  //设置返回的颜色值// Metallic and smoothness come from slider variableso.Metallic = _Metallic;                                                          //返回的金属程度o.Smoothness = _Glossiness;                                             //返回的光泽度o.Alpha = c.a;                                                                       //返回的透明信息}ENDCG                    //CG语言标记结束}FallBack "Diffuse"} 




0 0