XaiJu
Kruithne
Kruithne

patreon


WoW 3D: Texture Baking

Chapter 1: Introduction

When creating or importing models, especially buildings, it's common to use a wide range of materials and textures, rather than just one that maps over the entire model, with floors, ceilings, walls and more all using different textures.

Take this world/wmo/azeroth/buildings/castle/castle01.wmo for example exported from wow.export, it uses eleven different textures.

This works great for the game when players are up close, as multiple buildings all sharing the same textures can use much less VRAM, load quicker, and provides much higher visual quality.

There are some scenarios however when you don't want to have eleven separate textures for a building. A primary example of this is when a building is far off in the distance in a game, it's wasteful to be loading all the textures, but we still want to be able to see it.

For this, games (and often other large scale rendering solutions) will use something called Level of Detail (LOD), where the fidelity of geometry and textures for far away objects is reduced.

In this guide, we're just going to be focused on the texture side of things. Rather than rendering the model with all of its textures, LOD models bake all of the textures onto a single image.

In the above example, the LOD texture used is only 256x256. This dramatically reduces the quality, but at a distance it's often impossible to tell anything changed.

In addition to creating LOD models for optimizing distant assets, texture baking like this can also be used to create low-poly versions of buildings to use as smaller props.

Let's say you wanted to put Dalaran City in a snow globe, you absolutely wouldn't want to shrink the entire WMO itself and stick it in, that would be a nightmare. Instead, you would create a tiny version of the model with a baked, low-res texture.

Some other use cases may include exporting models to applications that only support one texture, such as Tabletop Simulator, or baking results of shaders and lighting for use in other applications.

Regardless of your use case, let's start baking! As with all of my guides, I'll be using Blender since it's free and open-source.

Chapter 2: Baking

Before we start, we need is a model. For this example, I'm going to be using the world/wmo/azeroth/buildings/castle/castle01.wmo exported from wow.export.

Since the end result is that our model will only have one texture, we need to arrange how everything will fit into a single image like a giant jigsaw puzzle.

Thankfully, Blender can do this automatically for us using the Smart UV Project feature. Let's start by adding a new UV map to the object.

With the object selected, switch to Edit Mode. Make sure you have the new UV map selected. Ensure everything is selected (A) and then run Smart UV Project (UVSmart UV Project).

A small modal window will pop-up. The only setting you'll likely need to change from defauls is Correct Aspect, disable this, then go ahead and press OK.

If you're running this on a large model, it might take some time to complete. Blender may even become unresponsive, just give it some time to resolve.

Once done, if you switch to the UV Editor panel, you should see that our newly created UV maps the entire model neatly without any overlap.

The next thing we need to do is create a new material on our object. To do this, switch back to Object Mode and open up the Material Properties tab.

Add a new material slot to the object and then click the New button with the empty slot selected.

The name of the material doesn't matter, so for this example I'll just call it mat_bake. Turn out focus to the Shader Editor panel and add an Image Texture (Add TextureImage Texture) node to the material.

Contrary to what you might be expecting, you do not want to connect the Image Texture node to anything. Just leave it disconnected by itself.

Click the New button on the Image Texture node. Uncheck Alpha and set the Width/Height to the dimensions of your preference, which will vary depending on what you intend to use it for.

Remember, the smaller the dimensions, the lower quality the end result (which may be the intention here). Additionally, it's best to use powers of two for your dimensions (256, 512, 1024, etc).

Select the Image Texture node and copy it (CTRL + C). Now you need to go through all of the other materials on your object and paste the node (CTRL + V) into it.

Additionally, you need to make sure that in every material, the node is not connected to anything and is the only node selected.

Why are we doing this? When we bake the model, Blender is going to bake every material to the active node in the shader. If we don't add this node which references the image we created, or we have something else selected, it will bake to the wrong image.

Before we run the bake, make sure that you have both the new UV and the new material we created both selected in their respective lists.

In the Render Properties tab, scroll down to the Bake section and hit the big button that says Bake.

