PDA

View Full Version : mvNoise, Perlin noise - problem



Darkhog
28-05-2013, 11:57 AM
I've looked into making some perlin noise for my procedurally generated shooter and found this: http://www.pascalgamedevelopment.com/showthread.php?5632-perlin-noise-delphi-source-code

Unfortunately unit given here requires some strange mvMath unit, which I wasn't able to find. Any help? Game is at stage where replacing unit isn't problem, so if you have any other Perlin noise generation unit, I'd be happy to use it.

laggyluk
28-05-2013, 02:29 PM
in glscene there is a unit for that. googled 'glscene perlinnoise.pas'
http://read.pudn.com/downloads28/sourcecode/windows/opengl/88103/Source/Base/PerlinNoise.pas__.htm

Darkhog
28-05-2013, 02:37 PM
Yeah, but wouldn't I then need to download whole glscene? I don't need it. All I need is 2D perlin noise, as it is for 2D game, anyway.

SilverWarior
28-05-2013, 09:07 PM
Hi!
At the time of 2nd PGD mini challenge I was fidling myself with Perlin Noise generation and I made my own algorithm similar to Perlin Noise.
The biggest problem is that code which is used for combining seperate octave textures into one tends to exeds its limits sometime (value for certain pixel can exceed 255 which results in parts of the texture to become negative).

I was also planning on adding support for further postprocessing of Perlin Noise result to get better results in the end.
For instance I use perlin noise for generating heightmap. Height of the map can be between 0 and 255.
I consider height range of 0-8 as seabed so I use postprocessing to smoth (almost level) it out.
I consider height range pf 9-10 as sand beaches so I try to make them smoth and nicely sloped.
....
I gues you got the point.
I was also thinking of controlling this terain smothening with another texture for creating biomes etc.
Unfortunately I haven't done anything on postprocessing so far as I was running out of time for 2nd PGD mini competition and later I havent returned to this.

I have ability to specify seed nuber when I'm starting but I'm not sure if it would alow me making infinite Perlin Noise textures.
Oh I was planning to use custom Random number algorithm implementation to gain the ability to have threadsafe random number generation which isn't posible using Delphi random number generator.

Now if you wan't I could go and try to continue my work where I left of. I hope I comented my code :(

