Is this a bad way to fix the lightmap issue?

Hello, I had spent last night struggling with what I thought was a lightmap error. After spending quite a while trying to fix the problem and then replicate the problem I found it wasn’t the lightmap UV channel that was the issue but the first UV channel (which had overlapping UVs). Now from what I understand the UVs with your colour information can have overlapping UVs and your lightmap UVs can’t- which is what I had in this example…


What I did to fix this is I squashed all the UVs for the colour channel into the 0-1 space and used the texture coordinate node in the material editor to tile and stretch out my squashed UVs. The Lightmap UVs remained the same. This is the result:


As you can see the lighting has been baked with no errors. My question is that is this a bit of a hacky fix? Granted, it does look better but I was under the impression that overlapping UV’s were ok on a tileable texture- and has always worked for me previously. Or shall I just say ‘hey, as long as it looks good and works properly’ and get on with the rest of the scene.

Thanks in advance

I havent had any issues with beeing able to overlap in your first UV channel. Can you post your UV’s? both of them?

Hi Phillips -

With Tileable Mesh pieces and modular elements where you now you are wanting to overlap you UV’s in the texture, it is always better to create a second UV unwrap with your modeling program of choice. In the Static Mesh Editor, you can then set the Light Map Coordinate Index to 1 and have a texture coordinate index as 0 which is what your material applies to and 1 where you light map information applies to.

Here is a brief breakdown of how to generate the 2nd UV channel in 3ds Max:

Decide what my ultimate lightmap resolution will be in the engine, the default is 32, but I tend to like to push that a little up to 64 or even 128. If your using mobile 32 is probably fine.

Assuming you are combining your meshes into one in the engine, you will need to select all the meshes and apply an UnwrapUVW. If you are not combining them as one mesh in the editor, you will repeat the following steps for each mesh item.

In the UnwrapUVW modifer, Look for Map Channels section. It should by default be set to Channel 1 which is where you do all your texture unwraps for the materials. Click the up arrow next to the Channel 1 to advance to Channel 2.

A Window will pop up and ask you whether you want to Abandon or Move the Unwrap. Assuming that you like the islands you created in your initial unwrap and that the follow some since of shape to the mesh, you will want to MOVE the islands.

Once the Map Channel now says 2, Open your UV Editor.

In the UV Editor, under preferences, turn on your grid.

Still under preferences, Grid Size should be set to (1/[Resolution Size of your Lightmaps]) So for 64 it would be 0.015625 and 128 would be 0.0078125. Max will round up to its lowest significant digit in the window, but it will hold the original number entered.

Click OK to accept and close the window.

You should now see a very fine grid laid out over your 0,1 space. Each square in that new grid represents a pixel on the lightmap when it is rendered. Since a pixel is the smallest renderable unit, each square will either get a light component or a shadow component (think black or white).

Keeping Step 9’s knowledge at hand, layout your UV islands across you 0,1 space minding the general rules of leaving at least 2-3 grid boxes between each island and remember the edges of the map wrap so the top and bottom edge are connected as are the left and right.

Size of each island will probably not be nearly as big as on your texture unwrap and that’s ok as long as they are consistently not as big. Do not worry to much about organic lines and trying to lay them out perfectly according to the grid lines as long as you respect the 2-3 box space. Organic Shapes tend to already have more shading along them that you would not see on hard edge surfaces.

This is a time consuming process, but if you do it your shadows will look so much better and you will have far less problems with light builds.

Let me know if this helps

Eric

@Visceral3D:

Here are my UV maps for both versions. As you can see the ‘fixed’ version has squashed UVs which I have then stretched back out in the material editor. The 2nd image is how I thought they should’ve been but creates shading errors on my mesh.

Here are the lightmap UVs for both versions. All UVs are snapped to the grid with space between them.

Thanks for such an in depth response :). Unfortunately, I had done exactly that already. I have the same Lightmap UVs on both images in my previous post. However the UVs for my diffuse map is different. It seems as if I can only get good lighting on my prop is when they’re within the 0,1 space- although that shouldn’t be the case.

Hi Phillips -

This is an interesting issue and I am curious to dig into it further. If possible would you be willing to let us test your asset, an FBX and the texture would be all we need.

Let me know -

Eric

Hi Eric, here are the files you requested.

This is the prop in the images above:
https:///Large_Wall_002.FBX

Here is the texture file:
https:///Outer_Wall_Texture_Sheet_001.tga

And here are two other props which I have had the same issue with but fixed it with the squashed UVs:
https:///Large_Wall_Trim_003.FBX
https:///Large_Wall_Trim_004.FBX

Thanks for your help :slight_smile:

Hey -

I got the files and am working on the reproduction. Thank You again.

Eric

Hello, I’ve been trying to find a fix for this but no luck so far. How did you get on with the files I sent you?

Hi -

So I am not able to reproduce what happened to you. I am able to stretch the first UV channel outside the 0,1 space and have them tile correctly in the editor with correct lightmapping from the second UV channel.

Here is my UV unwrap in Maya (which you can see goes well outside the 0,1 space):

Here is the imported Asset in the Engine (Default Level):

And here is the UV0 Channel in the Static Mesh Editor(not the red outside of the 0,1:

And finally here is the UV1 Channel in the Static Mesh Editor(which I did not alter your unwrap):

-Eric

Hmm that’s weird how we’re getting different results. My first set of UVs that were giving me errors are the same as what you have. Could you send me an fbx file so I can compare and see what I might be doing wrong?

Hi -

Sure thing. Here is the adjusted FBX.

Eric

Test_FBX

Hi Eric. I imported your version no problems. However I couldn’t find any differences between our versions. I did another little test:

Your version is on top. Mine has the same UV layout but I’m getting different results again.

Now I figured that last time my fix was to squash all the UVs within the 0-1 space for the first channel. This worked but it wasn’t really the right way to do it.

As a little test I tried switching my UVs around so they were in the opposite channels. Obviously this wasn’t going to produce the desired result but what it did do was fix the shading errors. Note that the error message at the top is no longer present.

So I’m thinking is there something that might be causing the lightmap to be drawn from the first UV channel instead of the second. It seems that my colour information AND the lightmap is only being drawn from the first channel. Perhaps something is going wrong between exporting between 3ds max and UE4 or maybe there’s just a setting in UE4 that lets the game engine know that there are 2 sets of UVs that need to be read- although I’m pretty sure the latter is not the case.

Ok it’s official… I’m the biggest idiot on earth. Lightmaps on UE4 are defaulted at channel 0. Of course I needed channel 1. I changed the lightmap channel setting and got the result I was looking for…

facepalm

Now I have wasted several hours being daft I guess I can crack on with it

Thanks for your all your help though. Without it I probably would’ve been stuck on that simple problem forever lol.

Hi -

We all do it for time to time. I am happy that we solved your issue though. I am going to turn you final response into the correct answer for others who may come across the same issue.

Thank You

Eric