Lightmaps & Converting image to another uv space
This post is about methods to convert an image (texture, displacement map etc.) made for specific uv-mapping, into corresponding image for another uv-mapping of the same object.
Let’s say, you need to convert a displacement map generated for AUV/GUV mapping of zBrush into more “reasonable” one (loading it into zBrush and regenerating displacement doesn’t work… don’t ask, I had this situation in a midpoint of production
) to mix it with displacement for another uvSet (mentalray has problems with multi-uvSet displacement). Or the mapping of the object has changed, and you want to update already painted textures as well. Or something else – you name it

So, here’s a head displacement map for a specific mapping. For some reasons we’ve decided to change it into this (definitely, this is not a best head uv mapping showcase
):

For conversion we need to have both mappings as separate uvSets (how to transfer mapping from one object to another with the same or different topology/vertex order – is another topic you better get familiar with, ’cause this issue appears all the time
) In this case, original map was made for default map1, and we need to convert it into next uvSet after that (named cyl).
Now we have two methods to do the conversion: first one is what we call user-friendly, but it’s slower and produces poorer result; second one is a bit more difficult to setup, but faster and makes better quality. I’ll describe both in the same order.
- Batch Bake (mental ray) -
1) Assign to an object a surfaceShader with original map on the uvSet it’s made for (in this case, it’s default map1):

2) Disable everything we don’t need in render settings (finalGather for example) and set an appropriate sampling (it’ll define amount of artifacts in converted image and the time of the conversion itself);
3) Open options dialog for Lighting/Shading > Batch Bake (mental ray), enable ‘Use bake set override’ and set resolution, bit depth and file format you need. It’s important to set Color mode: Light and color. At the bottom ‘Override mesh UV set assignments’ lets you specify uvSet name you want to convert this Light and color data (i.e. out image map) into:

Now run the conversion and wait for the result (usually placed into mentalray/lightMap folder of the current project):

Despite the user-friendly interface and simplicity of shader network, conversion time via this method is pretty long (10 min in my case), and the resulting map has artifacts in high density areas:

So, let’s switch to the second method…
- mib_lightmap_write shader -
1) Assign surfaceShader without any maps to your object, just constant material to minimize calculations;
2) Once again, disable everything we don’t need like finalGather, but in this case sampling doesn’t matter – set it to low values for the sake of render time. Actually, you can point the camera into empty space to render nothing.
3) Connect mib_lightmap_write shader to shadingGroup of this surfaceShader (maya should do the default connection of .message to .miLightMapShader itself), and set four things there:

texture: connect mentalrayTexture node here, enable writable for it and set resolution, bit depth and the name of the file to store conversion result into (file extension will define the file type, i.e. entering .exr would make this file the actual openEXR type one, though traditionally without reasonable compression
);

coord: coordinates data to convert image into. Plug mib_texture_vector here (through mib_texture_remap if you want to mess with uv regions) and set the target uvSet to convert into (attribute select: 0 – points to default map1, 1 – points to the next one, cyl in this case);
input: actually, that’s what you want to convert. Connect mib_texture_lookup here with another mib_texture_vector in it, which obviously has select set to 0 (since original map is made for default map1). The image itself could be maya file node or mentalrayTexture (with writable turned off this time, of course);
fg_mode: disable with -1 value;

Now render the image (could be blank, as I’ve already mentioned above), lightmap generation will start and make converted file we need, then usual rendering will run though we don’t need it anymore.
Through this method we get better quality result (no artifacts anymore) and much faster (6 sec in my case).
Adding a scene with this network:

3 Responses to “Lightmaps & Converting image to another uv space”
Отлично
очень интересно!
вопрос: а можно таким способом запечь occlusion, а то черерез Batch Bake (mental ray) уж очень много артефактов, даже с завышенными настройками.
Можно запечь что угодно – процедурные текстуры, освещение, отражения и т.п. Окклюжен тоже, только возможно скорость будет не очень. Просто тыкайте в инпут лайтмапа то что нужно запечь (и в mib_texture_vector надо правильный uvSet поставить – скорее всего 0).
Leave a Reply