 Home
 » Viewing Profile: Posts: ProgrammerGuy123
ProgrammerGuy123
Member Since 06 May 2012Offline Last Active Nov 02 2013 03:05 PM
Community Stats
 Group Members
 Active Posts 11
 Profile Views 1,642
 Submitted Links 0
 Member Title Member
 Age Age Unknown
 Birthday Birthday Unknown

Gender
Not Telling
User Tools
Latest Visitors
Posts I've Made
In Topic: Hovercraft Physics
21 July 2012  07:53 PM
In Topic: Whats Wrong With My Perlin Noise Function?
31 May 2012  05:13 PM
In Topic: Whats Wrong With My Perlin Noise Function?
31 May 2012  03:56 PM
byte[,] temp = new byte[height, width]; for(int x = 0; x < width; x++) { byte value = (byte)((PerlinNoise2D((double)x) * 64) + 64); temp[value, x] = 1; }
This is exactly why I was using integers in my pervious attempts for everything and not decimals. Is there any way I could efficiently convert the integers into decimals and back into inegers again? Or should I go back to the way I was doing it and have everything calculated with integers. Right now I'm multiplying the perlin value by 64 just for testing as you can see then adding the same value to get rid of any negatives. But like you said I'm only going to get values based on integer boundries so what should I do?
In Topic: Whats Wrong With My Perlin Noise Function?
31 May 2012  02:19 PM
You have revised it to be even more wrong than before. By just calling Next without the seeding operation, you guarantee you get a different value for any given input point each time it is called. Random isn't really what you want to use here. You want a hash function, that correlates an input, x, to an output, y. The hash needs to ensure that the hash for x+1 is in no way correlated to the hash for x, so that patterns do not appear in the output.
jtippets linked to the reference implementation for Perlin noise. It might be a good idea to look and see how it does hashing, interpolation, etc...
Also I note that you seem to be using a lot of integer coordinates and values. There is a problem with this. The algorithm you are using will generate pseudorandom values at integer coordinates, but since you never sample the "between" points (noninteger), the result is probably going to look a great deal like white noise.
Ok so I tried to fix a lot all of these problems but the function is still acting up and I'm really confused on why because I scrapped the whole thing to use double values instead of integers and I even took the complete RNG from this article about perlin noise. This solves the problem of having to use hash tables because now I'll get a random number where x and x+1 is a completely different number. However now it seems to return negative values which makes absolutely no since considering I use his RNG not .NET's. Also the InterpolatedNoise method is almost the exact same I'm just not smoothing the values because I want to simplify it. Then there is the CosineInterpolate method. To me logically this must be the reason for my negative values because as stated before I took the entire RNG from the article so it can't be that. The CosineInterpolate method was taken from this article.
I've made no methods all the methods responsible for generating perlin values are from reliable sources. What is going on?
public double PerlinNoise2D(double x) { int octaves = 1; double freq = 16; double amp = 1; double total = 0; for(int i = 0; i < octaves; i++) { total += InterpolateNoise(x * freq) * amp; } return total; } double InterpolateNoise(double x) { int xInt = (int)x; double xFrac = x  xInt; double v1 = Noise(xInt); double v2 = Noise(xInt + 1); return CosineInterpolate(v1, v2, xFrac); } double Noise(int x) { x = (x<<13) ^ x; return ( 1.0  ((x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0); } double CosineInterpolate(double a, double b, double x) { double f = (1  Math.Cos(x * Math.PI)) / 2; return (a * (1  f) + b * f); }
In Topic: Whats Wrong With My Perlin Noise Function?
31 May 2012  08:50 AM
If I recall correctly, each time around the main loop you're meant to double the frequency and decrease the amplitude. You seem to be keeping them constant.
The values were not changing because I only had one octave for simplicity therefor there was no need for them to change.
You are also using Random() wrong.
You should initialize it once, with a single seed of your choosing, and then just continuously call "next" to read out the random value.
This was a mistake on my part I was thinking I needed a random value based on "x" which mean if "x" is ever the same it should generate the same number.
I have revised the code I think to fix this problem but no luck. First I need just one octaves to work then I can generate more and add them up but for now I'm focusing on one octave which you will see in my code:
public int PerlinNoise2D(int x) { int total = 0; int octaves = 1; //only one octave for simplicity for(int i = 0; i < octaves; i++) { int freq = 16;//16 for simplicity I only have one octave so it doesn't need to change int amp = 1; //1 for simplicity again ^^^ total += InterpolateNoise(x * freq) * amp; } return total / octaves; } int InterpolateNoise(int x) { int v1 = random.Next(64); int v2 = random.Next(64); return CosineInterpolate(v1, v2, x, 16); // the 16 is from the frequency } int CosineInterpolate(int a, int b, int x, int length) { return (int)((1 + Math.Cos(3.1415f * x / length)) / 2 * (a  b) + b); }