Home Technical Talk

My experiment with Lightmaps in UVch2

polycounter lvl 18
Offline / Send Message
capone polycounter lvl 18
I've often heard that you're not supposed to overlap uv's when making lightmaps. I wanted to test this theory and have found that it IS ok to overlap uv's. Sure, if you want multiple copies of say a pillar to have their own unique uv space for colour variation that's all good but I often come across little things that will receive the same light and don't really require any unique attention. I've now come to the conclusion that it's ok to overlap such elements and in the process I save extra uv space to improve the overal quality of the lightmap.

Let me explain what I found out and after I'd love to hear what others can add to the theory to help me better understand this process.



So first here is a scene. The box is the main piece in question. So in UV2 I have the bottom poly in the middle and the side poly to the left.

dellighttest1.jpg

Now as expected, 2 is pitch black because it's sitting on the floor. 1 shows the shadow of the half box next to it.

dellighttestresult1.jpg

Ok so now lets map the opposite side to 1 and give it unique uv's

dellighttest2.jpg

both 1 and 3 have the same info because in the scene they are receiving the same light information because both sides of the scenery are symmetrical. As expected.

dellighttestresult2.jpg

So I move the uv's of 3 and overlap with 1. It gets exactly the same result, uv space saved.

dellighttestresult3.jpg

Ok,so what if we moved the teapot close to 1

dellighttest3.jpg

I thought at this point the teapot shadow would be on both sides or something since they are flipped...

dellighttestresult4.jpg

...Yet I flipped the uv of JUST 3 and rendered again, the same result. I flipped it vertically, the same.

Conclusion? It's fine to overlay lightmap UV's and it doesn't matter if they are flipped. Just as long as they perfectly overlayed.

Can anyone back this up or add some thoughts?

Replies

  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    While this may work for a few cases of ambient occlusion, this idea falls apart as soon as you have directional lighting. Since the lights might be casting directional shadows and illuminating surfaces in only one direction, as soon as you overlap or stack any UVs, your lightmap will most likely become incorrect.
  • capone
    Offline / Send Message
    capone polycounter lvl 18
  • capone
    Offline / Send Message
    capone polycounter lvl 18
    I see where I'm getting confused here. My previous studio would make UV channel2 maps for most assets but they didn't bake a lightmap but rather somehow the game engine picked it up and calculated real time lighting based on those uv's...or something.

    I'm trying to find a reason to map channel2 for an portfolio asset, does it make no sense to continue? Another advantage from mapping to channel2 that I know of is that you can add a 'colour map' (never found the correct term for this) that overlays the diffuse in the engine but because the uv's are much more unique you can add extra colours/stains etc to each of multiple repeated elements.

    Basically, what's the advantages of mapping to UV2?
  • Eric Chadwick
    UV2 = each face has its own unique spot in the UV, so the lighting can be different & specific. Lightmaps are usually lower-frequency (less detailed than the color map), so the texture pixels can be quite large and still look OK.

    UV1 = you can overlap, reuse, and/or tile the texture to your heart's content. This makes the texture pixels smaller on the mesh, and so you get more apparent detail. Cracks, woodgrain, writing, etc.

    The other texture you mentioned is usually called a detail map.
  • capone
    Offline / Send Message
    capone polycounter lvl 18
    Thanks for the info. I think in my case then the only benefit from mapping to UV2 would be to create a detailmap.
  • Eric Chadwick
    Well the detail map typically just uses the same UV as the color map, except the tiling is increased in the shader. So no need for UV2.
  • glib
    Eric: I think he was talking about an unwrapped channel 1, not a tiling one. Using a 'detail map' on a second channel that was uniquely unwrapped seems like an awkward route to embark on. Using decals or blending would probably make more sense.

    capone: If you're not lightmapping an asset, then you're right, you don't need a unique second uv channel. If you're looking to bake in certain always present shadows or occlusion, then doing a more clever unwrap in your first channel and baking it in there would probably be a better route.
  • capone
    Offline / Send Message
    capone polycounter lvl 18
    Hmm, ok, couple more questions...

    1) Just say I was doing a lightmap for the purpose of the engine, does my original theory still make sense that it's ok to overlap/flip uv's?

    2) So just for portfolio reasons I want to have some sort of detail map. So for (a made up) example, I have 4 wheels. I had a small texture budget so overlapped all 4 wheels in my diffuse map on channel1 but I want to add little smears of extra colour/dirt etc here and there on each wheel so they look different. Now glib suggested 2 solutions 1 of which is decals, when he says decals I think of lots of planes placed all over the wheel which is a bit messy. I'm guessing there is another way of adding decal within a texture using specialized shaders or something? Secondly is blending, no experience of this but again am guessing it it's a larger map that can be placed over the diffuse again using specialized shader options? Is there a shader that most max users use? I'm currently using Lumonix and Advance Software shaders.
  • Eric Chadwick
    Nope, don't overlap UV2 if it's going to be used to bake a lightmap. Except if you know for certain the faces are always going to be lit the same, then you can overlay them. However it's best to move all the overlapping bits, except one of them, exactly 1 UV unit out of the 0-1 UV box, so all those overlapping faces don't cause light-baking errors.

    Yeah you can use 2 color maps, depends on the shader. Pretty sure Shader FX can do this easily. Just multiply the detail map with the regular color map, both using UV1. Each wheel would need its own shader though, so you can setup different offsets for the detail map. So you could pack four wheel detailmaps into one.

    Edit.. a cheaper way to add variations is to use vertex color instead. Less texture mem, but also less sexy.
  • capone
    Offline / Send Message
    capone polycounter lvl 18
    This sounds like you're imagining me to just overlay random colour/details from my detail map over the mesh if you're talking about offsetting it? Remember there is only 1 wheel UV in UV channel 1, so if I add colour/details to the wheel in the detail map I can't offset it?

    Does anyone have any examples of a typical flat detail map?
  • Eric Chadwick
    Here's a typical use of a detail map, to add tiny details that are tiled like crazy across a large surface.
    http://www.cafu.de/wiki/textures:perfect_detail_maps
    I don't agree with the results that programmer gets, too washed out, but it does show detail maps in action. UDK has an example too somewhere, couldn't find it though.

    I assumed you wanted specific overlays, not a random low-frequency tiled texture. In that case I would approach it like a lightmap, packing each wheel's decal/overlay into its own quarter of the detailmap. Then I'd use offsets in the shader to show just the 1/4 of the detailmap that I wanted, for each wheel.
  • capone
    Offline / Send Message
    capone polycounter lvl 18
    Thanks Eric, yeah wanting to do specific overlays. So if you make an extra detail map why not then just map it all to a unique set of UV2's? Instead of going to every element and offsetting it trying to find the right bit of texture? The budget is the same.
  • Eric Chadwick
    Well, actually every additional UV channel you add will increase the vertex count for the model, which will increase how much room it takes up in memory. Using four materials (for the different offsets) takes less memory than duplicating all those UV verts.

    As mentioned though there are many different approaches. Floating decals is one approach, vertex color is another, vertex blending between two textures is another, using an overall detailmap is another, etc.

    This is for a portfolio piece, right? I would then choose the method that is the most visually pleasing, without being technically wrong (like it would be if you packed four unique wheels in a single 2048 or something).
  • capone
    Offline / Send Message
    capone polycounter lvl 18
    Whenever I see example of vertex colour/blending it's always used as a sort of gradient. As for decals I'm convinced floating decals would be too messy and add 100+ tri for what I'm wanting. It's good for flat surfaces but it gets awkward when they have to wrap around cylinders etc

    So if painting to UV2 is out of the question I'm not quite sure what the solution is. Shame because that's the only way you can paint while knowing where it's going to display. Have to say, I have never heard about massive memory increase with 2 UV's. All of the three engines I have used could handle them and it wasn't an issue at all.

    I'll try and find more info on this, would be great if this could be cleared up.
  • Eric Chadwick
    If it's a portfolio piece, not an actual shipping-game asset, then just go for it. use whatever methods you want. The finished look of the art is like 90% of what people will judge it by, only like 10% of the judging is the technical side (depending on the employer).

    Someone on your dev team is going to be the gatekeeper for perf issues, they'll tell you if your model is too bloated.
Sign In or Register to comment.