1

我正在尝试提出一种技术来生成流星陨石坑的高度图。目前我试图保持小而简单,并且有一个简单的算法,其中标记了陨石坑的中心,在其半径内,它周围的像素根据它们与中心的接近程度而着色。

这种方法的问题是它会产生 V 形陨石坑,我需要更多的“U”形结果。我不熟悉正弦波的使用,我觉得插值不会很快起作用,因为流星半径内可能有多少像素。

有什么建议么?

4

1 回答 1

2

我假设您有一个纹理或其他图片格式,可以在宽度和高度 (x,y) 上进行索引,并且火山口也在 x,y 中给出,x,y 在纹理内,这将产生这样的算法。

Texture2D texture = ...;
Vector2 craterPosition = new Vector2(50,50);
double maxDistance = Math.Sqrt(Math.Pow(texture.Width,2) + Math.Pow(texture.Height,2));
for(int x = 0; x < texture.Width; x++)
{
    for(int y = 0; y < texture.Height; y++)
    {
        double distance = Math.Sqrt(Math.Pow(x - craterPosition.x, 2) + Math.Pow(y - craterPosition.y, 2));
        //the lower distance is, the more intense the impact of the crater should be
        //I don't know your color scheme, but let's assume that R=0.0f is the lowest point and R = 1.0f is the highest
        distance /= maxDistance;
        double height = (Math.Cos(distance * Math.Pi + Math.Pi) + 1.0) / 2.0;
        texture[x,y] = new Color((float)height,0,0,1);        
    }
}

这里最重要的一行可能是

double height = (Math.Cos(distance * Math.Pi + Math.Pi) + 1.0) / 2.0;

看看余弦曲线http://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Cos.svg/500px-Cos.svg.png它有一个很好的平滑的“火山口状”圆角从 Pi到双皮。由于我们的距离变量从 0~1 缩放,我们使用距离 *Pi + Pi。但这会给我们一个从 -1 到 1 的结果。所以我们将 1 添加到最终结果,然后除以 2 以获得 0 到 1 之间高度的平滑结果。

我希望这可以帮助你。

于 2011-05-03T12:26:40.887 回答