UnityShader学习2 SurfaceShader

//一份SurfaceShader最基础的模板
Shader "ShaderLearn/sf1" { Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} _Glossiness ("Smoothness", Range(0,1)) = 0.5 //光滑程度 _Metallic ("Metallic", Range(0,1)) = 0.0 //类型和下面CGPROGRAM模块中的变量一一对应 } SubShader { Tags { "RenderType"="Opaque" }//描述渲染类型 LOD 200//层级细节 CGPROGRAM //cg语法 // Physically based Standard lighting model, and enable shadows on all light types #pragma surface surf Standard fullforwardshadows /* surface: 编译指令,固定要写 surf:是下面的函数名; Standard:光照模型(其实也是函数,是unity的cginc后缀文件里面的函数) fullforwardshadows:这个之后的是描述的一些选项(这里指支持所有的阴影类型),其他更多选项详见官方手册,搜索Optional parameters */ // Use shader model 3.0 target, to get nicer looking lighting #pragma target 3.0//shader model 版本 //声明,与属性里面的变量一一对应 sampler2D _MainTex; half _Glossiness; half _Metallic; fixed4 _Color; struct Input { /* 用于描述uv的纹理坐标 使用uv开头的纹理属性说明使用第一套纹理,如果使用uv2开头,就会使用第二套纹理坐标。 _MainTex这个不能变 对应上面定义的属性名和 sampler2D _MainTex */ float2 uv_MainTex; }; // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader. // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing. // #pragma instancing_options assumeuniformscaling UNITY_INSTANCING_CBUFFER_START(Props) // put more per-instance properties here UNITY_INSTANCING_CBUFFER_END void surf (Input IN, inout SurfaceOutputStandard o) { /* 第一个参数:就是我们上边定义的一个Input结构体 第二个参数:inout即是输入又是输出, SurfaceOutputStandard是一个结构体 */ // Albedo comes from a texture tinted by color fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; o.Albedo = c.rgb; // Metallic and smoothness come from slider variables o.Metallic = _Metallic; o.Smoothness = _Glossiness; o.Alpha = c.a; } ENDCG//cg语法结束 } FallBack "Diffuse" }

 

posted on 2019-05-09 23:27  炼金师  阅读(123)  评论(0)    收藏  举报

导航