I’m wondering about scale map of directional lightmap.
This is baked sky light only.
Is this correct?
I want to try to get high light seems to ambient reflection with this map in Lighting_DirLightmap.
Is there a good way to use this map?
I’m wondering about scale map of directional lightmap.
This is baked sky light only.
Is this correct?
I want to try to get high light seems to ambient reflection with this map in Lighting_DirLightmap.
Is there a good way to use this map?
What is scale map?
isn’t this baked light direction?
What space does it use? World… Object…
It is in Tangent Space, with some biased vectors (For efficiently saving them in an unsigned RGBA8 texture)
To use it completely manually, you need your normals in tangent space, which if sampling normal maps, they already are (Unless rotated). It’s very cleaver when you have no normalmaps, then the l_dot_n for the dirlightmaps is simply the .z component (it’s equivalent to a dot product if all your normals are unmodified vertex normals)
You also need your viewDir in tangent space (Tangent-space viewDir is silly, but works, and can be converted directly from vert program!)
Here’s some code:
Vertex program to get the ts viewdir/lightmap coords:
TANGENT_SPACE_ROTATION;
o.ts_view = mul(rotation, ObjSpaceViewDir(v.vertex));
o.lm_coord = v.texcoord1 * unity_LightmapST.xy + unity_LightmapST.zw;
Fragment program to create the usual suspects of light components (normals, viewdir, lightdir, halfdir, n_dot_l, and v_dot_l)
half3 lmdir_sample = DecodeLightmap(tex2D(unity_LightmapInd, i.lm_coord.xy));
UNITY_DIRBASIS
half3 ts_light =
lmdir_sample.x * unity_DirBasis[0] +
lmdir_sample.y * unity_DirBasis[1] +
lmdir_sample.z * unity_DirBasis[2];
fixed l_dot_n = saturate(ts_light.z); //Normal is flat, therefore .z is sufficient
fixed v_dot_n = saturate(i.ts_view.z); //Normal is flat, therefore .z is sufficient
ts_light = normalize(ts_light);
fixed3 ts_half = normalize(ts_light + i.ts_view);
fixed n_dot_h = saturate(ts_half.z); //Normal is flat, therefore .z is sufficient
All that “Normal is flat” stuff can just be replaced by a dot product from your normals to the vector in question.
Hope it helps! It’s all meant for a vert/frag program in PrepassFinal or ForwardBase