# TextureBaker

Compatibility: <mark style="color:green;">URP</mark>, [<mark style="color:yellow;">HDRP</mark>](#user-content-fn-1)[^1], [<mark style="color:yellow;">STANDARD</mark>](#user-content-fn-1)[^1], [<mark style="color:red;">IN-EDITOR-BAKING</mark>](#user-content-fn-2)[^2]

The TextureBaker is a powerful tool designed to streamline the process of creating texture atlases and combining materials into a single material. By consolidating textures and materials, the TextureBaker helps optimize rendering performance and reduce draw calls in your Unity projects.

## How to Enable Texture Baker

The Texture Baker feature is disabled by default and needs to be manually enabled in your project settings. Follow these steps to enable the Texture Baker:

* Navigate to the directory: `/TeoGames/Mesh Combiner/Settings/Resources/`
* Locate the `URP Texture Baker` scriptable object.
* Add the `URP Texture Baker` scriptable object to your Baker Settings: [#step-2-register-your-baker](..#step-2-register-your-baker "mention")
* Make sure that material baking is enabled on combiner: [#bake-materials](../../combiner/mc-mesh-combiner#bake-materials "mention").

Here is example how baker setting may looks like when it's configured:

<figure><img src="https://2346867356-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJpXGyndvcGe1bSLCt3Yt%2Fuploads%2FbKXPOO9wqZ2jIrksQgds%2Fimage.png?alt=media&#x26;token=61a29c1e-5bdc-4c3d-bd82-0cd72eb3c2ea" alt=""><figcaption></figcaption></figure>

## Default compatibility

### Texture Configurations:

* **Base Map:** Represents the main color texture.
* **Normal Map:** Contains surface normal information for advanced lighting effects.
* **Emission Map:** Specifies emissive areas of the material, emitting light in the scene.
* **Metallic Map:** Defines the metallic properties of the material.

### Shader Compatibility:

* URP Lit
* URP Simple Lit
* URP Unlit

## Configuration Options

The URP Texture Baker comes with default configurations tailored to work with specific textures and shaders. However, you have the flexibility to customize these configurations according to your project requirements. Here are the key configuration options available:

### Opaque Material

Used for rendering solid objects that do not transmit light. Materials with a render queue value less than 3000 are selected for baking.

### Transparent Material

Used for rendering objects that transmit light or have semi-transparent properties.

### Textures

A list of textures that will contain the output material. These textures will be assigned to the output material.

Each entity in the Textures list has the following fields:

* **Texture Name:** The property name in the output shader where the texture will be assigned.
* **Format:** The texture format.
* **Liner:** Indicates whether the texture uses linear color space
* **Default Color:** Specifies the default color of the texture. This color will be used if the source material doesn't have a texture.
* **Is Diffuse Texture:** Indicates whether the texture is a diffuse texture. Only one texture should be checked. _Note: Material will not be baked if there is no default texture on it._
* **Filter Mode**_:_ Determines the texture filtering mode
* **Keywords:** Specifies keywords that will be enabled if the texture is used

### Shaders

A list of shaders that will be accepted by the material baker. If a source material is based on one of the specified shaders, it's properties will be used to map the source material properties to the output material.

Each entity in the Shaders list has the following fields:

* **Shader:** The source shader.
* **Properties:** A list of mappings from the source shader to the target shader.
  * **Texture Name:** The target shader's texture name, which should correspond to one of the [#textures](#textures "mention") entities.
  * **Property Name:** The source shader's property name.

### Output Size

Specifies the size of the output texture (e.g., 1024x1024, 512x512, etc.)

### Max Texture Size:

Specifies the maximum size of the input texture. Input textures larger than this size will be downscaled to match this value.

### Keywords

Specifies keywords that will be enabled on the output material in any case.&#x20;

## How it Works?

The Texture Baker functionality operates through a series of steps to efficiently combine materials and create texture atlases. Here's how it works:

1. Input Material Check. The Texture Baker first checks each input material to ensure it meets specific conditions:
   * It should use one of the specified shaders.
   * It should have a default texture assigned.
2. Baking Process:
   * Once the input materials pass the validation checks, the Texture Baker proceeds to scale and bake all configured input textures into output textures.
   * Each input texture is scaled and positioned uniformly within the output texture, ensuring consistency in size and placement across all textures.
   * After the baking process is complete, each source material is replaced with the generated material containing the baked textures.
3. Atlas Management:
   * As textures are baked into the output texture, the Texture Baker monitors the atlas space usage.
   * When the output texture reaches full capacity, the Texture Baker automatically creates a new atlas to accommodate additional textures.
   * This automatic atlas creation ensures efficient use of texture space and prevents texture overflow.

## Known limitations

The experimental nature of the Texture Baker feature entails several known limitations that users should be aware of. Here are some of the identified limitations:

* **Tiling and Offset Not Supported:** Currently, the Texture Baker does not support tiling and offset functionality. Users should refrain from relying on tiling and offset configurations when using the Texture Baker.
* **Inability to Handle UVs Larger than 1:** The Texture Baker is not equipped to handle UV mappings larger than 1. Users should ensure that UV mappings for textures do not exceed the boundaries of 1 to avoid unexpected behavior.

**Note:**

* Users should exercise caution and thoroughly test their projects when utilizing the Texture Baker feature, as it may exhibit unexpected behavior due to its experimental status.
* Feedback on encountered limitations and issues is valuable for improving and refining the Texture Baker functionality in future updates.



[^1]: Not supported out of the box, but can be configured

[^2]: In editor baking is not supported and may give unexpected results.