Once it's finished baking, switch to the Image Editor panel and switch to the bake image. The name of the image will be whatever we entered when we specified the image dimensions, in this instance, it's called "Bake".

It worked! The only issue is that it's super dark. As I mentioned earlier, this method also bakes the lighting as well. If you don't want to include the lighting, switch the Bake Type to Diffuse and then uncheck Direct/Indirect under Contributions.

Your model should now be baked to a single image without any influence from the scene lighting. You can go ahead and save the image somewhere from the Image Editor panel if necessary.

Finally, we need to convert our model to use this new baked image. To do this, start by deleting every material apart from the bake one we added.

Additionally, go ahead and connect the Image Texture node to your Principled BSDF node in the shader for the bake material as well.

Finally, our model is still using the original UV map. Go ahead and delete the original UV map, using our new bake UV instead.

If everything went to plan, our model is now successfully baked to a single texture file, ready to use or export for whatever purpose you needed this for.

Did that seem a bit too much like hard work? Check out the next chapter for a macro that automates the entire process into one button.


Chapter 3: Transparency

In some scenarios, the object we're baking, such as this tournament_banner_be02 exported from wow.export, may include transparency, which is lost when baking.

To resolve this, we need to make another map that is just for the alpha channel.

Start by going over your materials and anywhere that you use transparency, instead mix together a black and white Diffuse BSDF node, using the alpha channel as the factor.

For materials that don't have any transparency, simply replace them with a plain white Diffuse BSDF node.

The end result is that your model should be completely white aside from the parts that need to be transparent, which should be completely black.

Go ahead and bake your model just as we did before, with the end result being a black and white alpha map for your model. Save this as a separate texture, so you should now have a diffuse texture and an alpha texture.

Depending on your end use-case, having the alpha as a separate mask texture may be beneficial, but for most scenarios you'll want it included as the alpha channel of the texture itself.

This can be done in most photo editing software, but I'll be using Photoshop. To start, load the diffuse texture into your photo editing software of choice and add a new Layer Mask to it.

Enter the editing mode for the layer mask (Alt + Click in Photoshop) and then paste in the black/white mask we created.

Exit the mask editing mode, and you should now find that your image has transparency. Go ahead and save that as a PNG (or your desired alpha-supporting format), and you're done!


Chapter 4: Automation

The best things are done with a single button, so as with most of my guides, here's an easy to use Python macro that does everything we just discussed in a single click.

Macrohttps://gist.github.com/Kruithne/88bbe2935b50c4a2e63ed5c44bb03a7c  

If you're not familiar with how these macros work, check out my recent guide on quickly creating Python macros in Blender.

Using the macro is as simple as selecting the object and running it. By default, it will not use lighting and bake to a 256x256 image.

You can adjust the settings easily by just changing the bake_resolution and include_lighting properties at the top of the macro.

Transparency, as covered in Chapter 3, is also handled automatically and can be controlled by the bake_alpha_mask and channel_pack_alpha_mask properties at the top of the macro.

If bake_alpha_mask is set to True, all materials on the object will be temporarily swapped with a black/white mask, and then baked to an internal image which is linked in the final bake material and can be saved separately.

In addition, if channel_pack_alpha_mask is set to True, the alpha mask is written directly to the alpha channel of the diffuse texture, rather than being included as a separate image, allowing it to be saved as a single image with transparency.


Chapter 4: Conclusion

That's about everything for this guide. Hopefully even if you don't have an applicable use for this technique, perhaps you learnt something new.

I sometimes use this method (along with the decimate modifier) to produce low-poly versions of buildings in backgrounds of heavy scenes.

Additionally, I also use this as a way to easily create single-texture assets compatible with Tabletop Simulator that we use in my D&D group.

On that subject, I have another guide coming very soon that delves into all kinds of good stuff about using WoW assets in Tabletop Simulator, so stay tuned if that interests you.

That's it for now! As always, if you have any problems or questions with this guide, wow.export or Blender in general, feel free to ping me in the #champions-lounge channel on my Discord.

WoW 3D: Texture Baking

More Creators