Hi,
As one of my learning curves with terrain creation I was hoping to have a simple sphere textured using a 3D noise function set to give the visual of what the world looks like.
Then, I want to pick a point ( coordinates etc ) and build a planar terrain around that point and have it generated based on the same noise function set that created the sphere and thus should show the same visual.
As you can see from the images attached the sphere looks somewhat valid ( the poles have a mess of texture, which may be resolved if I use something different to the Unity Sphere ). However, the four planes are not quite working the way I was expecting. I can see that the top left when wrapped round will line up with the bottom left and similarly on the right. The row of 4 image shows this working. But not the way I thought it would.
I was hoping to work the planes in as a 3 x 3 or 5 x 5 block of smaller terrains, with their respective positioning information, which would be tiled across the x and z axis based on the distance ratio and planet radius and thus eventually reach the original tile.
Am I missing something obvious here? Here are the two main code blocks that generate the texture from the ComplexNoise noise class.
Thanks in advance.
xSphere Monobehaviour Class
[Header("Terrain Information")]
public int width = 360;
public int height = 180;
public float radius = 1f;
public int seed = 0;
[Header("Texture Information")]
public int texWidth = 512;
public int texHeight = 256;
public Gradient gradient;
public Shader shader;
[Header("Positioning Information")]
public Vector3 virtualOffset;
public float eastBounds;
public float westBounds;
public float northBounds;
public float southBounds;
Bounds bounds;
xSphericalMap sphereMap;
ComplexNoise complexNoise;
// Use this for initialization
void Start () {
float ewStep = eastBounds - westBounds;
float nsStep = northBounds - southBounds;
bounds = new Bounds();
bounds.center = virtualOffset;
bounds.min = new Vector3(westBounds, 0, southBounds);
bounds.max = new Vector3(eastBounds, 0, northBounds);
complexNoise = new ComplexNoise();
complexNoise.Define(seed);
sphereMap = new xSphericalMap();
sphereMap[0] = (ComplexNoise)complexNoise;
sphereMap.MapBounds = bounds;
sphereMap.MapRadius = radius;
sphereMap.MapResolution = new Vector2(texWidth,texHeight);
sphereMap.MapSeed = seed;
sphereMap.Build();
Texture2D texData = xTexture.Create(sphereMap.MapData, gradient, false);
xTexture.Write2PNG(Application.dataPath + "/Heightmap_W" + width + "H" + height + "_Seed_" + seed + ".png", texData);
Material mat = new Material(shader);
mat.mainTexture = texData;
GetComponent<Renderer>().material = mat;
}
xSphericalMap Class
// Build the spherical map
void BoundsToPolar()
{
westBounds = mapBounds.min.x;
eastBounds = mapBounds.max.x;
southBounds = mapBounds.min.z;
northBounds = mapBounds.max.z;
}
public override void Build()
{
// Make sure we have one sub module assigned
base.HasEnoughModules(1);
BoundsToPolar();
float startTime = xUtils.StartTimer();
float lonExtent = eastBounds - westBounds;
float latExtent = northBounds - southBounds;
float xDelta = lonExtent / MapResolution.x;
float yDelta = latExtent / MapResolution.y;
float curLon = westBounds;
float curLat = southBounds;
mapData = new float[(int)MapResolution.x, (int)MapResolution.y];
int width = (int)MapResolution.x;
int height = (int)MapResolution.y;
Vector3 virtualOffset = mapBounds.center;
for (int y = 0; y < MapResolution.y; y++)
{
curLon = westBounds;
for (int x = 0; x < MapResolution.x; x++)
{
float _r = mapRadius * Mathf.Cos(Mathf.Deg2Rad * curLon);
float _x = _r * Mathf.Cos(Mathf.Deg2Rad * curLat);
float _y = _r * Mathf.Sin(Mathf.Deg2Rad * curLon);
float _z = mapRadius * Mathf.Sin(Mathf.Deg2Rad * curLat);
mapData[x, y] = ((ComplexNoise)subModules[0]).Evaluate(_x, _y, _z);
curLon += xDelta;
}
curLat += yDelta;
}
float endTime = xUtils.EndTimer();
Debug.Log(string.Format("Spherical Data Generated in {0} milliseconds", xUtils.TimerDuration(startTime, endTime) * 1000.0f));
}


