How to set a given Island margin for UV?

I am building assets in blender for use in UE4.

For UV maps and light maps I need to have 2 texels spacing around each island (i.e. 4 texels minimum between islands). To calculate what spacing I need in 0-1 space I use the formula 1/[lightmap size]*2 (e.g. 1/64*2 = 0.032 for a 64x64 map) to convert.

At first I naively plugged this value into the "Margin" parameter of the Unwrap function but this gave me a much too small margin in 0-1 space. Actually, A value of 1 (the maximum) for "Margin" translates into a margin of 0.111 in 0-1 space. Hmm.

2 questions:

• What is the math behind the "Margin" parameter of the Unwrap function?
• What is the process to get a margin of a given number of texels (besides trial and error which is time consuming)?
• it's indeed weird, never noticed this before. The margin parameter in the Lightmap Pack function produces different results from the margin parameter when you pack the islands using Ctrl + P. If you pack the islands after unwrapping with Ctrl + P and enter 0.032 in your example, does that reflect what you expect? – aliasguru Sep 11 '17 at 13:32
• The Lightmap pack function gives predictable results (Margin = percentage of full map size) but the behavior of Unwrap and Pack Islands is the same as described above. – jeancf Sep 14 '17 at 8:20