Here is how you can blend data of noise and gradient together, in 3D. This should provide you with asteroid style shapes.
First, our container to store the Data:
public class MapData {
public float[,,] Data;
public float Min { get; set; }
public float Max { get; set; }
public MapData(int width, int height, int depth)
{
Data = new float[width, height, depth];
Min = float.MaxValue;
Max = float.MinValue;
}
}
We init this data container as follows:
blendData = new MapData (Width, Height, Depth);
Now, if you already have your generated noise, and gradient maps, you can blend them as follows:
// first pass - blend gradient values
for (var x = 0; x < Width; x++) {
for (var y = 0; y < Height; y++) {
for (var z = 0; z < Depth; z++) {
// Get gradient values
float gradValue1 = (float)NoiseMap.Get (nx, ny, nz);
float gradValue2 = (float)GradientMap.Get (nx, ny, nz);
// Multiply
float blendValue = gradValue1 * gradValue2;
// keep track of the max and min values found
if (blendValue > blendData.Max) blendData.Max = blendValue;
if (blendValue < blendData.Min) blendData.Min = blendValue;
blendData.Data[x,y,z] = blendValue;
}
}
Doing so will give you some pretty crazy values, so we are going to want to normalize these in order to provide an easier way to work with this data in the future:
// secondary pass to normalize the blended values
for (var x = 0; x < Width; x++) {
for (var y = 0; y < Height; y++) {
for (var z = 0; z < Depth; z++) {
blendData.Data[x,y,z] = (blendData.Data[x,y,z] - blendData.Min) / (blendData.Max - blendData.Min);
}
}
}
Render this data, and you should see a asteroid style shape emerge.