Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Perlin Noise Problem

Author
Message
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 11th Oct 2010 02:07 Edited at: 16th Oct 2010 23:52
I found this site: http://freespace.virgin.net/hugo.elias/models/m_perlin.htm

For those who don't know what Perlin Noise is:
http://en.wikipedia.org/wiki/Perlin_noise

Can't seem to figure out what is wrong with it. Image is attached.

Code:


Code Snippet 2:


Found from another website:


Tried almost everything I could think of.

Any help would be appreciated.

Thanks

Edit:

Added pictures of finished algorithms as I finish them. Check the posts below.
old_School
16
Years of Service
User Offline
Joined: 29th Aug 2009
Location:
Posted: 11th Oct 2010 02:10 Edited at: 11th Oct 2010 02:12
Might try testing the code by setting it to a specfic sound then go for random

Edit:
Not sound I mean image.

Edit:
Scratch that I did mean sound but I also dont see were it has a path or anything to detect sound files. Looks like its missing alot of construts. Maybe its just me.
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 11th Oct 2010 02:11 Edited at: 12th Oct 2010 02:17
@old_School - What exactly do you mean?

Edit:
@old_School - Perlin Noise is for Images. It generates noise, smooths it, and the perlin noise algorithm would output something like this:



The input image is generated random noise. It is generated to output different results everytime.

Posted Wiki.
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 12th Oct 2010 21:59
No one? Hmm thought someone might know something about perlin noise. There are a lot of examples out there...mine is just one of those that isn't working. lol
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 12th Oct 2010 22:41
DarkCoder once wrote an awesome perlin noise function:


What that function does, is first create a bunch of random memblocks, representing a grid of a certain resolution. For example, if startingres=512, and octaves=8, that would create grids with random numbers in each spot, of resolution: 512x512, 256x256, 128x128, 64x64, 32x32, 16x16, 8x8, and 4x4. Then, the program adds all of those together. Thats where the interpolation comes in - for example, the 4x4 grid has to be interpolated up to 512x512. Then, you add all the interpolated values together, to get the final result.


