I am trying to replace the Unity3d terrain splat maps with PNG files created outside Unity3d (Photshop 7). The editor tool script that I found on this forum replaces splat maps, in the project view. I placed the JavaScript file in the assets/editor folder, and it then appears in the Unity3d assets pulldown, allowing me to swap maps with an external PNG. The results when I swap a splat makes makes no sense to me. I thought red, green, blue and black would define what parts of the terrain are 1 of 4 terrain textures. But it is not working that way, I get very strange results on the terrain. Does alpha channel matter? Maybe I am using the wrong PNG format? Thanks for any help you can give.
Red, green, blue and alpha channels all are weights for the corresponding splat texture. All the weights (over all splat maps) should sum up to 1.0, so having a black color does not make sense (it's zero weight for all textures - hence result is black). Yes. Each splat map is 4 channels, RGBA.
It seems my problem is the PNG file format. In Photoshop 7 or CS3, I cannot save a PNG file with an alpha channel. Only formats like TIF and PSD can do that from PS. FYI I want to use Photoshop to create more precise splat maps (like exact line draws versus paint brush swipes in Unity terrain editor). My other motivation is that I would end of with splat data that I could pixel read to determine what terrain texture type my player is on. I wish I could read and plot the terrain splat in Unity3d, but I can work around that limitation if I could just import and export splat maps (like you can with height maps). In short ... I cannot swap the splat map with something that works the way you say it should work, because loadImageToTexture can only use PNG or JPG with no alpha. What art tool can save a PNG with alpha? I also have a related question. How could I export the PNG ARGB32 of a splat map I made with the Unity3d terrain tool?[/u]
Why not just let the Unity asset pipeline import the file for you and the use the Texture2D class to access the pixels and copy them over into the splatmap. Instead of doing the texture loading manually using the WWW class?
??? Photoshop exports PNG with alpha since Version 6 if not even earlier. But alpha in photoshop means an Alpha Mask applied and/or a transparent background.
Photoshop does not export a 32 bit ARGB file, which appears to be what Unity3d splat maps need. I like the idea of using Texture2D class. Only problem is, once I have my new splat map texture, how would I assign that texture to say "SplatAlpha 0"? I tried - renderer.material.SetTexture("SplatAlpha 0", texture) but it did not work.
Was there ever a good solution to this? I'm having the same problem at the moment, with World Machine 2 generated bitmaps. I can try using .tiff but I don't really think that's the problem (I am using .png right now, and Unity's import settings to convert to ARGB32).
There's this. I don't think .png really works for this unless there's some way to save the alpha channel I didn't figure out, but .tiff does work for sure. --Eric
I'm using that, no good results. Maybe I don't get the exact requirements of splat maps. I'm using World Machine 2 to create them, but I have no freaking idea what exactly it's putting into the files, especially regarding alpha channels, nor do I have a very good understanding of what exactly the splat map needs to look like. If anyone knows a link where that's explained, I'd be happy. Google turns up nothing of relevance. Here's the .png I've been playing with, if anyone cares. Maybe the problem is with it?
Ah! Much better results if I enable "build alpha from grayscale" in the import settings. Still far from perfect, but at least no weird artifacts anymore.
Here's a working .tiff file; if you take a look at the individual channels you should see how it works. "Build alpha from grayscale" won't get the correct results because the alpha is supposed to be a discrete channel like r, g, and b. --Eric
The .png you attached doesn't have an alpha channel, at least one doesn't appear when I open it in GIMP. The idea behind splat maps is actually pretty simple: it uses each channel to define areas for textures, etc. So if you open a splat map in Photoshop, go to the channels panel and turn off all the channels except one. Then you'll see the area definition for that particular channel. Prior to the terrain function in Unity I used the "nature" script (which does pretty much the same thing) and I hand painted the splat maps manually in Photoshop by just turning on one channel at a time and painting only in that channel. HTH.
That helps a lot, thanks. Now, how do I get this from WM2? Anyone know a photoshop trick to seperate out the channels or something? I can do a tiff export from WM2, but it will export pretty much like the png, not as seperate channels. Or maybe I'm still missing something?
What bigkahuna wanted to tell you, is HOW to edit seperate channels in your file with maximum control. Your PNG from WM2 will contain the channels as all other grafic formats contain channels... You should check your photoshop manual on how to edit them individualy. Frank
It looks like WM2 is only using 3 of the 4 channels, is it possible that you're only using 3 textures? If so, just open the .png / .tif file in Photoshop and add an alpha channel. The re-save, preferably as a .psd (since Unity reads these natively). That should work. If not, I'd wait and see what Eric has to say, he's the terrain "guru" here.
I know that. The problem appears seperating them from each other in some semi-automated way. But I think WM2 has another option, I can simply generate them individually and then merge them in PS. I'll try that, and if it works, I will post the workflow for others to follow.
I noticed the true content of your question too late, so, i äh just refer to my signature in this case Frank
Without seeing what the terrain looks like in WM2 I can't say for sure, but it sounds like the .PNG you posted should work fine. You just need to open it in Photoshop (or GIMP) and add an alpha channel. I saved a sequence of screenshots showing what I mean and put it in a zip file (attached). Take a look at this and tell me if this helps or if I'm completely off...
I have a solution for the WM2 part, but it still has its problems: Use the following 3 macros in WM2: Slope Coverage Height Coverage Local Heights Add a Clamp filter behind Local Heights and filter out roughly the lower half (use "extend"). Convert all 3 outputs to bitmaps using the colorizer filter. Just leave the default settings, that'll give you grayscale output. Link to 3 bitmap outputs. This gives you 3 bitmaps in grayscale that contain the slope, height and local height coverage data. Now open one of these in PS, add an alpha channel and delete the contents of all channels except one (say, red). Now open the second file, copy it's blue channel to the blue channel of your working image. Repeat with the green channel of the third image. Save the result as a .tiff and you'll have one problem left: In a lot of places, there will be more than one channel active, which gives weird lighting results in Unity. Any PS help appreciated. Ideally, the resulting image would be four-colour. Not sure how to achieve that.
Hm, this is starting to drive me insane. It appears to work now, except that lighting in Unity is totally off. Look at the screenshot attached. The splatmap is also attached. What am I missing?
well, not sure if it helps you as i just skimmed the post but this is what i do with photoshop 7 using layer masks and it works well: 1. open your grayscale bitmaps the splat base (attached) in photoshop. 2. select all on a bitmap copy (apple-c). 3. in the splat base, select your desired color layer (don't muck with the channels). hold down alt click on the mask tile to the right of the layer tile in the layer palette. paste (apple-v) the bitmap in. 4. go to the 'layer' pulldown menu, 'remove layer mask', 'apply'. do this for each, on the black color layer make sure you use the same bitmap both in the black layer mask and in the alpha channel in the channels palette. EDIT: you were posting while i was. that effect you're showing means you borked the process somewhere. (in the project folder do you have the texture set to ARGB32?) : )
Ok, the channels should all add up to 1. I'm getting some fairly good results here, look. But the PS process to get this is quite involved. I'll check if I can make it easier.
Ok, I got the process down now. Here's how to handle the three images generated above in PS: Load one. Add Alpha channel and invert it (so it's white) Clear out (Cmd-A, Backspace) the Green and Blue channels Load the second file. Select the Green channel, Cmd-A, Cmd-C Select the Green channel OF THE FIRST IMAGE and Cmd-V repeat with 3rd file and Blue channel You now have one image where the RGB channels represent slopes, heights and local heights. Now use the "channel as selection" feature of PS on the red channel, then select the alpha channel and cut out (CMD-X). Repeat with the green and blue channels. This yields you an image where the alpha channel is set everywhere none of the others are set, i.e. the sum is 1 everywhere. Save as a .tif with alpha channel. Import into Unity. Set import settings correctly (ARGB 32). Use ApplySplatmap.js Here's a second terrain I generated in WM2 and got into Unity with procedural texturing applies with the method outlined in this thread:
One more: The short method retains the overbright problem. If you want to avoid that, here's an ugly hack on how. I'd love to have a better solution but right now I don't: convert the image to 8-bit, indexed colour give it a custom palette - red, green, blue and black - and no dithering voila. do a gaussian blur with pixel size 1.0 for better visuals.
Got it. Here's a better way to get the splatmaps to be perfect: In PS, invert the red and green channels use "channel to selection" on the blue one select the green channel and Cmd-X repeat both steps for the red channel invert the green channel use "channel to selection" on the green channel select the red channel and Cmd-X invert the red channel then do the thing with the alpha channel from above. This yields you a very pretty and not-overbright splat map for the procedural texturing:
I've put the necessary steps up into a PS action that you can find attached. It will pop up 3 "open file" dialogs where you have to select the three files for the RGB channels (slope, heights and local heights if you followed my WM2 example).
I tried the PS Action, and at least with my home-brewed splat maps (instead of World Machine), the action doesn't fully work on CS3. I want to write up some of the things that have come out of these threads. In the meanwhile, I want to share one thing that may have been covered already, but here it is in case it hasn't. If you want your actual splats (the RGB channels) to be rendered at full strength without appearing overexposed on the terrain for a given lighting level, then the alpha channel of the splatmap should be set to black. Remember that the alpha channel is the 4th splat on the map. And even if you don't define a texture in the terrain object for the 4th splat, it is used as the first, or default splat on the terrain when nothing is painted on. If you take an undefined terrain and add a single texture, and then change it to something else, the entire terrain will take on that texture. So if you were to add the 4th splat to the World Machine RGB map, the entire terrain would have it at the fade level defined by the alpha channel. The RGB splats are added after that one. So a grayscale value of other than black (0) in the alpha channel but no splat assigned to that slot will act like an exposure level since a stark white empty texture is being blended with the other three.
Thx! One typo in your script not "file:// " but "file:///", so all script will be: Code (csharp): @MenuItem("Assets/Overwrite 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 path = EditorUtility.OpenFilePanel("Overwrite with png", "", "png"); if (path.Length != 0) { var www = new WWW ("file:///" + path); while (![url]www.isDone[/url]) ; www.LoadImageIntoTexture(texture); } } Tested on indie under Windows Vista, work good. P.S. Error was Code (csharp): You are trying to load data from a www stream which had the following error when downloading. Couldn't open file /splat3_201.png UnityEngine.WWW:LoadImageIntoTexture(Texture2D) UnityEngine.WWW:LoadImageIntoTexture(Texture2D) change_splat_texture:Apply() (at Assets\Editor\change_splat_texture.js:17) [..\..\Runtime\Export\[url]WWW.cpp[/url] line 652]
Hi, I just bought world Machine and discovered this interesting thread. Am I correct by understanding that it's possible to bypass the Photoshop step thanks to the alpha input in WM's bitmap output ? and if yes, could someone share a WM scene with the right nodes connected ? in particular, I don't see what data must feed this alpha input. Thanks in advance...
I just downloaded the Tom's Terrain Tools but I don't have Terragen or WM2. Is there any other way to make splatmaps or overlay maps? For example, can I use Gimp for making overlay maps and what is the image format I need to save in Gimp? I have been trying to use PNG-image as overlay map but I always get the message "overlayMap must be in RGBA 32 bit or RGB 24 bit format".
I believe there is a free version of L3DT. http://www.bundysoft.com/docs/doku.php?id=l3dt:about You can use the wizard to get you started, too. Here are my instructions on how to use it with Tom's Terrain Tools. http://forum.unity3d.com/viewtopic.php?t=50018&highlight=l3dt
Thanks for the hint RoyS. I will need to do some experimenting with L3DT. I was just hoping that there would have been a simple way to create overlay map with Gimp.
I hate to revive an old thread, but its easier than starting over. I've tried to create a splatmap with the template file provided by DrJones above. It works except one of the 4 channels is being applied over the entire terrain. I thought it might be because the Red layer didn't have mask, so I created one and applied the B/W image, but it gave me the same results. Possibly something changed in the way Unity uses splatmaps in the last 3 years :/? Can anyone help me with this? Thanks.
I made a quick overview to help people understand how splatmaps work in general, hope it helps. And please correct me if anything is wrong, I just learned all this tonight which is how I found this thread. Guessing this will happen to people in the future too :I Same thing mirrored on dropbox cause the attachment resolution is quite bad.
I know it's an old thread but in case anyone comes across this problem again, one workaround in photoshop is to install a plugin called superPNG. It allows you to save out proper RGBA values to PNG files as opposed to just transparency.
This totally fixed the issue and here's some more details to fix it quickly in photoshop. 1. My splat map from WM2 was a .png to start with. Even if you save it as a .tiff there won't be an alpha channel in WM2 version 2.2, I don't know about the new 2.3 which has a new splatmap device that probably works better than this one. 2. Open your splatmap in Photoshop or whatever you have to work with and add a new channel by clicking 'new channel' button in the lower right corner of the Channels list ( right next to layers) 3. This will automatically give you a black alpha channel. Make sure you click the eyes back on all channels so they are visible. You splat map will look orange and purple maybe, but it's fine. 4. Save the file as a .tiff and use this new splatmap instead. Works great for me, except if I try to use a Bumped Specular material on the terrain, I get a crazy intense brightness from my directional light that I can't seem to figure out so it's usuless and I really wanted to be able to use this material. Is there another material I can use instead?
Thank you for that detailed explanation and the screenshots in PS. I saved it for future reference as well. I have everything working, but I need another splatmap to handle more than 4 textures. I can't seem to find anyone that knows what to do about that? World Machine says, if you need more than 4 textures, make another bitmap...but how would you actually do this in detail? I can't get Unity to recognize another splatmap in conjunction with the first one which works great and is named Splatmap0. Someone said something about a file called FirstPass handling the first 4 textures and AddPass taking care of other groups of 4 textures after that, each group getting assigned another splat map...but how do I get this to work. It doesn't automatically create another splatmap when I add a fifth texture it just turns everything pink instead and disregards my original splatmap apparently but not sure what is going on to tell the truth. I didn't have this problem until I used the splatmap replacement editor script by the way so it's something to do with that process. Thanks!