Bake materials
API function: algo.bakeMaps
Use this feature as part of your mesh optimization process to transfer mesh and materials information to texture maps.
Usecase
Usually, you would use this function in two scenarios:
- Auto baking: optimize a set of meshes with different materials into one or multiple meshes with one material (see
Algo::CombineMaterials
)- Create UVs, tangents and normals (optional if they already exist)
- Repack UVs
- Normalize UVs
- Bake Maps
- Create a material with generated textures
- Merge meshes (optional)
- Assign the created material
Tip
Copy your original UVs in an empty channel if you don't want them to be overrided.
- LOD baking: bake mesh and material information from a high detailed LOD and assign created textures to a low detailed LOD.
- Duplicate LOD0 occurrences
- Generate LOD1 (decimation, proxy mesh, ...)
- Create tangents on LOD0 (optional if they already exist)
- Create UVs, tangents and normals on LOD1 (optional if they already exist)
- Repack UVs (LOD1)
- Bake Maps (source: LOD0, destination: LOD1)
- Create a material with generated textures
- Assign the created material to LOD1
This example shows a model with many curved surfaces. After baking, the triangle count is reduced from 40,000 to 8,000:
This example shows a model with many flat surfaces. After baking, the triangle count is reduced from 20,000 to 278:
Subsequently, you can use these maps to transfer information back to optimized assets.
Parameters
Method
When source and destination are different, the function tries to find the destination's (lowpoly) texel's corresponding position on the source (highpoly). To do so, several approaches are possible:
- Ray only: shoots a ray from the destination position along the normal vector. Bake the information from the intersection of the ray and the source. Fastest.
- Proj only: finds the nearest position (shortest distance) from source to destination. Slower than ray-only.
- Ray and proj: shoots a ray alon the normal vector and projects if it does not intersects.
Maps
Maps of various types are used for baking.
Diffuse map
This map defines the base colors of the 3D model.
This map is also referred to as the albedo map.
Normals map
This map defines the map of normals for a material, in tangent or object space.
The color of each pixel in this map represents a direction.
Opacity map
This map defines the transparency of a material.
This map is also referred to as the transparency map.
Roughness map
This map controls how rough or smooth the surface of a material appears.
Metallic map
This map determines how metal-like a surface is.
Ambient Occlusion map
This map provides information about which areas of the model should receive high or low indirect lighting.
Indirect lighting comes from ambient lighting and reflections. For example, the steep concave parts of your model, such as a crack or a fold, don't realistically receive much indirect light.