Shader "Custom/Test01" { //Custom/Test01 表示所以 Shader的所在位置和名字
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
//_Name("Display Name", type) = defaultValue[{options}]
//_Name - 变量名 Display Name 显示面板上的变量名
// type 类型
}
SubShader {
Tags { "RenderType"="Opaque" }
//Tags 渲染类型 = 不透明的
//类型分类 Transparent 透明的 Opaque不透明的
//Tags有很多分类常用有
// "IgnoreProjector"="True" 不被Projectors影响 //"ForceNoShadowCasting"="True" 从不产生阴影
//"Queue"="xxx" 指定渲染顺序队列
LOD 200
//LOD 代表可以被渲染的组件等级,可以使用什么样的组件
//VertexLit及其系列 = 100
//Decal, Reflective VertexLit = 150
//Diffuse = 200
//Diffuse Detail, Reflective Bumped Unlit, Reflective Bumped VertexLit = 250
//Bumped, Specular = 300
//Bumped Specular = 400
//Parallax = 500
//Parallax Specular = 600
CGPROGRAM //开始标记 这是一段CG程序
//基于物理的标准照明模型,并对所有光源类型启用阴影
#pragma surface surf Standard fullforwardshadows
//#pragma 编译
//surface 表示是一个表面着色器
//Standard 着色器代码的方法的名字 //标准的
//fullforwardshadows 全面阴影
//使用着色器模型3.0,以获得更好的照明
#pragma target 3.0
sampler2D _MainTex; //定义一个sampler2D的变量
//sampler2D就是GLSL中的2D贴图的类型 sampler1D,sampler3D,samplerCube等
//_MainTex = 着色器部分所定义的变量 !!这是一段CG程序,必须使用和之前变量相同的名字进行声明。 (下同)
struct Input { //输入的结构体必须命名为Input
float2 uv_MainTex;
//float2变量 代表两个float数
// uv 提取uv值,_MainTex着色器变量
};
half _Glossiness;//定义一个half
//half 16位浮点数 float是32位浮点数
half _Metallic;//定义一个half
fixed4 _Color;//定义一个fixed4
//fixed定点数 fixed4 四个定点数
void surf (Input IN, inout SurfaceOutputStandard o) { //input输入部分由struct定义 //inout 输出 SurfaceOutput结构
//out 部分参数
//struct SurfaceOutput {
// half3 Albedo; //像素的颜色
// half3 Normal; //像素的法向值
// half3 Emission; //像素的发散颜色
// half Specular; //像素的镜面高光
// half Gloss; //像素的发光强度
// half Alpha; //像素的透明度
// 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"
}
Unity shader学习笔记 (三)
最新推荐文章于 2022-11-02 17:30:45 发布