Beast Lightmapping Math

Hey, I’m trying to reduce draw calls by merging the lightmap texture produced by beast with my normal diffuse texture, so it can be drawn in a single pass. I’m having a problem with understanding how unity combines these at runtime, so I can do it offline in photoshop with blend layers. I thought it was a straight up multiply, then double, but no luck ;_;

Posted a test scene to show the difference:

The bottom one appears to be more vibrant. There are no lights in the scene and the scene ambience is black. Any ideas what would cause the differences?

Apologies if this in the wrong forum, was going to put it in shaderlab, but iphone peeps might have more experience in doing this for optimisation reasons.

I think you can replicate the function of Unity with the OVERLAY method in Photoshop.
This enhances the light tones and dark tones by multiplying respectively up and down, thus increasing contrast.

The lightmaps baked in Unity 3.0 are semi-HDR. The exact encoding depends on the target platform (i.e. for mobile platforms it’s different). On a PC, the encoding is “RGBM”, with values in the range of 0…8.

Decoding is: finalColor = color.rgb * color.a * 8

So if you try just using that texture without corresponding decoding, you lose the “* color.a * 8” part.

Alternatively, I guess you can set the generated lightmaps to be imported as regular texture, instead of a lightmap, in which case RGBM encoding won’t be done on them.

Hey i’m using thE EXR lightmaps in my won shaders, decoding the RGBM valiez thanks to the formula you provided. Works fine. Just out of curiosity (and in case i need to port some scenes to my recently acquired unity iPhone licence, what’s the encoding on that platform? Also i noticed that a scene baked for pc/Mac with beast becomes screwed up when switching to iPhone target. Is this a bug or is there a particular reason for that? (from what i noticed, it looked More like UVs getting screwed up than just the lightmap values not being read properly.

Tks Aras for all the great insight you provide on the forums!

Thanks for that info Aras - its the only reference that explains the diff between my lightmaps on standalone vs. iOS. I was wondering if you have any other information to share as in how the encoding is done on the iOS side. My HDR lightmaps looks “clipped” in its light range and i’m hoping that if i understand the encoding difference then i can find a fix in photoshop to edit the .EXR so that it’ll look same on standalone and on iPAD.

Thanks in advance.

I know this is old, but I found this info in UnityCG.cginc that may help others with similar Q’s
:

// Decodes lightmaps:
// - doubleLDR encoded on GLES
// - RGBM encoded with range [0;8] on other platforms using surface shaders
inline fixed3 DecodeLightmap( fixed4 color )
{
#if defined(SHADER_API_GLES)  defined(SHADER_API_MOBILE)
	return 2.0 * color.rgb;
#else
	// potentially faster to do the scalar multiplication
	// in parenthesis for scalar GPUs
	return (8.0 * color.a) * color.rgb;
#endif
}