Quick Start
In this quick start chapter is explained how Vertex Forge's editor tool works and is provided simple examples demonstrating how to bake:
Material's diffuse textures into a mesh.
Combine and optimize generated meshes.
Bake lightmaps into a mesh.
For this chapter we will use the free Low Poly Dungeons Lite asset by JustCreate. After downloading and importing package, open example scene.

Texture2D Baking
For the first example we will bake diffuse maps into a mesh from materials they are using and render result using the simple vertex color shader.
Open Shader Forge editor window from the Main Toolbar → Window → Amazing Assets menu:

Select Dungeons gameObject in the Hierarchy window and drag and drop it inside VF editor window:


List of objects suitable for texture baking will be displayed in the conversion list.
For baking texture into selected meshes, inside Solver group click on the Property Name drop down menu and choose the _MainTex. This is the texture's property name defined inside shader and used by mesh materials for Diffuse/Albedo rendering.
Vertex Forge reads texture from material using this property name and bakes it inside a mesh:

Texture property names listed in this menu depends on the shaders used by objects in the conversion list and it may differ based on the used render pipeline. Choose texture property name that is used by the Diffuse/Albedo map rendering by materials.
If using Standard shader in Built-in RP, then diffuse texture's property name is: _MainTex For Lit shader of URP it is: _BaseMap For Lit shader of HDRP it is: _BaseColorMap
After choosing texture's property name, conversion list will display if materials used by selected objects have such texture property:

Now, click on the Run button at the bottom of the editor window.
The editor tool will generate new meshes with texture baked inside (per vertex) for all objects in the conversion list, replace all initial meshes inside MeshFilter and SkinnedMeshRenderer components with their newly generated duplicate meshes and new material in the Renderer components. Based on all those actions new prefab asset file will be created and instantiated in the scene, in the same position as the source object.

Now all meshes in the scene are rendered without any diffuse textures, using just one material.
VF package included Preview shader (used by generated prefab) is Unlit type and is designed to display baked data from any mesh vertex buffer. For this example, textures are baked inside vertex color:

Vertex Forge tool allows baking textures inside any mesh vertex buffer and package includes Preview shader for rendering this baked data. However it is up to the user to create and setup custom shaders for reading this baked data from a mesh and render it according to the requirements.
Mesh Combine
Instead of generating multiple meshes, VF editor tool can combine all meshes inside object hierarchy into one mesh and such way only one draw call will be used for their rendering.
Inside Generate group select Combine Everything and click on the Run button again:

Now instead of generating and rendering 49 meshes, only 1 mesh will be generated and entire scene will be rendered using by one mesh, one material and one draw call.
Mesh Optimize
Using the right click Context Menu → Highlight Last Saved File option, navigates Projects window to the folder where generated files are saved. It should contain mesh, material and prefab asset files:


Those are all files used by rendering current example scene. No other materials or textures are used and total size of those assets should be about 1.66 MB. It is possible to optimize meshes and reduce generated files size.
One way is to set Mesh Compression to the High value (not recommended), but the better options is to remove unwanted and unused vertex attributes from the generated mesh:

Generated mesh inherits all vertex attributes from the source mesh, and some of them may not be needed any more, for example, UV0 is used for texture sampling inside shader and as mesh already has baked texture inside, then there is no need to keep this attribute. Same as tangent, it is used in shaders for Normal/Bump effect rendering and if generated mesh doesn't need such effect then tangent attribute can be removed too:

Inside Save group Select Attributes drop-down menu, disable Default checkbox there (this enables to manually choose mesh attributes) and remove checkbox for the UV0 and Tangent:

Click on the Run button and check generate asset files size, it should be about 40% less:

If meshes will be rendered only with Unlit vertex color shaders, then all attributes can be removed except Color, this reduces generated file size even more.
Be cautious when removing attributes from a mesh, ensure they are never needed!
Lightmap Baking
Now we will bake textures and ligthmaps together inside mesh. Do not close VF editor window.
Delete generated Dungeons prefab from the scene. After that select original Dungeons gameObject and set it Static editor flag and all scene lights to be Baked. After that bake scene lightmaps.


Inside VF editor window click on the Add button and select Lightmap (Color):

Solver group now will contain Texture2D and LM Color baking properties:

Click on the Run button. Texture2D and Lightmap data will be baked inside mesh vertex color:

The result will not be exactly what is expected, as only Lightmap got baked. The reason is the Merge Mode option of the baking data, as is set to Replace for both texture bakers:

Merge Mode option defines how generated data is blend with the already existed data inside saved vertex buffer. In this example, first is baked Texture2D and it is saved inside vertex color buffer. After that is baked Lightmap and it also is baked inside the same vertex color buffer, replacing already existing data there.
We need to multiple Lightmap with already baked Texture2D data inside vertex color buffer. Change Merge Mode option for Lightmap to Multiply and after that click on the Run button:

If everything is done correctly, then generated mesh should have diffuse maps from material and scene lightmaps baked inside vertex color buffer.

While everything is done correctly, there is a little 'artifact' on the floor mesh. It is because that Vertex Forge reads texture coordinates (for baking) per vertex and if there is even a little difference in pixel colors of two neighbor vertices, than after baking their mesh faces will have different colors and create unpleasant result, as if textures are not correctly baked there.
Hide generated Dungeons prefab and have a close look at the center of the floor where four meshes creating the floor met.
In this corner each mesh vertex has a slightly different ligthmap color values. The similar differences are on other corners of those meshes too, and after baking this creates a look of incorrect texture baking. The solution in this case would be replacing problematic floor meshes with one Plane mesh and after that re-baking scene lightmaps:


And here is a result of how baking textures and lightmaps produces good quality result when using correct and appropriate meshes:

Before finishing this chapter, it is a need to mention that baking all kind of textures and maps inside mesh vertex color is not the best option. Note, that Unity compress and clamps values inside mesh vertex color buffer to [0, 1] range and as a result HDR and negative values, same as directional vectors should not be saved here. Also color buffer is affected by color space conversion.
Result of mesh vertex color buffer compression is visible only after reloading Unity Editor. Bellow is an example of how lightmaps baked inside vertex color are clamped by Unity:

All mesh vertex buffers: UV0 - UV7, normal and tangent (except vertex color) can store HDR and negative values, including directional vectors and are not affected by color space conversion.
So, for our example Dungeon scene proper place for storing lightmaps could be any vertex buffer, for example UV3 (or any other) and then use custom shader to manually blend baked diffuse map and lightmap values there:

Last updated