SilverWarior
28-05-2013, 09:30 PM
As I feared I haven't comented my code so I'll first have to figure out how it currently works >:(

Darkhog
28-05-2013, 09:45 PM
I have ability to specify seed nuber when I'm starting but I'm not sure if it would alow me making infinite Perlin Noise textures.

Not infinite, in chunks. The trick is to have x/y offset variables and to waste first x/y random numbers and create actual bitmap.

I.e. if you want to generate chunk you set x offset (for simplifying, let's assume that chunks are going in straight line) to chunksize*number of chunks already generated. Then, based of value of xoffset you "waste" first several columns. In pseudocode (for simplicity chunks are white noise):


function generate_chunk(rndseed,xoffset, yoffset,chunksize:Integer)
{
x,y,dump:Integer
Seed=rndseed
for x=0 to xoffset+chunksize
{
if x<=xoffset {dump = random(256); continue}
for y=0 to yoffset+chunksize
{
dump=random(256)
if y<=yoffset { continue}

Bitmap[x-xoffset,y-yoffset]=RGB(dump,dump,dump)
}
}

}


I know that much, just don't know how to apply it into real perlin noise app ;).

And yes, if you can I'd appreciate if you could make it work. All I need is simple Perlin noise.


The biggest problem is that code which is used for combining seperate octave textures into one tends to exeds its limits sometime
Simple

if value>255 then value:=255;
at the end of combining code, but before putting it into byte array should help with that.

SilverWarior
28-05-2013, 10:39 PM
Not infinite, in chunks. The trick is to have x/y offset variables and to waste first x/y random numbers and create actual bitmap.

I.e. if you want to generate chunk you set x offset (for simplifying, let's assume that chunks are going in straight line) to chunksize*number of chunks already generated. Then, based of value of xoffset you "waste" first several columns. In pseudocode (for simplicity chunks are white noise):

I certainly wouldn't use your approach. Why? As you say "wasting" random numbers would be wasting CPU time. Are you aware that random number generation is one of the bottlenecks of the Perlin Noise algorithm? And other is mothening the textures.

If you don't belive me just go and create several thousands of random numbers and see how much time would your computer need to do that. And if you think that 100x100 ofset would mean you would be wasting 10000 random generated numbers. NOT a good idea.

For solving this problem it would be wiser to use one of custom Random Number generation algorithms which alow takind additional imputs which are then used during random number generation. Problem with most of such algorithm is that when theese inputs numbers becomes large the random number generation becomes more eratic.




And yes, if you can I'd appreciate if you could make it work. All I need is simple Perlin noise.

OK then I'll get to work as soon as I find some time. Anwhay I still have a gime in mind which will use this.



Simple

if value>255 then value:=255;
at the end of combining code, but before putting it into byte array should help with that.

And the result would be flatheaded mountains. So unrealistic.
At the time I was thinking of finding highest point and then normilize whole texture so that this highest point doesn't exceed the limit.
Oh now I remembered that I was also planning to do a complete rewite of my algorithm. :(
Storing values in 2D array would be a problem for my postprocessing functions as I will require data to be soreted by height for instance. This means storing them in a list as nodes (Height, X and Y position). This will result in need for more memory.
Gues I should start searching for suitable Random number generator algorithm which supports accepting aditional parameters (X,Y position). This way I would be able to generate my map in chunks.

But first let my try to get that glscene algorithm working so that you will at lest have some basic random map generation available to work further on your game.

Darkhog
28-05-2013, 11:44 PM
And the result would be flatheaded mountains. So unrealistic.
Then apply some Gaussian blur to this.

Anyway, do however you want, but I'd like to be able to generate chunks of texture (it certainly is possible as Minecraft, Minetest-c55 and other mineclones features semi-infinite world and without making it with chunks it wouldn't work).

And don't bother with glscene thing. I can wait for proper solution (have other things to do in meantime anyway, like writing state machine and collision system).

SilverWarior
28-05-2013, 11:56 PM
I'm checking GLscene becouse I belive it has implementation of Perlin Noise which can use offset imputs. That is what you need.

Carver413
29-05-2013, 02:01 AM
Paul gave me a perlin noise unit. you can find it in this thread
http://www.pascalgamedevelopment.com/showthread.php?13312-Carver-Explorer
works great

User137
29-06-2013, 03:51 PM
I happened to come across simplex-noise, and still unsure how fitting it is for gaming. It claims to be kind of simplified and optimized replacer for Perlin noise. Actually Simplex is made by Perlin himself in 2001.
http://en.wikipedia.org/wiki/Simplex_noise
Some Java source
http://staffwww.itn.liu.se/~stegu/simplexnoise/SimplexNoise.java

Also, now that i think about it, i think this is 4D, where time is 4th dimension:
http://mrl.nyu.edu/~perlin/homepage2006/simplex_noise/index.html

Carver413
29-06-2013, 04:14 PM
I would be very interested in a pascal version of simplex as it supports up to 6D and it is needed in order to create seemless textures but I dont know much about java.
http://www.gamedev.net/blog/33/entry-2138456-seamless-noise/

laggyluk
30-06-2013, 05:13 AM
I've translated some 3d simplex noise implementation to pascal : http://laggyluk.com/?p=86

phibermon
30-06-2013, 05:31 PM
If your shooter is already procedural and you wish to you perlin noise for say, a graphical effect then you should pre-generate a seemless perlin texture and then do texture fetches with wrap around coordinates. With a non even scale iterator you get all the smooth interpolation properties of perlin noise without the CPU hit for generation.

If you really need true noise, perlin noise is an incredibly simple algorithm, you should be able to implement it yourself just by reading the wiki page.

If you don't try to do these things then you rob yourself of an opportunity to learn more :)

Darkhog
30-06-2013, 05:59 PM
While my problem is resolved, I need to point out that I rarely understand wiki pages on algorithms, as they usually involve some complex math. I also prefer tutorial-like resources to barebones, dry documentation. But I understand what you mean.

SilverWarior
30-06-2013, 06:27 PM
I must agree with Darkhog that Wiki pages sometimes doesn't offer easy understandable explanations.
While the base idea of wiki pages is to provide easy explanations to comon pepole I find it more and more often that they are written for more scientific audience (lots of scientific teminology). This of course make wiki explanations les understandable and actually forces you to read explanations for all that scientific terminology.
So in the end you can quickly wind up reading half a dozen wiki pages just to understand one thing.

Now as for Perlin noise generation the wiki article didn't helped me much to understand how it works. But I did managed to understand it quite good after readin Ken Perlins oficial explanation of Perlin Noise Generation. You can find it here:
http://www.noisemachine.com/talk1/
Another two great sites explaining how perlin noise works are:
http://freespace.virgin.net/hugo.elias/models/m_perlin.htm
http://webstaff.itn.liu.se/~stegu/TNM022-2005/perlinnoiselinks/perlin-noise-math-faq.html

User137
02-07-2013, 07:59 PM
I've translated some 3d simplex noise implementation to pascal : http://laggyluk.com/?p=86
I appreciated the effort, but i still translated my own ;) Your version was procedural, and didn't support 2D or 4D.
https://code.google.com/p/nxpascal/source/browse/trunk/src/nxNoise.pas

laggyluk
02-07-2013, 11:56 PM
I appreciated the effort, but i still translated my own ;) Your version was procedural, and didn't support 2D or 4D.
https://code.google.com/p/nxpascal/source/browse/trunk/src/nxNoise.pasi did it for my own use :P to make it 2d you pass z = 0

User137
03-07-2013, 02:25 AM
4D is fun too when you want to see 3-dimensional terrain bubble around like plasma 8) At first i thought the extra dimension would be most feasible to use as seed, IE. for 2D world i'd use 3-dimensional noise where Z = seed. But i realized that i could alter the permutation table instead.

