1,按照具体的步骤来生成LightMap文件后我们来写Shader
shader "LightMap/LightMapSH"{
Properties{
_MainTex("Main tex",2D) = "white"{}
}
SubShader{
pass{
CGPROGRAM
#pragma vertex vertx
#pragma fragment frag
#include "unitycg.cginc"
sampler2D _MainTex;
float4 _MainTex_ST; //unity 默认的纹理采样变量 后面加 ST
struct v2f{
float4 pos : POSITION;
float2 uv : TEXCOORD0;
float2 uv2 : TEXCOORD1;
};
v2f vertx(appdata_full v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP,v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
o.uv2 = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
return o;
}
fixed4 frag(v2f IN):COLOR
{
float3 lm = DecodeLightmap(UNITY_SAMPLE_TEX2D( unity_Lightmap,IN.uv2 ));
fixed4 color = tex2D(_MainTex,IN.uv);
color.rgb *= lm ;
return color ;
}
ENDCG
}
}
}