- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近一直在处理 perlin 噪声,在我使用的 tile 引擎中实现它时,我注意到 perlin 噪声函数产生了“ block ”,如下图所示。每个像素都是 500 x 500 数组中的另一个不同位置,该数组从 perlin 噪声函数返回。
在此示例中,持久性为 0.5, Octave 音阶计数为 5
当进一步演奏时,我拥有的 Octave 音程越多, block 就越大。
这是我用来调用 perlin 噪声函数的代码:
PerlinNoise p = new PerlinNoise();
//returns a float[][] array of 500 by 500
p.GeneratePerlinNoise(p.genWhiteNoise(500, 500), 5, (float) 0.1);
PerlinNoise 类
导入java.util.Random;
public class PerlinNoise {
Random r;
public PerlinNoise() {
r = new Random();
}
public void setSeed(long seed) {
r.setSeed(seed);
}
public void printOutArray(float[][] arr) {
for(int i = 0; i < arr.length; i++) {
for(int n = 0; n < arr[0].length; n++) {
System.out.print(arr[i][n] + ", ");
}
System.out.print("\n");
}
}
public void printOutTerrain(float[][] arr) {
for(int i = 0; i < arr.length; i++) {
for(int n = 0; n < arr[0].length; n++) {
float a = arr[i][n];
if(a < 0.4) {
System.out.print("W");
} else {
System.out.print("L");
}
}
System.out.print("\n");
}
}
//-------------------------------------------------------------//
float[][] genWhiteNoise(int width, int height) {
float[][] noise = new float[height][width];
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
noise[y][x] = r.nextFloat();
}
}
return noise;
}
float[][] genSmoothNoise(float[][] baseNoise, int octave) {
int height = baseNoise.length;
int width = baseNoise[0].length;
float[][] smoothNoise = new float[height][width];
int samplePeriod = 1 << octave; //calculates 2^k
float sampleFrequency = (float) (1.0/samplePeriod);
for(int i = 0; i < height; i++) {
int sample_i0 = (i / samplePeriod) * samplePeriod;
int sample_i1 = (sample_i0 + samplePeriod) % height; //wrap around
float vertical_blend = (i - sample_i0) * sampleFrequency;
for(int n = 0; n < width; n++) {
int sample_n0 = (n / samplePeriod) * samplePeriod;
int sample_n1 = (sample_n0 + samplePeriod) % width; //wrap around
float horizontal_blend = (n - sample_n0) * sampleFrequency;
//blend the top two corners
float top = Interpolate(baseNoise[sample_i0][sample_n0],
baseNoise[sample_i1][sample_n0], horizontal_blend);
//blend the bottom two corners
float bottom = Interpolate(baseNoise[sample_i0][sample_n1],
baseNoise[sample_i1][sample_n1], horizontal_blend);
//final blend
smoothNoise[i][n] = Interpolate(top, bottom, vertical_blend);
}
}
return smoothNoise;
}
float[][] GeneratePerlinNoise(float[][] baseNoise, int octaveCount, float persistance)
{
int height = baseNoise.length;
int width = baseNoise[0].length;
float[][][] smoothNoise = new float[octaveCount][][]; //an array of 2D arrays containing
//generate smooth noise
for (int i = 0; i < octaveCount; i++)
{
smoothNoise[i] = genSmoothNoise(baseNoise, i);
}
float[][] perlinNoise = new float[height][width];
float amplitude = 1.0f;
float totalAmplitude = 0.0f;
//blend noise together
for (int octave = octaveCount - 1; octave >= 0; octave--)
{
amplitude *= persistance;
totalAmplitude += amplitude;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
perlinNoise[i][j] += smoothNoise[octave][i][j] * amplitude;
}
}
}
//normalisation
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
perlinNoise[i][j] /= totalAmplitude;
}
}
return perlinNoise;
}
//linear average between two points
float Interpolate(float x0, float x1, float alpha)
{
return Cosine_Interpolate(x0, x1, alpha);
}
//Linear Interpolation
float Linear_Interpolate(float x0, float x1, float alpha)
{
return x0 * (1 - alpha) + alpha * x1;
}
//Cosine interpolation (much smoother)
float Cosine_Interpolate(float x0, float x1, float alpha)
{
float ft = (float) (alpha * 3.141592653589);
float f = (float) ((1 - Math.cos(ft)) * 0.5);
return x0*(1-f) + x1*f;
}
}
所以重申我的问题:为什么我的 perlin 噪声函数的行为方式是这样的,就像只生成 block 中的空间一样?
最佳答案
所以要解决这个问题,我所要做的就是交换 genSmoothNoise() 方法中的 vertical_blend 和 horizontal_blend 变量。休息后你注意到的是惊人的
关于java - Perlin 噪声生成无法正常运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16973848/
我正在研究我的论文,以构建乐谱(乐谱)识别系统。这是我的输入文件: 这是一些预处理和去除五线谱后的结果: 我在这里遇到的问题是,在五线谱删除步骤之后出现了一些超小的、不需要的“点”。这些点/噪声与实际
这可能是一个愚蠢的问题(当然),但对于我已阅读/发现的所有内容,没有一个与我想做的相匹配......这是 GIT 的基本情况。 为了使我的情况更简单,我有两个分支: - master(主要分支) -
我的项目: 我正在开发一辆带有 3 轴加速度计和陀螺仪的槽车,试图估计汽车姿态(x、y、z、偏航、俯仰),但我的振动噪音有一个大问题(而汽车在例如,加速度计的噪声值在 ±4[g](其中 g = 9.8
我正在尝试实现 2D Perlin 噪声来创建类似 Minecraft 的地形(Minecraft 实际上并不使用 2D Perlin 噪声)而没有悬垂或洞穴之类的东西。 我这样做的方式是创建一个 [
我有一个代表图像的二维数组。我必须向图像添加 RMS 2 单位的背景高斯噪声。我不熟悉噪声的 RMS 测量以及如何添加它。您能否告诉我如何执行此操作? 最佳答案 按照我的理解,您想要在每个像素处添加遵
更新:正式问题列表: 2D 噪声实现的浮点值(输入参数和输出)代表什么? - 部分回答,输入是坐标。输出怎么样?另外,我可以使用我的整数作为坐标的 float 吗? 1.0、122.0 等? 在 2D
我正在尝试使用 Perlin 噪声生成地形。我了解如何使用笛卡尔坐标生成它,但无法完全理解它在球体上的工作方式。我知道您可以将 2D 表面投影到球体上,但失真不会扰乱噪声分布吗?要在球体表面生成均匀噪
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我正在尝试将 fBm 实现到行星的球体上。为了创建我的球体,我将其从立方体转换为此类。不幸的是,生成的 fBm 显示为镜像补丁。此外,它只在 2 个面上执行(包装其他面的值)。当呈现为 sphere
我想知道为什么在 Simplex 推出后,Perlin 噪声至今仍然如此流行。单纯形噪声是由 Ken Perlin 自己制作的,它应该取代他的旧算法,该算法对于更高的维度来说速度较慢,但质量更好(
我终于设法为 Love 2D 编写了 Perlin 改进噪音的工作 Lua 版本。但是,当我运行它时,我得到了这个: 我想这很好。但我想要看起来更像这样的东西: 我怎样才能做到这一点? 最佳答案 第一
我终于设法为 Love 2D 编写了 Perlin 改进噪音的工作 Lua 版本。但是,当我运行它时,我得到了这个: 我想这很好。但我想要看起来更像这样的东西: 我怎样才能做到这一点? 最佳答案 第一
我正在尝试处理我从采样源数据行(Java Sound API)获得的字节数组。如果我将字节数组与小数相乘,播放流时会产生噪音。 在播放声音之前,我将立体声 wav 文件分成左右声道。这很好用。但是,如
对于我正在进行的元胞自动机项目,我需要使用不同的算法和技术随机生成二维 boolean 数组。目前,我在应用程序中只有一种随机化类型——循环遍历数组中的每个单元格并生成一个随机 double 变量,然
我叫 Chris,正在开发我的第一个 Java 游戏。到目前为止,我已经创建了一个基于图 block 的 2D 游戏,但是我的关卡是以这样一种方式完成的,如果我创建一个图像并且它全是绿色,那么绿色就代
block 之间的平滑 所以我一直在开发一个统一的游戏,想将我的世界从 150x150 的 map 扩展到一个看似无限的程序世界。我的计划是以Perlin Noise为基础,使用0-1的不同值来判断地
(此程序的依赖项:vector --any 和 JuicyPixels >= 2 。代码可用作 Gist。) {-# LANGUAGE Haskell2010 #-} {-# LANGUAGE Ban
我最近用 C# 编写了 Diamond-Square 过程生成算法的实现。但是,生成的噪声在所处理的“正方形”之间具有非常明显的边界。伪代码看起来像这样 gen() { This takes
我已经尝试了所有方法并阅读了我在互联网上看到的关于 Perlin Noise 或 Simplex Noise 的每一个链接,甚至剖析了一些我认为工作正常的 Javascript 示例。 但我仍然得到看
我在任何方面都不精通视频压缩,但目前正在从事一个使用 H.264 压缩残差图像的项目 我的问题更多是关于视频编码器的一般性问题。据我了解(正如维基百科所解释的那样), block 运动补偿编码器将当前
我是一名优秀的程序员,十分优秀!