新建Standard Surface Shader,详解说明
Shader "Custom/shader3"
{
Properties //Properties代码块
{
_Color ("Color", Color) = (1,1,1,1) //Color类型 双引号“Color”是用来显示在Inspector面板中 _Color是内部用
_MainTex ("Albedo (RGB)", 2D) = "white" {} //2D贴图类型
_B ("B", 2D) = "white" {}
_A ("A", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5 //数值范围0-1,默认取值0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader //SubShader
{
Tags { "RenderType"="Opaque" } //RenderType着色器类型,这里是渲染类型为不透明
LOD 200 //渲染层级
CGPROGRAM //CG语言 用来生成定点片元pass通道
// Physically based Standard lighting model, and enable shadows on all light types
//#pragma surface 指这个是表面着色器 ,surfmjj指方法名,Standard光照模型,fullforwardshadows支持前向渲染阴影
#pragma surface surfmjj Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex; //对应Properties代码块中_MainTex,CG中类型是sampler2D
sampler2D _B;
sampler2D _A;
struct Input //表面着色器输入结构体
{
float2 uv_MainTex; //纹理uv坐标必须“uv”开头,加纹理名称组合
float2 uv_A; //纹理_A的uv坐标
float2 uv_B; //纹理_B的uv坐标
};
half _Glossiness; //对应Properties代码块中_Glossiness,CG中类型是half
half _Metallic;
fixed4 _Color; //对应Propertiesz中color类型
UNITY_INSTANCING_BUFFER_START(Props) //GPU Instancing开和关
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
void surfmjj (Input IN, inout SurfaceOutputStandard o) //上面申明的surfmjj方法,具体定义
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
fixed4 a=tex2D(_A,IN.uv_A);
fixed4 b=tex2D(_B,IN.uv_B);
fixed4 d=lerp(c,b,a.a); //lerp混合贴图
o.Albedo = d.rgb; //返回主Albedo通道的颜色
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = d.a;
}
ENDCG
}
FallBack "Diffuse"
}
最后记录下最近的sss皮肤测试