文章内容主要参考冯乐乐的博客,原链接:点击打开链接
shader介绍的前3条链接
只是我把内容写成代码,然后了注释,比较简洁,附代码:
//shader的路径,它会出现在你选择某个Material的shader时的下拉列表里,并且可以随时更改;
Shader "Custom/BasicDiffuse" {
//大括号内的内容会出现在inspect面板,注意这里不要;号
Properties {
//变量名,在inspect里面显示名字,数据类型,默认值
_EmissiveColor("Emissive Color",Color)=(1,1,1,1)
_AmbientColor("Ambient Color",Color)=(1,1,1,1)
_MySliderValue("This is a slider",Range(0,10))=2.5
_MainTexture("Base(RGB)",2D)="white"{}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
//当我们在Properties块中声明一个新的变量时,就提供了在Inspector界面中改变它的值的方式。
//这将自动建立一个连接,两者将操作同一个数据。
//数据类型,变量名,这里注意变量名,要跟Properties里面声明的相同
float4 _EmissiveColor;
float4 _AmbientColor;
float _MySliderValue;
struct Input {
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
//在这个函数里面计算值
void surf (Input IN, inout SurfaceOutputStandard o) {
float4 c;
c=pow((_EmissiveColor+_AmbientColor),_MySliderValue);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
//当这个shader在当前环境中运行失败后,会默认调用Unity自带的Diffuse Shader
FallBack "Diffuse"
}