使用Perlin噪声创建闪电? [英] Using Perlin noise to create lightning?

查看:146
本文介绍了使用Perlin噪声创建闪电?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我有几个问题与主题标题中给出的主题相关。

Actually I am having several questions related to the subject given in the topic title.

我已经使用Perlin函数在我的应用程序中创建闪电,但我不完全满意我的实现。

I am already using Perlin functions to create lightning in my application, but I am not totally happy about my implementation.

以下问题是基于初始和改进的Perlin噪声实现。

The following questions are based on the initial and the improved Perlin noise implementations.

为了简化问题,让我们假设我通过使用1D Perlin函数调制由这些节点处的N个节点组成的水平线的高度来创建简单的2D闪电。

To simplify the issue, let's assume I am creating a simple 2D lightning by modulating the height of a horizontal line consisting of N nodes at these nodes using a 1D Perlin function.


  1. 根据我的理解,传递给Perlin函数的两个后续值必须相差至少一个,或者产生的两个值是相同的。这是因为使用简单的Perlin实现,Random函数使用一个int参数,在改进的实现中,值映射到[0..255],然后用作索引到包含值[0..255 ]。是这样吗?

  1. As far as I have understood, two subsequent values passed to the Perlin function must differ by at least one, or the resulting two values will be identical. That is because with the simple Perlin implementation, the Random function works with an int argument, and in the improved implementation values are mapped to [0..255] and are then used as index into an array containing the values [0..255] in a random distribution. Is that right?

如何实现Perlin函数返回的第一个和最后一个偏移值(即对于节点0和N-1)总是0(零)?现在我用我的Perlin函数调制一个正弦函数(0 .. Pi)来实现,但这不是我想要的。

How do I achieve that the first and the last offset value (i.e. for nodes 0 and N-1) returned by the Perlin function is always 0 (zero)? Right now I am modulation a sine function (0 .. Pi) with my Perlin function to achieve that, but that's not really what I want. Just setting them to zero is not what I want, since I want a nice lightning path w/o jaggies at its ends.

我如何改变Perlin函数(所以我会得到两个不同的路径,我可以用作动画的开始和结束帧的闪电)?我当然可以为每个节点值计算一个固定的随机偏移量,或者使用不同的设置排列表来改善Perlin噪声,但是有更好的选择吗?

How do I vary the Perlin function (so that I would get two different paths I could use as animation start and end frames for the lightning)? I could of course add a fixed random offset per path calculation to each node value, or use a differently setup permutation table for improved Perlin noise, but are there better options?


推荐答案


  1. 这取决于如何实现它和从中取样。使用多个八度音阶有助于对整数进行相当大的修改。

  1. That depends on how you implement it and sample from it. Using multiple octaves helps counter integers quite a bit.

每个八度音阶和附加插值/取样提供了perlin噪声中的大部分噪声。理论上,你不应该使用不同的整数位置;您应该能够在任何时间进行抽样,并且它与附近的值类似(但不总是相同)。

The octaves and additional interpolation/sampling done for each provides much of the noise in perlin noise. In theory, you should not need to use different integer positions; you should be able to sample at any point and it will be similar (but not always identical) to nearby values.

我建议使用perlin作为乘法器而不是简单的加法,并使用闪电过程中的曲线。例如,具有范围[-1.5,1.5]的perlin和闪电的正常曲线(两端为0,中心为1), lightning +(perlin * curve)将保持你的结束点。根据你如何实现你的perlin噪声发生器,你可能需要像:

I would suggest using the perlin as a multiplier instead of simply additive, and use a curve over the course of the lightning. For example, having perlin in the range [-1.5, 1.5] and a normal curve over the lightning (0 at both ends, 1 in the center), lightning + (perlin * curve) will keep your ends points still. Depending on how you've implemented your perlin noise generator, you may need something like:

lightning.x + =((perlin y,octaves)* 2.0) - 0.5)* curve(lightning.y);

if perlin 返回[0,1]或

if perlin returns [0,1] or

lightning.x + =(perlin(lightning.y,octaves)/ 128.0) * curve(lightning.y);

如果返回[0,255]。假设 lightning.x 以给定的值(也许为0)开始,这将给出仍然满足原始开始点和结束点的有点锯齿状线。

if it returns [0, 255]. Assuming lightning.x started with a given value, perhaps 0, that would give a somewhat jagged line that still met the original start and end points.

这篇关于使用Perlin噪声创建闪电?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