不想写,,还想学,,只能想出个这种方法来了,参考:
https://onevcat.com/2013/07/shader-tutorial-1/
Shader "Unity Shaders Book/Chapter 3/Redify" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" } //renderType只是标记当前shader的类型,起个Tag作用,详情:https://www.jianshu.com/p/d8356533fcc2
LOD 200 //当lod小于的话就不会工作,zai QualitySetting里面会有
CGPROGRAM ///表名从这里开始,ENDCG结束
// #pargma 关键词 函数名 光照模型 [其它选项]
#pragma surface surf Lambert addshadow
//不懂,通过使用编译指示符#pragma multi_compile或者#pragma shader_feature,结合判定宏是否启用的指令defined,
//https://blog.csdn.net/wodownload2/article/details/104223134
#pragma shader_feature REDIFY_ON
//很复杂,ampler2D就是和texture所绑定的一个数据容器接口。
//要想访问在Properties中所定义的变量的话,必须使用和之前变量相同的名字进行声明。于是其实sampler2D _MainTex;做的事情就是再次声明并链接了_MainTex,使得接下来的CG程序能够使用这个变量。
//https://onevcat.com/2013/07/shader-tutorial-1/
sampler2D _MainTex; //二维纹理,为什么和上面的一样呢
struct Input {
//CG程序中,我们有这样的约定,在一个贴图变量(在我们例子中是_MainTex)之前加上uv两个字母,就代表提取它的uv值(其实就是两个代表贴图上点的二维坐标 )
float2 uv_MainTex;
};
// 输入 SurfaceOutput是预定义的输出结构,surf函数的目标就是根据输入把这个输出结构填上。
void surf (Input IN, inout SurfaceOutput o) {
//tex2d函数,这是CG程序中用来在一张贴图中对一个点进行采样的方法,返回一个float4
//取_MainTex图片上坐标为IN.uv_MainTex.点的RGBA
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
}