/// <summary>
/// Generates mesh using some random values interpolated with trilinear interpolation.
/// Uses coordinates transformed with warp values.
/// </summary>
/// <param name="width">Mesh widht.</param>
/// <param name="height">Mesh height.</param>
/// <param name="depth">Mesh depth.</param>
public void GenerateFromNoiseCubeWithWarp(int width, int height, int depth)
{
Voxel[, ,] voxels = new Voxel[width, height, depth];
Vector3 center = new Vector3(width / 2, height / 2, depth / 2);
NoiseCube n0 = new NoiseCube(16, 16, 16);
NoiseCube n1 = new NoiseCube(16, 16, 16);
NoiseCube n2 = new NoiseCube(16, 16, 16);
NoiseCube n3 = new NoiseCube(16, 16, 16);
NoiseCube n4 = new NoiseCube(16, 16, 16);
Parallel.For(0, width, (x) =>
{
for (int y = 0; y < height; y++)
{
for (int z = 0; z < depth; z++)
{
Vector3 position = new Vector3(x, y, z);
float weight = center.Y - y;
float warp = n0.GetInterpolatedValue(x * 0.004, y * 0.004, z * 0.004);
float cx = x + warp * 8;
float cy = y + warp * 8;
float cz = z + warp * 8;
weight += n1.GetInterpolatedValue(cx / 32.04, cy / 32.01, cz / 31.97) * 64.0f;
weight += n2.GetInterpolatedValue(cx / 8.01, cy / 7.96, cz / 7.98) * 4.0f;
weight += n3.GetInterpolatedValue(cx / 4.01, cy / 4.04, cz / 3.96) * 2.0f;
weight += n4.GetInterpolatedValue(cx / 2.02, cy / 1.98, cz / 1.97) * 1.0f;
voxels[x, y, z] = new Voxel()
{
Position = position,
Weight = weight
};
}
}
});
ComputeNormal(voxels);
ComputeAmbient(voxels);
CreateGeometryBuffer(ComputeTriangles(voxels, container.Settings.LevelOfDetail));
}