- Home /
Correctly Rebuilding Terrain Basemap
I am adding a dynamically generated "seafloor" texture to my terrains by adding a new element to the terrainData's splatPrototypes array. I then get the terrain's AlphaMap, populate the new seafloor channel, and call trnDat.SetAlphamaps(0, 0, alphaMap) to update the terrain.
It works beautifully! ...Except that the seafloor areas are rendered completely black on areas of the terrain that are grater than the terrain's basemapDistance from the camera.
I have tried using trnDat.SetBaseMapDirty(), trnDat.ResetDirtyDetails(), and terrain.Flush() to rebuild the terrain's base map after updating it's AlphaMap, but they either have no effect, or turn all the channels in my terrain's basemap black.
What is the correct way to regenerate a terrain's basemap?
Thanks,
-Aubrey
Answer by duck · Dec 24, 2009 at 10:17 AM
When I have done this (and it works correctly for me), the only commands I have called after SetAlphamaps look like this:
terrainData.SetAlphamaps(0, 0, splatmapData);
terrainData.SetDetailLayer(...) // once for each detail layer
terrain.terrainData = terrainData; // reassign data to terrain
terrain.lighting = TerrainLighting.Lightmap; // assign lightmap (which I also generated)
terrainData.RefreshPrototypes();
terrain.Flush();
Maybe simply reassigning the terrainData as I do in the 3rd line above will fix it for you... the other lines, as far as I understand, are unrelated to the splatmaps/basemap, but I included them just in case, because with my project the basemap seems fine and matches the new splatmaps properly.
hope this helps.
Thanks! Unfortunately, this still isn't working for me. Here's my complete terrain code: http://pastebin.com/m764df6bd Here's a screenshot of the error in my game: http://img96.imageshack.us/img96/2267/screenshot20091224at112.png
As you can see, on the $$anonymous$$imap camera (which is farther from the terrain than the main camera), the seafloor texture is solid black.
What does SetDetailLayer(...) do? Should I be using it ins$$anonymous$$d of directly altering the splatPrototypes array?
This is an old post, but I thought I would share for anyone else stumbling on this.
I was getting weird results from my procedural splatmap as well, particularly my basemap was blocky and popping in and out. By simply setting the resolution of the basemap prior to applying the splat info it solved my problem.
terrain.terrainData.base$$anonymous$$apResolution = (i set $$anonymous$$e to my splat map resolution)
Answer by Tom 1 · Jan 25, 2010 at 08:32 PM
You also need to renormalize the splatmap data. All channels of all splatmaps combined should not exceed 1.0 or you will get weird effects. So if you add something to the alpha channel, you have to reduce all other channels.