How to lightmap without disturbing texture

Hi,

This is my first project so I'm on a bit of a learning curve.

I have a large number of objects that use the same shader. However, to make them look different I have been changing the size and position of the texture on the geometry in cinema 4d. This worked fine as I would import the fbx into unity and use the combine children script to combine the objects, but the textures on them stayed in the same place (I was using a cubic texturing, not UVs)

However, I need to lightmap these objects as I use a lot of lights and unity cannot run the game. I know how to create a lightmap and tile a texture in unity - this is ok for some things but for others it doesn't look right. I also know that I could bake the lightmap with the textures on in c4d, but the textures look really pixellated.

Is there not a way I can keep the texturing of the objects like in the first instance, but also apply a lightmap to them?

I am very thankful for your help :)

Yes there is. You need to create the lightmap coordinates in a second UV channel. This allows you to preserve your normal colour texturing and UV coordinates.

I haven't done this in cinema 4d (only in max), however I would guess that the concepts are broadly the same. It's also a fairly large topic, so I'm just going to breeze through the general idea quickly.

For instance, you might have lots of brick walls in your scene which each use a brick texture repeated many times. You also have some houses, which use a different texture.

These textures can be modified using a lightmap shader, which essentially darkens or lightens the colour texture based on the appropriate area from the lightmap texture.

You could lightmap this whole scene using one large lightmap texture, which is applied to all the objects, but it is applied in a different texture layer and uses the 2nd layer of UVs to determine which part of the lightmap texture should be used for each surface. So, regardless of whether your objects are using the brick texture or house texture in channel 1, they both use the lightmap texture in channel 2, and each surface maps to a different unique area within the lightmap.

In max, in the UV Unwrap modifier, there's an "automatic unwrap" tool, which basically takes every face on your model, and maps it to a unique area with the UV range. So you'd use this to make sure that every face of every part of your scene is mapped to some unique area of the lightmap texture, in the second UV layer.

So you can see that while your brick walls might use a fairly high-res tiled brick texture in channel 1, they will also use a completely different mapping to particular areas of the lightmap texture, at a comparitively low-res, and not tiled at all.

You can then use your 3d app's "bake texture" equivalent to bake the lighting into a texture, but make sure you tell it to use the UV2 layer, so that it bakes all the lighting onto the single lightmap texture - not using the colour texture layer!. You should end up with something that looks like a patchwork black and white jigsaw puzzle of all the shapes that make up your scene spread around one large texture.

You then need to export your scene to Unity, assign Lightmap shaders to your materials, and assign the single large lightmap texture to the appropriate texture slot in each material.