What you're doing... doesn't look like its that. Not that i thoroughly read through it (and I can't compile it :\)

DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 12th Oct 2010 22:55 Edited at: 16th Oct 2010 02:23
@Neuro Fuzzy - I only found like two examples on the forums after searching for quite a bit. I haven't found this one though. My latest example should compile. Thanks 4 trying..might need matrix01util. Fixed my example. Try it now.

This noise seems a lot more controlled.

I did want to get my demo working though. I couldn't figure out most of the demos I did find.

Thanks for the snippet. ^^

Edit:

This is interesting. It seems he generates noise first. I didn't know that. Hmm each octave (sample) is stored in a memblock.

Ahhh I don't know what mod is. What is that? I looked it up and it is confusing.

DarkCoder made one hell perlin noise example. It is going to take a very long time to figure it out. I don't know if I can. I'm trying to make mine as simple as possible.
sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 13th Oct 2010 02:50
Increase the value of Persistence#, then you'll keep trying until you suss it out
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 13th Oct 2010 03:02 Edited at: 13th Oct 2010 03:05
@sladeiw - Tried different values. There are acceptable values on the website I posted.

I did manage to get Diamond Square to work. Now I just have to get Perlin Noise to work. Perlin Noise is more flexible and has more variation then Diamond Square so I will use Perlin Noise.

Here is Diamond Square:



I am going to rework diamond square to work for different algorithms.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 16th Oct 2010 00:26
Ah! I'll try to explain the snippet to you. I have a need to create 3d perlin noise and evaluate it at certain points, so I took a look back at this post and realized I didn't really understand the interpolation. I do now, and let me explain it to you


O rite, 1st, "mod" is the modulo function. Basically... Remember in elementary school, when you would write 3/2=1R1. mod returns the remainder. Basically:
a=b*k+c. Given a and b, find the largest k and smallest c, where k is a whole number. C is the remainder, and C is a mod b (this definition takes into accounts floats, so 3.1 mod 1.5=.1)

Cubic interpolation takes in four values, and interpolates between the second and third value, given a value *inbetween 0 and 1*. Any float modulo 1.0 will be inbetween 0 and 1. That number represents the distance from the last whole point (which would be considered an index on the memblock grid).

All "memblockX#" and "memblockY#" are is the distance from the last whole grid area, for which noise data exists, and this is the value used to interpolate.

So, the function gets interpolants of four rows, like this:
--*--
--*--
--*--
--*--
where a * represents the last -, + a number less than 1. The interpolated information is calculated for each *.

Then, the last line of the "bicubic sampling" section:
mHeight# = CubicInterpolate( mHeight1#, mHeight2#, mHeight3#, mHeight4#, memblockY# )
takes the information from those four *s, and interpolates between the second and third.

Then, that value is added to a "total". Strength# represents how much of that value gets added, and it decreases exponentially with "OctaveID".

height# = height# + mHeight# * Strength#
Strength# = Strength# * .5

After adding up all the interpolated interpolants, with weighting, all it does is save that data to the memblock and move on to the next thing.

I was gonna draw a diagram but I g2g like right now, i might later

DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 16th Oct 2010 02:14
@Neuro Fuzzy -

I understand what mod means now. Thanks.

I don't really know why Dark Coder would use memblocks. He could use an array with another dimension for the octave. I guess it is a good way to store the information.

In every example I have noticed Perlin Noise has taken each sample this way:



Here he is using a different way to sample for interpolation.


Attached Image Showing Diagrams For Both Snippets.

I looked at the Diamond Square example and tried to figure it out, but that algorithm is even more difficult to understand. It seems it is limited to two octaves and a preset algorithm for sampling.

I am trying to make the Perlin Noise Algorithm as simple as possible. I have tried several variations of the algorithm because not everything was explained here:

http://freespace.virgin.net/hugo.elias/models/m_perlin.htm

I just posted every variation of my perlin noise. What could I possibly be doing wrong?

A diagram would definitely be helpful!

Thanks your the greatest!

DigitalFury
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 16th Oct 2010 02:24
Updates:

Played around with the Diamond Square function to output different results:

dark coder
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 16th Oct 2010 06:14 Edited at: 16th Oct 2010 06:18
Quote: "I don't really know why Dark Coder would use memblocks. He could use an array with another dimension for the octave. I guess it is a good way to store the information."


Because if I used a 2D array then I'd have a lot of unused indices, I could have used a single 1D array and calculated the offsets myself, but I guess I found this method to be clearer.


Quote: "Here he is using a different way to sample for interpolation."


My code supports both bilinear and bicubic sampling, linear interpolation only requires 2 values and a weight, but cubic requires 4 values and a weight, and that's only for one axis. Because it's bicubic I have to do this across both axis which requires 16 samples(4*4), whereas bilinear is 4 samples(2*2), the result is that bicubic is far smoother. Notice that you only quoted the code from the first set of samples, that calculates the weight across the X axis for a Y offset of -1, I do the same 3 more times for a Y offset of 0, 1 and 2. This gives me 4 cubically interpolated heights across the X axis, I then use those heights to do a final cubic interpolation thus giving me bicubic. Similarly, if I were to do tricubic interpolation I'd need to do a total of 64 samples(4*4*4), or 8(2*2*2) for trilinear.

DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 16th Oct 2010 07:02 Edited at: 16th Oct 2010 23:49
@dark coder - So in order to bicubically interpolate you need to apply a Cubic Interpolation to those four samples.

I think I only did one linear interpolation to one sample. I guess I can adapt my code to sample the same way you do. Hopefully it works.


@ Everyone:

Updates: Fault Formation Algorithm

Finally Figured it out.

The first algorithm is the Fault Formation Algorithm.

I need to do some more work to it.

It is different from the results of other people's examples. I may need to look into why.

Here is a screenie!:


The number is the amount of interpolations.

Digital Fury
DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 16th Oct 2010 23:32 Edited at: 16th Oct 2010 23:39
Finished Voronoi Diagrams. I didn't like how it turned out so I am going to write my own.



Next algorithm is going to be the circles algorithm.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 17th Oct 2010 01:08
Cool. All the images look a bit grainy though... You might want to try "set display mode" to get a higher resolution. On a related note, you might want to check out anti-aliased lines (Phalaex had an implementation of xiaolin-wu anti-aliasing).

Also, you might wanna consider putting these in the "code snippets" section. It'd be pretty cool.

DigitalFury
15
Years of Service
User Offline
Joined: 30th Jul 2010
Location: United States
Posted: 17th Oct 2010 01:11
@Neuro Fuzzy - Blew up the images two times. That would be why. ^^ Oooo anti-aliasing sounds awesome. Will look into it. I am making a lib for an event bigger project. I might not post them. Might after the project.

Digital Fury

Login to post a reply

Server time is: 2026-07-22 12:41:52
Your offset time is: 2026-07-22 12:41:52