Spherical Terrain Object?

Is it possible to create a terrain object from a sphere?

I'm building a "Little Prince" type planet that the game camera rotates around and would love to use the super optimized terrain to build up the exaggerated mountains.

Is there a way to use a quad mesh object as a stand-in for terrain that the terrain tools will work on?

I can build my own mesh, but it will likely be a lot heavier than a terrain object.

This new Q&A site ROCKS, BTW.

Spence.

You can't use unity's terrain engine at all to make spherical terrains, even by putting multiple terrain pieces together. Much of the optimisation done within the terrain engine relies on the terrain being a flat horizontal plane which is deformed upwards only by the heightmap. Same with the trees & grass system, etc - all designed to work on terrain which lies on the X-Z plane. For this reason, the rotation controls in the inspector of the Terrain GameObject have no effect at all.

The most common way of achieving spherical terrain that I've seen is to build your own "CubeSphere" using 6 heightmaps, one for each side of the cube. I've done this before, and I've seen at least two other people on the IRC channel accomplish it.

The technique is essentialy this:

  • Generate 6 heightmaps which seamlessly join in the same way that a skybox joins.
  • Use Unity's mesh building API to build each side of your CubeSphere separately
  • For each side, you need to 'Spheriphy' the grid mesh which makes up the cube's side, and then add on the value from the heightmap for that side. My code for determining the position of a vertex on any given side of the CubeSphere looks like this (x & y is the position within the heightmap for the side):

    // first calculate as if this is the top side
    float yi = planet.baseHeight + altitude;
    float xi = ((x / (float)planet.mapMax) - 0.5f);
    float zi = -((y / (float)planet.mapMax) - 0.5f);
    Vector3 v = new Vector3(xi, 0.5f, zi);
    v.Normalize();
    v *= yi;
    
    // rotate according to side orientation
    switch (side.orientation)
    {
        case Planet.Orientation.Top: break;// nothing
        case Planet.Orientation.Bottom: v = new Vector3(v.x, -v.y, -v.z); break;
        case Planet.Orientation.Back: v = new Vector3(v.x, -v.z, v.y); break;
        case Planet.Orientation.Front: v = new Vector3(v.x, v.z, -v.y); break;
        case Planet.Orientation.Left: v = new Vector3(-v.y, v.x, v.z); break;
        case Planet.Orientation.Right: v = new Vector3(v.y, -v.x, v.z); break;
    }
    position = v;
    
    

Terrains are only height maps on planes... there's no spherical support that I'm aware of. Depending on your needs, you may be able to fake something by putting multiple terrain objects together, but you're probably just going to have to model your terrain in a 3D program.

Hey All,

Had the same problem as described so I went with building my own mesh. I started with a 6 sided cube mesh made in Rhino. I used the Grasshopper plugin to sample height-map values and added the vector amount to each UV on the cube respectively. The result is pretty good but very heavy, which leds into a L.O.D. (level of detail) issue. Not to mention having to code in planetary gravity and player controllers. IE… Planets are custom Assets as far as terrain is concerned. Took me a couple of weeks to figure out ‘my’ work-around for planet making and I’m still not done. … never done… best practice guild for planet creation needed…

vote here please
https://feedback.unity3d.com/suggestions/spherical-terrain-generation