Unity创建默认Shader 会为我们创建一个
Shader "Sbin/sf" {
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//计算材质所要表现金属光泽
}
//没有pass通道 自动帮我们生成代码
SubShader {
//描述渲染类型 是一个不透明的物体
Tags { "RenderType"="Opaque" }
LOD 200
//代码块 到End 使用CG语法
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
//根据 surface关键词 surf是下面的函数 Standard 使用的光照模型 fullforwardshadows描述的其它选项
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
//获得一个更漂亮的光照 不用默认2.0
#pragma target 3.0
sampler2D _MainTex;//二维纹理
struct Input {
float2 uv_MainTex;//必须使用uv开头不然下面获得不了
};
half _Glossiness;//浮点类型
half _Metallic;
fixed4 _Color;//4阶向量 对应Color
// 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
//输入 //有入有出 类似ref 类型
void surf (Input IN, inout SurfaceOutputStandard o) {
// 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
}
FallBack "Diffuse" //如果带不动回滚
}
改造成以前版本的surface shader
Shader "Sbin/sf" {
Properties {
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
//没有pass通道 自动帮我们生成代码
SubShader {
//描述渲染类型 是一个不透明的物体
Tags { "RenderType"="Opaque" "queue"="transparent" }
LOD 200
//代码块 到End 使用CG语法
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
//根据 surface关键词 surf是下面的函数 Standard 使用的光照模型 fullforwardshadows描述的其它选项
//#pragma surface surf Lambert alpha addshadow
#pragma surface surf Lambert addshadow
// Use shader model 3.0 target, to get nicer looking lighting
//获得一个更漂亮的光照 不用默认2.0
#pragma target 3.0
sampler2D _MainTex;//二维纹理
struct Input {
float2 uv_MainTex;//必须使用uv开头不然下面获得不了
};
//输入 //有入有出 类似ref 类型
void surf (Input IN, inout SurfaceOutput o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);//从纹理采样
o.Albedo = c.rgb; //漫反射颜色
o.Alpha = c.a;
}
ENDCG
}
//FallBack "Diffuse" //如果带不动回滚 注释掉不然用
}
//#pragma surface surf Lambert alpha addshadow
这个注释掉是采用 材质本身的alpha 但是有没有光照下的阴影