Is it possible to export terrain splat maps?

Is it possible to export terrain splat maps to an image format that I can open up in Photoshop? If so, how can this be done?

Thanks

You can modify them through script. You need to drag them from the terrain asset to the script in the editor. Then you can save it, modify it or replace it.

Can you be more specific? I see the terrain asset with the splat maps in them. Where do I drag them? What script are you talking about? Thanks.

This code should save a png file to you projectfolder (parent of the assets folder).
Then you can modify it in Photoshop. The script can also replace an existing texture. Probably used when you want to view the changes you have done to the texture in Photoshop.
Drag the splatmap to the splat variable.
Warning: This code is not tested and I don’t know if it will compile correctly, but if not, it will probably be a small error.

var splat : Texture2D;
var from : Texture2D;
function save (tex : Texture2D) {
	var bytes = tex.EncodeToPNG();
	File.WriteAllBytes(Application.dataPath + "/../splatmap.png", bytes);
}

function Replace (tex : Texture2d, from : Texture2D) {
	tex.Resize (from.width, from.height, from.format, true);
	pixels = from.GetPixels (0);
	tex.SetPixels (pixels);
	tex.Apply;
}

Thanks man. I was able to save it out. This is my test code.

function Awake() {
	
	try {
	 
	   var bw : BinaryWriter = new BinaryWriter(File.Open("splatmap.png", FileMode.Create));
	   var pngBytes = splat.EncodeToPNG();
	   bw.Write(pngBytes);
	  
	   bw.Close();
	   
	}
	catch (err) {
		 Debug.Log("Save Error");
	}  
}

One more code example for export terrain splat texture from Assets menu. Realy you can export ordinary textures also if needs.

How to use:

  1. Place this script on Assets\Editor dir in your project dir, call it like Export_texture.js or what ever you prefer.

  2. Click on texture for export in Project tab

  3. Go Assets / Export Texture menu

  4. File with texture appear in Assets dir with name exported_texture.png, you can change it in script body.

// For save splatmap as PNG file.
import System.IO;

@MenuItem("Assets/Export Texture")

static function Apply () {
   
   var texture : Texture2D = Selection.activeObject as Texture2D;
   if (texture == null)
   {
      EditorUtility.DisplayDialog("Select Texture", "You Must Select a Texture first!", "Ok");
      return;
   }
   
   var bytes = texture.EncodeToPNG();
   File.WriteAllBytes(Application.dataPath + "/exported_texture.png", bytes);
}
1 Like

great. really helped me. thx

I have exported the splats but when I open them in photoshop and save them, it breaks the file. Is there any solution for this? I think it’s because of the alpha…

KEMBL, I am stuck. I can’t find where the splatmap is so I can’t select it and therefore I can’t use your script to export it. Can you please tell me where the default location is to find the splatmap in Unity 4.2? Thanks.

Hi,
I just bought this, looks great.

Dumb question:
The main reason I bought it was to get rid of the ugly terrain tiling issue with some landscapes I bought from the asset store using default unity shader. I’ve run through the doc, converted the splat maps from existing terrain, and did the texture blending color and generated a new material.

But…still getting ugly texture tiling artifacts.
Can’t see anything specific for this issue in the manual (maybe I missed it)

Is there a simple process for doing this?

I gather it’s the Multi UV Mixing but playing with the settings doesn’t seen to do anything.
I have to recreate the material each time right?

Comletly useless and brocken scipts, use this instead Dropbox - File Deleted - Simplify your life

For reference, if you need to select a terrain and export all alphamaps as PNG, here’s how to do it:

using System.IO;
using UnityEditor;
using UnityEngine;

public class ExportSplatmap : MonoBehaviour
{
    [MenuItem("Terrain/Export Splatmap...")]
    static void Export()
    {
        Terrain terrain = Selection.activeObject as Terrain;
        if (!terrain)
        {
            terrain = Terrain.activeTerrain;
            if (!terrain)
            {
                Debug.Log("Could not find any terrain. Please select or create a terrain first.");
                return;
            }
        }

        string path = EditorUtility.SaveFolderPanel("Choose a directory to save the alpha maps:", "", "");

        if (path != null && path.Length != 0)
        {
            path = path.Replace(Application.dataPath, "Assets");
            TerrainData terrainData = terrain.terrainData;
            int alphaMapsCount = terrainData.alphamapTextureCount;

            for (int i = 0; i < alphaMapsCount; i++)
            {
                Texture2D tex = terrainData.GetAlphamapTexture(i);
                byte[] pngData = tex.EncodeToPNG();
                if (pngData != null)
                {
                    File.WriteAllBytes(path + "/" + tex.name + ".png", pngData);
                }
                else
                {
                    Debug.Log("Could not convert " + tex.name + " to png. Skipping saving texture.");
                }
            }
        }
    }
}

Each alphamap will be on a color channel (Red, Green, Blue, Alpha) of the PNG image. If the terrain has more than 4 textures, it will export additional images.