# ExportBasemapDiffuseTexture

### Export Basemap Diffuse Texture

```csharp
Texture2D ExportBasemapDiffuseTexture(int resolution, bool saveHolesmapInAlphaChannel, bool enableHeightBasedBlend = false, float heightTransition = 0)
```

Bakes all terrain paint textures Diffuse maps into one Basemap texture.

*<mark style="color:blue;">saveHolesmapInAlphaChannel</mark>* - If set to **true**, texture's alpha channel will contain holesmap's cutout values.&#x20;

By default [TerrainData](https://docs.unity3d.com/ScriptReference/TerrainData.html) object doesn't use **Height Based Blend** feature. This is optional feature for the terrain material and if converted terrain uses it, it needs to be manually set inside **ExportBasemapDiffuseTexture** method:

<div align="left"><figure><img src="https://1477282451-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIJi2f6hCjtiGR5oUl9gw%2Fuploads%2FA5rC2RZftKVVbgagmMjm%2Fheight_based_blend.png?alt=media&#x26;token=1757e13e-8182-4ebe-b6fb-39b214e6127b" alt="" width="424"><figcaption></figcaption></figure></div>

{% hint style="info" %}
Material's height based blend values can be read using **Terrain.GetMaterialHeightBasedBlendValues** method.
{% endhint %}

***

```csharp
Texture2D[] ExportBasemapDiffuseTexture(int resolution, bool saveHolesmapInAlphaChannel, int splitCountHorizontal, int splitCountVertical, bool enableHeightBasedBlend = false, float heightTransition = 0)
```

Splits terrain into 2D grid by *<mark style="color:blue;">splitCountHorizontal</mark>* and *<mark style="color:blue;">splitCountVertical</mark>* amount and for each chunk calculates BasemapDiffuse texture.

This method can be used in combination with multi-chunk mesh exporter, in this case index of a mesh in 2D grid array and Basemap texture's, are the same.

```csharp
//Example of generating multi-chunk meshes (8x8 grid) with UVs per chunk and
//exporting Basemap Diffuse textures for each one. 

bool calculateUVsPerChunck = true;
int vertexCount = 100;
int textureResolution = 2048;
int splitCountHorizontal = 8;
int splitCountVertical = 8;

Mesh[] meshes = terrainData.TerrainToMesh().ExportMesh(vertexCount, vertexCount, splitCountHorizontal, splitCountVertical, calculateUVsPerChunck);
Texture2D[] diffuseMaps = terrainData.TerrainToMesh().ExportBasemapDiffuseTexture(textureResolution, false, splitCountHorizontal, splitCountVertical);

for(int i = 0; i < meshes.Length; i++)
{
    GameObject go = new GameObject();

    //Assign generated terrain mesh
    go.AddComponent<MeshFilter>().sharedMesh = meshes[i];


    //Creating material using default shader
    Material material = new Material(TerrainToMeshUtilities.GetDefaultShader());

    //Setting up material to use diffuse texture
    TerrainToMeshUtilities.SetupDefaultMaterial(material, diffuseMaps[i], false, null, null, null);


    //Assign material
    go.AddComponent<MeshRenderer>().sharedMaterial = material;
}
```

***

```csharp
Texture2D ExportBasemapDiffuseTexture(int resolution, bool saveHolesmapInAlphaChannel, int splitCountHorizontal, int splitCountVertical, int splitColumnIndex, int splitRowIndex, bool enableHeightBasedBlend = false, float heightTransition = 0)
```

Splits terrain into 2D grid by *<mark style="color:blue;">splitCountHorizontal</mark>* and *<mark style="color:blue;">splitCountVertical</mark>* amount and calculates BasemapDiffuse texture for chunk with index *<mark style="color:blue;">splitColumnIndex</mark>* and *<mark style="color:blue;">splitRowIndex</mark>*.

{% hint style="warning" %}
If texture exporter methods are used in the run-time builds, make sure <mark style="color:red;">**Terrain Textures Exporter**</mark> shader is inside **Always Included Shaders** array of the [Graphics Settings](https://docs.unity3d.com/Manual/class-GraphicsSettings.html)
{% endhint %}

<div align="left"><figure><img src="https://1477282451-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIJi2f6hCjtiGR5oUl9gw%2Fuploads%2FGt8GjjYsaDwmlpGSwP3c%2FAlways_Included_Shaders.png?alt=media&#x26;token=62374a3e-9ef7-45ae-9713-b00194946682" alt=""><figcaption></figcaption></figure></div>
