Mesh Baker by Digital Opus [RELEASED]

Yes, it is very easy to re-use combined materials for different mesh bakes. You probably only need to bake the materials once.

The Texture Bake generates a ScriptableObject asset called the Texture Bake Result. This is all that each Mesh Baker needs.

You can bake the textures in one scene and then MeshBake the meshes in another scene by assigning the Texture Bake Result to the MeshBaker:

Another way to have multiple Mesh Bakers share a single texture bake is to organize them in the hierarchy so that there are multiple mesh baker children of a single texture baker:

thanks for the detailed explanation! I’ll give it a try and let you know if I have more questions.

Hello. I have a Kitbash Cargo object I’d like to optimize to use in a traffic system that would duplicate and move this object at runtime.
Is it possible to add MeshBaker within a prefab?
GameObject - Create Other - MeshBaker - Texture and Meshbaker doesn’t create a node inside the prefab.

I add meshbaker/texturebaker to prefabs all the time. Just make an empty game-object in the prefab and then in the inspector add a script for MB3_Texture_Baker. For every separate mesh you want add a MB3_Mesh_Baker script. Note that the batch-prefab baker requires a scene, so it won’t work, but the other ones do work.

1 Like

Three way to add Mesh Bakers and Texture Bakers to prefabs:

  1. Drag the scripts “MB3_MeshBaker” or “MB3_TextureBaker” from the project onto a game object in your prefab. Then SciptContextMenu → Added Component → Apply To Prefab

  2. Use the “Add Component” button in the inspector window for a game object in your prefab. Then Then SciptContextMenu → Added Component → Apply To Prefab

  3. Use GameObject - Create Other - MeshBaker - Texture and Meshbaker to create a Mesh Baker and Texture Baker in the scene. Drag this game object into your prefab instance hierarchy. Right click on the added game object in the hierarchy window. Added Game Object → Apply To Prefab

I should also add that everything referenced by the MeshBaker and TextuerBaker needs to be either an asset in the project folder or something inside the prefab. This includes: the combined mesh, source objects, materials, texture bake result. Note that the combined mesh will only exist in the scene if you use “output → bake into scene object”. You will need to use “output bake into prefab” or manually drag a mesh asset from your project into the MeshBaker’s mesh slot for this to work.

I’m trying to bake together Skinned Mesh Renderer characters that use a custom shader made in shader graph. The properties on the shader that are exposed to inspector vary from mesh to mesh, meaning I have to make a Custom Texture Blender script to get them to bake properly.

Unfortunately, I’m not really sure how to go about this. Your “Blend Non-Texture Properties” tutorial only seems to scratch the surface about it. It references to an “advanced tutorial” about the topic that’s supposed to be linked in the description but is not.

I was wondering if this tutorial is currently available anywhere, or if you’re able to give me some insight on how I can go about solving this. Most of the custom shader properties are floats, and there’s a couple colors as well.

This is a very hard problem to solve: “The properties on the shader that are exposed to inspector vary from mesh to mesh”. When these meshes are combined it is difficult to have a single material that works for the entire mesh.

I don’t know the details of your problem but the Blend Non Texture Properties may not be enough. That feature works well with texture-proprties that have a matching non-texture-property and the shader blends the two. Like albedo-texture and color-tint. It sounds like your shader has some float properties that act like switches that turn on and off features in the shader. Is this correct? If so then this behaviour will be difficult or impossible to implement using a TextureBlender.

Can you modify your shader so that these “switches” are driven by texture properties instead of float properties? For example if you have three float properties: feature1, feature2, feature3, then you could read these values instead from a new texture property: texFeature_r1_g2_b3 (red channel is feature1, blue channel is feature2, green channel is feature3). The texture can be very small 16x16 and each channel might be a solid color. This new texture property can be “atlased” so that when the materials are combined, the different parts of the mesh use different UV rectangles of the texFeature_r1_g2_b3 atlas.

Another solution might be to use mesh colors in a similar way. You can write four floats into the meshes colors r,g,b,a channels for each vertex. When these meshes are combined the data in the colors channel is still there.

Let me know if this helps.

That makes sense. Most of the shader properties are floats that dictate intensity. For example, the shader has a Fresnel effect in which the intensity/strength can be changed via a float. Some are clamped to 0-1 ranges, some are not.

The shaders are made by an artist I work with who works entirely in Shader Graph and doesn’t have much of a background in understanding the math behind his shaders. So often I’m left with parameters that are unclamped or that I don’t necessarily know exactly what they’re doing under the hood.

This seems like it’s more trouble than it’s worth, or downright impossible as you noted. I’ve decided to find which meshes have similar values and just make them the same, the difference is negligible in these cases. In cases where they’re not similar, I’ll bake those with other meshes that I find with similar values. Then I’m able to use your TextureBlenderURPLit as reference to blend stuff like Smoothness for Metallic/Specular and Color for albedo in a new script.

Which I think is fine. It’s 4 characters with submeshes for clothing and the skinned mesh renderer count adds up to 30. Aiming to combine them all in to 1 was probably a little overzealous :stuck_out_tongue:. Getting it from 30 to 2-4 is still a big win!

Thanks for the insight!

Hello:

Why TexureBaker and MeshBaker miss materials?

Do I miss something?

Thanks.

Can you describe your situation in more detail? What version of Unity are you using? What is your target platform? Which Render Pipeline? Which shaders? Also I would suggest starting simple and adding complexity. For example start with combining two props. Add the props to the Texture Baker and bake. Check the console for error messages. Were atlases generated? If so do they look correct? Does the combined material look correct? If everything looks correct then try to bake the meshes. Also if you haven’t already I would suggest watching the first few tutorials. https://youtube.com/playlist?list=PLCzm-udM-shncdtvrieqgi-hHDU1kt0d4&si=ut0aD4rprwbl1Hs5

I just followed the turorial videos to TextureBaker And MeshBaker, my unity and pipline is : 2022.3.50f1 URP.

Atlas is generated, it seems normal.

I will check the video about TextureBaker And Meshbaker again tonight. It I mis something I will record it.
Thanks.

What is the shader on the combined material(s)? If the shader is not a URP shader (the Standard shader for example) then you will get pink materials like this. Is the shader the same one that the source materials are using?