1.Shader在什么情況下使用
Self-Illumin(自身照明),即自發(fā)光材質(zhì)魄梯,乍看一下這玩意還真不太熟伟叛,仔細(xì)研究了下源碼發(fā)現(xiàn)其實也就是最簡單的顏色混合兄墅。本系列主要是針對不愿意用光照的系統(tǒng)自行發(fā)光,通過光照貼圖來渲染顏色晃酒,這樣可以避免復(fù)雜的光照困擾表牢。
2.Shader的價值(用的多不多),Shader的難度
個人幾乎沒見過用官方的這個shader掖疮,難度低初茶。
3.代碼詳細(xì)注釋
Shader "Legacy Shaders/Self-Illumin/Bumped Diffuse" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_Illum ("Illumin (A)", 2D) = "white" {}
_BumpMap ("Normalmap", 2D) = "bump" {}
_Emission ("Emission (Lightmapper)", Float) = 1.0
}
CGINCLUDE
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _Illum;
fixed4 _Color;
fixed _Emission;
struct Input {
float2 uv_MainTex;
float2 uv_Illum;
float2 uv_BumpMap;
};
void surf (Input IN, inout SurfaceOutput o) {
//主紋理采樣
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
//混合_Color
fixed4 c = tex * _Color;
//設(shè)置Albedo顏色
o.Albedo = c.rgb;
//自發(fā)光顏色由紋理顏色和_Illum采樣顏色的a通道混合
o.Emission = c.rgb * tex2D(_Illum, IN.uv_Illum).a;
//主要用于meta pass,用于烘焙Lightmap
//詳細(xì)看這篇https://blog.csdn.net/u012871784/article/details/81179432
#if defined (UNITY_PASS_META)
//讓自發(fā)光的強度與_Emission做倍率乘法
o.Emission *= _Emission.rrr;
#endif
o.Alpha = c.a;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG
//兩個SubShader按順序執(zhí)行浊闪,執(zhí)行成功則后面的不執(zhí)行恼布,適配低端機型
SubShader {
Tags { "RenderType"="Opaque" }
LOD 300
CGPROGRAM
#pragma surface surf Lambert
#pragma target 3.0
ENDCG
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 300
CGPROGRAM
#pragma surface surf Lambert nodynlightmap //禁用動態(tài)光照貼圖
ENDCG
}
FallBack "Legacy Shaders/Self-Illumin/Diffuse"
//詳細(xì)看這篇https://blog.csdn.net/u012871784/article/details/81179432
CustomEditor "LegacyIlluminShaderGUI"
}
4.Shader編寫思路,用到的知識點
本系列烘焙的部分其實還比較復(fù)雜搁宾,可以看這篇