In our game, there is an unsightly texture seam where two terrain objects meet. We’re using lots of solid colors, so if we were able to paint over two terrains at once that would allow us to easily deal with the seams. Unfortunately, Unity’s terrain only supports editing one terrain at a time, and I haven’t found anything that allows working on multiple terrains at once. Does such a tool exist?
Is this in the right subforum?
I don’t know of any… and yes it is the right subforum. I didn’t respond because I didn’t know of any…
I believe the Unity native terrain uses a splat map so you could take the splat map out and paste it in your favorite graphics editor and fix the seams there…
Oh, that actually was what I needed to know! Didn’t realize they exported their splat maps. Thanks!
EDIT - They don’t export their splat maps :[
I don’t know if I’m supposed to have the source code for the Unity Shaders - I downloaded it from somewhere and I have no clue if it was a legit source… if this is a violation of EULA or something - I’ll get rid of them immediately… But here are the properties I have defined for the shaders which should allow you to access the splat maps from (TerrainObject).MeshRenderer.Material.GetTexture()
http://docs.unity3d.com/ScriptReference/Material.GetTexture.html
Shader "Nature/Terrain/Diffuse" {
Properties {
[HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
[HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
[HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
[HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
[HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
// used in fallback on old cards & base map
[HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
[HideInInspector] _Color ("Main Color", Color) = (1,1,1,1)
}
Looks like the property “_Control” is the texture you want to yank out of the Material… Maybe “_BaseMap” - idk…
EDIT: looks like the source code is ok to reference - I think I got it from this thread: http://forum.unity3d.com/threads/builtin-unity-shaders-source.2085/
Although that’s a really old version of unity…
EDIT2: You can download the updated shader source from here: http://unity3d.com/unity/download/archive
EDIT3: Looks like that is the 4.6.1 shader source I downloaded - I guess I did get it from the download archives.
Oh interesting. I may look into that, but I actually stumbled upon another way to export the splat map. If you use AssetDatabase.CreateAsset with a terrain, the resulting asset in the project actually has the splat map as its child. I think this is true in all cases, but I’m using the SECTR STREAM plugin which is doing that asset creation for me. So that was already a part of my pipeline. From there, I’m using Texture2D.EncodeToPNG to export that as a PNG.
var bytes = texture.EncodeToPNG();
var path = Application.dataPath + "/Art/Generated/" + texture.name + ".png";
File.WriteAllBytes(path, bytes);
EditorUtility.DisplayDialog("Success", "Splat Map exported to " + path, "Ok");
The problem I’m hitting now is that the generated PNG displays properly inside of Unity but not in an external editor. The map is all there in Unity, and I can mess with its import settings, but the file outside of Unity is pure alpha.
Ah, I figured it out. For some reason, the generated PNG has full alpha on every pixel. Easy fix.
I guess I didn’t think of the fact that it probably uses the alpha channel for the splat as well… Unfortunately, Gimp doesn’t let you edit alpha channels with much ease. The shader is using the alpha channel as one of the splats… If you have three textures, it’s not going to be a problem, but if you have four, it’s also going to be using it. Additionally, there seems to be a problem that all the values have to add to 1 because the splats are percentage based so using an external graphics editor is probably not the solution you’re looking for…
Nobody was responding to your post so I responded with my best guess - which is a bad best guess…
Oh no worries, you were super helpful. All I had to do was iterate through and max the alpha channel in the texture
Color32[] colors = texture.GetPixels32();
for (int i = 0; i < colors.Length; ++i)
{
colors[i].a = byte.MaxValue;
}
texture.SetPixels32(colors);
texture.Apply();
Yeah, but I’m saying the alpha is part of the splat map for texture 4 for your terrain map and the value of the colors must add up to one. So, thats a problem unless you’re going to procedurally generate your splat maps or ONLY use clone and never use a 4th texture: http://forum.unity3d.com/threads/terrain-splat-maps.10455/
I.E. if you leave the alpha channel all at “one” it’s going to tell the shader that you want a full sampling of texture # 4 at every location on the map.
Like I said - I was wrong about using a graphics program - it’s an extremely bad idea…
Ah, well then we’re left without a solution. That video you posted only shows stitching the terrain heightmaps together, which is actually an issue the SECTR plugins solve quite nicely. I really appreciate all the help though.
The system of exporting, editing, and reimporting does work, but like you said, it makes it impossible to use a 4th splat texture as we’re ruining the alpha channel. We’re running with this system until we find a better solution though, as it does work.
Sorry I sent you down a dead end… I feel like a jerk for not realizing it ahead of time - my experience with the native Unity Terrain is limited…
That’s okay, you’re no jerk, I appreciate the help! Can I assume that you use WorldMachine for terrain? What kind of data is your terrain represented by in your games? A mesh?
My “games” consist of me dinking around programming various things and then stopping and starting something else because making art for them takes too long and I find it very tedious… I tend to enjoy coding more than making meshes and the like… I am more seriously working on an “endless” (ulong.maxvalue x ulong.maxvalue) terrain generator, but that doesn’t incorporate any of the native terrain stuff and is pretty simple stuff…
One time I tried to make a few addons for Oblivion and, later, Skyrim (what got me into programming) and I quickly realized that hand design is a real pain in the butt for one person to do unless they have masterful skills and patience and I didn’t even have to design the base meshes for Bethesda’s construction kit…
My dream is finally finishing a “roguelike” RPG that is more like a modern Daggerfall with huge swaths of procedurally generated landscape, towns, dungeons, npcs, enemies, party members, and the sort - but I tend to jump all over the place when I’m learning new things… e.g., I finished a rough draft of my endless terrain generator and then, instead of refining it, perfecting biomes, etc, I made a tiling voxel generator.
I.E. I’m just here for the fun of making algorithms.
Anyway, did you look into the functions for “declare as neighbor” or whatever that comes with the native Unity terrain?
Haha well fun algorithms are fun! I’ve enjoyed doing some procedural stuff. Nothing procedural about this game though. Anyways, I know the functions you’re talking about and they stitch the heightmaps together but not the splatmaps
Anyway, barring finding a tool that does it for me, I’d probably just script a method to pull out the splat maps and blend their edges together…
Sorry to bring this old thread up, But I found an amazing asset for it here: https://www.assetstore.unity3d.com/en/#!/content/44037 have look, hope that helps.