Perlin 的 OpenGL 噪声
我正在通过一些示例研究 Perlin 的噪声 @ http://dindinx.net/ OpenGL/index.php?menu=exemples&submenu=shaders 并忍不住注意到他在 perlin.c
中的 make3DNoiseTexture()
使用 noise3(ni)
而不是 PerlinNoise3D(...)
现在这是为什么呢? Perlin 噪声不是应该是不同噪声频率和幅度的总和吗?
问题2 ni、inci、incj、inck
代表什么?为什么使用 ni
而不是 x,y 坐标?为什么 ni
会随着
递增 ni[0]+=inci;
inci = 1.0 / (Noise3DTexSize / 频率);
我看到 Hugo Elias 使用 x,y 坐标创建了他的 Perlin2D,PerlinNoise3D(...) 也是如此。
提前致谢 :)
I was studying Perlin's Noise through some examples @ http://dindinx.net/OpenGL/index.php?menu=exemples&submenu=shaders and couldn't help to notice that his make3DNoiseTexture()
in perlin.c
uses noise3(ni)
instead of PerlinNoise3D(...)
Now why is that? Isn't Perlin's Noise supposed to be a summation of different noise frequencies and amplitudes?
Qestion 2 is what does ni, inci, incj, inck
stand for? Why use ni
instead of x,y coordinates? Why is ni
incremented withni[0]+=inci;
inci = 1.0 / (Noise3DTexSize / frequency);
I see Hugo Elias created his Perlin2D with x,y coordinates, and so does PerlinNoise3D(...).
Thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我现在明白为什么,并将回答我自己的问题,希望对其他人有帮助。
Perlin's Noise 实际上是梯度噪声的综合。在其生成过程中,我们必须计算从输入点的一个角点到输入点本身的向量与随机生成的梯度向量的点积。
现在,如果输入点是整数,例如要创建的纹理的 xyz 坐标,则点积将始终返回 0,这会给您带来平坦的噪声。因此,我们使用
inci, incj, inck
作为替代索引。是的,只是一个索引,没有别的。现在回到问题1,有两种方法来实现Perlin的Noise:
1.单独计算噪声值并将其存储在纹理中的RGBA槽中
2.预先合成噪声并将其存储在纹理中的 RGBA 插槽之一
noise3(ni)
是方法 1 的实际实现,而PerlinNoise3D(...)
建议后者。我个人认为,方法 1 更好,因为您在着色器中使用每个八度音阶的方式上有更大的灵活性。
I now understand why and am going to answer my own question in hopes that it helps other people.
Perlin's Noise is actually a synthesis of gradient noises. In its production process, we must compute the dot product of a vector pointing from one of the corners flooring the input point to the input point itself with the random-generated gradient vector.
Now if the input point were a whole number, such as the xyz coordinates of a texture you want to create, the dot product would always return 0, which would give you a flat noise. So instead, we use
inci, incj, inck
as an alternative index. Yep, just an index, nothing else.Now returning to question 1, there are two methods to implement Perlin's Noise:
1.Calculate the noise values separately and store them in the RGBA slots in the texture
2.Synthesize the noises up before-hand and store them in one of the RGBA slots in the texture
noise3(ni)
is the actual implementation of method 1, whilePerlinNoise3D(...)
suggests the latter.In my personal opinion, method 1 is much better because you have much more flexibility over how you use each octave in your shaders.
我对在
make3DNoiseTexture()
中使用noise3(ni)
而不是PerlinNoise3D(...)
的原因的猜测是,当您使用它时如果您希望能够直接在着色器中复制和修改PerlinNoise3D(...)
的功能。我对
ni, inci, incj, inck
背后的推理的猜测是,直接使用体积的 x,y,z 不会给出好的结果,因此通过用频率缩放噪声来代替可以独立于音量大小来调整噪声的分辨率。My guess on the reason for using
noise3(ni)
inmake3DNoiseTexture()
instead ifPerlinNoise3D(...)
is that when you use that noise texture in your shader you want to be able to replicate and modify the functionality ofPerlinNoise3D(...)
directly in the shader.My guess for the reasoning behind
ni, inci, incj, inck
is that using x,y,z of the volume directly don't give a good result so by scaling the the noise with the frequency instead it is possible to adjust the resolution of the noise independently from the volume size.