Noise Functions

Hi,



I’ve been looking at noise functions and procedural textures the last few days.



Basically my noise functions follow this basic signature:



float noise1d(float x);

float noise2d(float x, float y);

float noise3d(float x, float y, float z);





Using the information from here I’ve managed to implement Perling noise.



Now my actual problem isn’t the Perling noise I’ve implemented (it’s probably incorrect but I’ll be able to sort it out), it’s the fact I have no clue what input’s I’m meant to use or what to do with the output!  :stuck_out_tongue:



Right now all I’m doing to create an image is looping through each pixel and calling the noise function and setting that pixels noise to the returned value, ala:



for (int x = 0; x < width; x++) {
    for (int y = 0; y < height; y++) {

        byte pixel = (byte) 255 * noise2d(x, y);

        imageBuffer.put(pixel);
        imageBuffer.put(pixel);
        imageBuffer.put(pixel);
    }
}



This creates a grey scale image that looks kinda correct but I know this isn't how I'm meant to generate textures.  I do get the feeling I'm meant to use the returned value to set the pixels value but I'm at a loss as to where to get the input.

Am I meant to be using the location of the pixel in world space or something?  :?


- Chris

to be honest i don't understand where you are stuck. what i understood: you have your noise functions implemented and you can generate an image. do you have problems in creating a texture out of that image/buffer or is your problem of other nature?  :expressionless:

Hi,



Basically I have no idea how to use the algorithm  :frowning:



I’m able to generate an image but it looks nothing like the images most people show when they use Perlin noise.



ie.  From the site I linked:



http://freespace.virgin.net/hugo.elias/models/p_128.jpg

EDIT: Removed the Hot link



My generated images look nothing like that  :’( (Can’t show one as I’m at work right now)



So I’m guessing I’m using the algorithm wrong.



For a 128 x 128 image thats 16384 pixels, so surely you don’t call the noise function to set each individual pixel colour (which is what I’m currently doing and getting crappy results)?




  • Chris
Gentleman Hal said:

So I'm guessing I'm using the algorthim wrong.

For a 128 x 128 image thats 16384 pixels, so surely you don't call the noise function to set each individual pixel colour (which is what I'm currently doing and getting crappy results)?


With the noise functions you're using, that is indeed what you want to do.  You're probably using the wrong X/Y scale.  Try using noise2d((float)x/width, (float)y/height).

--Andrzej

about the page you used as reference [wikipedia]:

Incorrectly titled "Perlin noise". It's value noise. Value noise is similar enough that this article is a great introduction to what noise is all about.


maybe this helps a bit: http://www.cs.cmu.edu/~mzucker/code/perlin-noise-math-faq.html#algorithm

from the link above:
So all you have to do is call the noise function for every pixel you want to color, and you're done. Probably.

but also:
An interesting consequence of all of this is that the noise function becomes zero when x and y are both whole numbers.

x and y are the (float) parameters of the noise function

i have to admit i didn't read much about the perlin noise before, so excuse my ignorance :)

As promised here they are!  :slight_smile:







Rounded Integer Noise using a seed of 1.  This is basically completely random noise that is useless by itself but forms the base of the other (currently implemented) noise functions.







Interpolated Noise using the same function as above as the base.







Smooth Noise using the top noise function as the base.  As you can see looks a little fuzzy when just combined with Rounded Integer Noise.







Interpolated Smooth Noise using the above noise functions.





I haven’t got round to implementing Perlin Noise yet, but I will do hopefully this weekend.

Heres the last image zoomed in to double the size.  You can see this image is the same as the bottom left hand quarter of the last image in the above post  :slight_smile:







Ok, think I might be getting a little carried away now  :stuck_out_tongue:



I post more once I get some impressive images done!

sfera said:

about the page you used as reference [wikipedia]:
Incorrectly titled "Perlin noise". It's value noise. Value noise is similar enough that this article is a great introduction to what noise is all about.


maybe this helps a bit: http://www.cs.cmu.edu/~mzucker/code/perlin-noise-math-faq.html#algorithm


Ah righty, thanks.  That probably explains why my images look different  :P

I'm trying to create a procedural texture generator for jME.  Which is why I came up with the noise interface I gave in the first post.  The idea is to have a  generator class that can take any number of noise interfaces and chain them together to create the final texture.

Now I know the noise function is meant to be called for each pixel so thats cool.

ey6es said:

With the noise functions you're using, that is indeed what you want to do.  You're probably using the wrong X/Y scale.  Try using noise2d((float)x/width, (float)y/height).

--Andrzej


Is the x and y in your post the coordinate of the pixel?

i.e In a 128 x 128 image the first pixel would be (1, 1) and the last would be (128, 128)

If not then I still have no idea where to get the float x, y, z values for each pixel from  :(

Perhaps I could use the 1d noise function to generate the values for the 2d/3d noise functions?  That way I could just take a single float from the user as the 'seed'...

Basically I have never done anything about procedural texture / noise before and I'm trying to learn (for the benefit of all!), so if anyone has some nice input on the way to take procedural textures forward in jME please let me know.



Also I apologise for the bad explanation of my problem!


- Chris

I recently made a libnoise JNI wrapper for Java using SWIG. It works well as far as I tested it, although I haven’t yet bothered compiling the native library for Linux nor have a touched more than a tiny fraction of it’s complete functionality. I did manage to follow the tutorial on the website for the terrain texture generation though and I got the same results, so I must be doing somewhat okay.

Thanks for the links guy's I really seem to be getting somewhere now!  :smiley:



I'll post some screenies soon (regardless if anyone's interested!  :P)

i'm looking forward for those screenies :wink: