- Home /
unity_LightmapMatrix in Cg ?
All is in the question, I search since an hour now, what is the Cg equivalent for this : unity_LightmapMatrix ?
If someone got the solution ?
Comment
Answer by mabulous · Jan 09, 2013 at 09:58 PM
I know this question is 3 months old, but since it is the only valid page on this topic when googling for it, probably other people will find it too, so I post my findings here:
While I didn't find exact equivalent to unity_LightmapMatrix, I figured out how to compute lightmap coordinates and access lightmap texture from a CG shader.
simpy add the following two uniforms:
float4 unity_LightmapST;
sampler2D unity_Lightmap;
then in your vertex shader calculate your lightmap UV coordinates like this:
float2 lightMapUV= ((v.texcoord1.xy * unity_LightmapST.xy) + unity_LightmapST.zw);
then in your fragment shader, access the lightmap like this:
fixed3 lightmap = DecodeLightmap(tex2D(unity_Lightmap, i.lightMapUV));
DecodeLightmap comes from UnityCG.cginc
HTH