Light mapping a HUGE terrain - Details inside...

So I decided I like to take on really difficult challenges and push Unity’s terrain pretty hard.:slight_smile:

These terrains are for my Lunar Module Game called Lunar Flight Lunar Flight

I have a 6147x6147 height field, Unity is limited to 4096x4096 so to create my 6.147 kilometres of terrain I use L3DT to chop my map into 3x3 tiles of 2049.

Next up I had to manually create each terrain and import each tile’s RAW file and position the tiles

So far so good… but there was a problem with the edges, it seams L3DT introduce some error and they didn’t perfectly line up along the edges. So I got a hold of Stitchscape, but I soon discovered it didn’t support single edge stitching so I modified the code so it would.

Next I wrote a simple script to assign all the terrains neighbours so the the terrain LOD would respect the tile edges.

public Terrain[] terrains;

	// Use this for initialization
	void Start () 
    {
        //SetNeighbors(Left, Top, Right, Bottom);
        // Column 0
        terrains[0].SetNeighbors(null, terrains[1], terrains[3], null);                 // 00
        terrains[1].SetNeighbors(null, terrains[2], terrains[4], terrains[0]);          // 01
        terrains[2].SetNeighbors(null, null, terrains[5], terrains[1]);                 // 02

        // Column 1
        terrains[3].SetNeighbors(terrains[0], terrains[4], terrains[6], null);          // 10
        terrains[4].SetNeighbors(terrains[1], terrains[5], terrains[7], terrains[3]);   // 11
        terrains[5].SetNeighbors(terrains[2], null, terrains[8], terrains[4]);          // 12

        // Column 2
        terrains[6].SetNeighbors(terrains[3], terrains[7], null, null);                 // 20
        terrains[7].SetNeighbors(terrains[4], terrains[8], null, terrains[6]);          // 21
        terrains[8].SetNeighbors(terrains[5], null, null, terrains[7]);                 // 22
	}

Finally I have one massive terrain and performance is actually pretty good.

Now this is a support thread so I guess I should get to the point of the reason I am posting. I want to light map this terrain but (I think) due to Unity being a 32bit application it will run out of memory if I try to bake a lightmap on more than one terrain even before it gets to ‘The Beast’ So I decided to light each tile anyway by disabling all the tiles except the one I was lighting. This required moving the generated lightmap for each tile into a separate folder until I had all 9 of them and then could set the map array size and assign the atlas ID to each one.

As expected this produced seams along the tile edges where shadows would get clipped etc… as each tile does not influence each other during the bake. It looks like this:


Full Image

So at this stage I think my only option is to try and export each tile out as a mesh and generate the full lightmap in another application like 3DSmax which has support for .EXR format.

This is a real shame because each tile only takes 2.5 minutes to bake their respective maps and it would suggest that baking all 9 at once should be achievable.

Comments?

:face_with_spiral_eyes:

Why not set the lightmap resolution to zero on all of the terrains that you’re not generating a lightmap for? That way they will still cast shadows but will not be taken into account for the actual lightmap texture that you are baking.

OK Cool, I’ll give that a try! :slight_smile:

Unfortunately it doesn’t seem to work. It did do something for 40 minutes but it did not create an actual texture at the end of the process. :frowning:

I’m getting this problem: http://forum.unity3d.com/threads/75409-Beast-Crash-on-quot-Importing-ADS-Structure-quot

It bombs out at the building ADS structure

Did you ever find a solution for this?