So that's what i did now, adding seed: int64 parameter to constructor. Then masking the permutation bytes with xor and seed. Basically what it does is:

Imagine seed was 4 bits (it's 64 bits really), for example seed=0110.
Then i have original permutation byte-array, going for example
100011011100... then make the seed wrap to same length:
011001100110... and finally XOR them for final permutation:
111010111010
And final touch, because seeds 0 through 1000 still showed hardly any change, i multiply seed at beginning with some constant 85123154182917 number, to force more bit-changes. Looks fine for now.

Carver413
03-07-2013, 04:26 AM
why put that multipler in there at all. maybe sometimes you want only subtle changes or you want to choose a different multiplier. anyway thanks for the post, I'll be sure to check it out when I have some time.

pitfiend
12-07-2013, 05:47 AM
Maybe a bit late to ask, but, how Perlin Noise is different than a Plasma Cloud? Is there some advantage to use Perlin Noise?

SilverWarior
12-07-2013, 06:48 AM
Maybe a bit late to ask, but, how Perlin Noise is different than a Plasma Cloud? Is there some advantage to use Perlin Noise?

The main diferences between Perlin Noise and Pasma Cloud are:
1. In Plasma Cloud you put subsequent pixels between the other two pixels while in Perlin Noise you actually place subsequent pixels moved a bit based on pseudorandom gradiant vector.
2. In Perlin Noise you usually pregenerate premutation table and use thet for making random textures for each octave and thus removes the need to be constantly generating random numbers. This in the end gives you better perfornamce since random number generation is quite slow.
3. In perlin noise you can define custom size and presistance for each octave with which you get fine controll on final texture.

pitfiend
12-07-2013, 06:52 AM
The main diferences between Perlin Noise and Pasma Cloud are:
1. In Plasma Cloud you put subsequent pixels between the other two pixels while in Perlin Noise you actually place subsequent pixels moved a bit based on pseudorandom gradiant vector.
2. In Perlin Noise you usually pregenerate premutation table and use thet for making random textures for each octave and thus removes the need to be constantly generating random numbers. This in the end gives you better perfornamce since random number generation is quite slow.
3. In perlin noise you can define custom size and presistance for each octave with which you get fine controll on final texture.
So, if I feed a plasma generator with a precalculated table of permutation and allow the custom size and persitence, I could achieve similar results? Also want to be clear that you can generate plasma in many ways.