零碎代码
4.x 中lightmap相关的代码
//------------------------------------------------------------------------------------vs #ifndef LIGHTMAP_OFF o.lmap.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; #endif //------------------------------------------------------------------------------------ps // lightmaps: #ifndef LIGHTMAP_OFF #ifndef DIRLIGHTMAP_OFF // directional lightmaps fixed4 lmtex = tex2D(unity_Lightmap, IN.lmap.xy); fixed4 lmIndTex = tex2D(unity_LightmapInd, IN.lmap.xy); half3 lm = LightingLambert_DirLightmap(o, lmtex, lmIndTex, 0).rgb; #else // !DIRLIGHTMAP_OFF // single lightmap fixed4 lmtex = tex2D(unity_Lightmap, IN.lmap.xy); fixed3 lm = DecodeLightmap (lmtex); #endif // !DIRLIGHTMAP_OFF #endif // LIGHTMAP_OFF
平时我们只使用单光照贴图,可以这样写:
half2 lmap : TEXCOORD4; o.lmap.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; fixed3 lm = DecodeLightmap(tex2D(unity_Lightmap, i.lmap.xy));