Note that there are some explanatory texts on larger screens.

plurals
  1. POPerlin Noise not working
    primarykey
    data
    text
    <p>I have a bit of an issue (again) with my Perlin Noise generation. I have read multiple articles on how it works. I implemented it with the following code:</p> <pre><code>package PerlinNoise; import java.util.Random; public class PerlinNoise { private long seed; private Random rand; private float f; public PerlinNoise(long seed, float f) { this.seed = seed; this.f = f; rand = new Random(); } //interpolates generated noise public float getInterpolatedNoise(float x, float y) { float a = (int) Math.floor((double) x / f); float A = a + 1; float b = (int) Math.floor((double) y / f); //&lt;-- define the points around the point float B = b + 1; return cosineInterpolate( cosineInterpolate((float) getNoise(a, b), (float) getNoise(A, b), (float) (x - a * f) / f), cosineInterpolate((float) getNoise(a, B), (float) getNoise(A, B), (float) (x - a * f) / f), (float) (y - b * f) / f); //&lt;-- interpolates everything } //cosine interpolation private float cosineInterpolate(float a, float b, float x) { float f = (float) ((1f - Math.cos(x * Math.PI)) * .5f); return a * (1f - f) + b * f; } //generates random noise value between -1.0 and 1.0 private float getNoise(float x, float y) { if(y &lt; 0) { rand.setSeed((long) (332423 * (Math.sin(Math.cos(x) * x) + Math.cos(Math.sin(y) * y) + Math.tan(seed)))); }else{ rand.setSeed((long) (432423 * (Math.sin(x) + Math.cos(y) + Math.tan(seed)))); } float n = (float)(((float)rand.nextInt(255) - (float)rand.nextInt(255)) / 255.0f); return n; } </code></pre> <p>And here is when I add all my octaves together:</p> <pre><code> //performs perlin noise function public static float[][] getPerlinNoise(int octaves, long seed) { float[][] noise = new float[Main.csX][Main.csY]; for(int z = 0; z &lt; octaves; z++) { float f = (float)Math.pow(2, z); PerlinNoise oct = new PerlinNoise(seed, f); for(int y = 0; y &lt; Main.csY; y++) { for(int x = 0; x &lt; Main.csX; x++) { noise[x][y] = (noise[x][y] + oct.getInterpolatedNoise(x * f, y * f)) * (float)Math.pow(p, z); //&lt;- pumps out numbers between -1.0 and 1.0 } } } return noise; } </code></pre> <p>Sorry for the giant code dump there. The code all works when I run it, but I don't get Perlin noise. I just get this:</p> <p><img src="https://i.stack.imgur.com/iTq3U.png" alt="Definitely not Perlin Noise.."></p> <p>This is more of blury, blended noise than anything else. I get very similar results even when I add more octaves and/or ramp up the persistence. I used <a href="http://freespace.virgin.net/hugo.elias/models/m_perlin.htm" rel="nofollow noreferrer">this</a> article as a reference for building the code (and also <a href="http://webstaff.itn.liu.se/~stegu/TNM022-2005/perlinnoiselinks/perlin-noise-math-faq.html" rel="nofollow noreferrer">this</a> one). So if anyone has any ideas as to why this isn't working, please comment/answer. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload