Sign in to follow this  
Steve5050

Perlin Noise

Recommended Posts

Steve5050    145
Hi, using vb.net 2003 and dx9.0c I've googled perlin noise to death,went deep in to searches and I still can't get a grasp on it.I've read that you can apply it to anything you want. I have code where a guy used a dib and was animating the noise with loops, I'm not figuring out anything with that though. All the other code I have is just throwing me. I need help. I have the improved noise 3d algorithm. How would I use it on a quad.
 Vertices(0) = New CustomVertex.PositionColored(XMIN, 0, ZMIN, Color.OrangeRed.ToArgb)
        Vertices(1) = New CustomVertex.PositionColored(XMIN, 0, ZMAX, Color.Red.ToArgb)
        Vertices(2) = New CustomVertex.PositionColored(XMAX, 0, ZMIN, Color.Red.ToArgb)
        Vertices(3) = New CustomVertex.PositionColored(XMAX, 0, ZMAX, Color.OrangeRed.ToArgb)

I've tried things like (XMIN + Noise(0.9,0.8,0.9) , stuff like that because I don't get it. Also x = XMIN + XMAX / 2 with y and z folowing the same way than just ran Noise(x,y,z) If I get some help with just this quad maybe I can get some idea on how noise is implemented. Thanks Steve

Share this post


Link to post
Share on other sites
Zaph-0    128

Could you please be a little more precise on what you want to do with it ?

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

Share this post


Link to post
Share on other sites
Steve5050    145
I wanted to make some clouds for one.
I also wanted to do noise to see other
things I could possibly use it for.
Clouds would be the main thing though.

I've been to that link and many others.
I've googled it to death,I need to know how
to implement it,that is what I'm not picking
up on.

Thanks
Steve

Share this post


Link to post
Share on other sites
Steve5050    145
I'm using dx9 as I stated in my first post.
I had seen that before and didn't see anything to
help.
I should add that I'm not using any pixel or vetex shaders
either.

Thanks
Steve

Share this post


Link to post
Share on other sites
Ebola0001    138
if you are not or can not use any vertex or pixel shaders, your options are blending several textures together with noise at varying resolutions.

sorry but without the shaders that is all you got i think

Share this post


Link to post
Share on other sites
moosedude    145
perlin noise is kind of a "plug-in and play" algorithm. You can use any noise function, or any smoothing function to perform the task; this may be what's confusing you. I've googled this kind of stuff before and some tutorials can gloss this over to the point of confusion.

animation takes place when you increment the seed value into the noise function. Perlin noise is really just a sequence of "random" numbers, and the seed value is just a pointer to the start position in that sequence.

can you post the implementation of your perlin noise function?

Share this post


Link to post
Share on other sites
Steve5050    145
Here it is,this is the improved 3d perlin.

Public Class Atmo
Private p(512) As Integer
Private permutation As Integer() = {151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180}

Public Function Noise(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
Dim iX As Integer
Dim iY As Integer
Dim iZ As Integer
Dim u As Integer
Dim v As Double
Dim w As Double
Dim a As Integer
Dim aa As Integer
Dim ab As Integer
Dim b As Integer
Dim ba As Integer
Dim bb As Integer

' Find unit cube that contains point:
iX = Int(x) And &HFF&
iY = Int(y) And &HFF&
iZ = Int(z) And &HFF&

' Find relative x,y,z of point in cube:
x = x - Int(x)
y = y - Int(y)
z = z - Int(z)

' Compute fade curves for each of x,y,z
u = fade(x)
v = fade(y)
w = fade(z)

' Hash coordinates of the 8 cube corners:
a = p(iX) + iY
aa = p(a) + iZ
ab = p(a + 1) + iZ
b = p(iX + 1) + iY
ba = p(b) + iZ
bb = p(b + 1) + iZ

' Add the blended results from 8 corners of the cube:
Return lerp(w, lerp(v, lerp(u, grad(p(aa), x, y, z), grad(p(ba), x - 1, y, z)), lerp(u, grad(p(ab), x, y - 1, z), grad(p(bb), x - 1, y - 1, z))), lerp(v, lerp(u, grad(p(aa + 1), x, y, z - 1), grad(p(ba + 1), x - 1, y, z - 1)), lerp(u, grad(p(ab + 1), x, y - 1, z - 1), grad(p(bb + 1), x - 1, y - 1, z - 1))))

End Function

Private Function fade(ByVal t As Double) As Double
Return t * t * t * (t * (t * 6.0# - 15.0#) + 10.0#)
End Function
Private Function lerp(ByVal t As Double, ByVal a As Double, ByVal b As Double) As Double
Return a + t * (b - a)
End Function
Private Function grad(ByVal hash As Long, ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
Dim h As Long
Dim u As Double
Dim v As Double
Dim g As Double

'// CONVERT LO 4 BITS OF HASH CODE
h = hash And &HF&

'// INTO 12 GRADIENT DIRECTIONS.
If (h < 8) Or (h = 12) Or (h = 13) Then
u = x
Else
u = y
End If

If (h < 4) Or (h = 12) Or (h = 13) Then
v = y
Else
y = z
End If

If ((h And 1) = 0) Then
g = u
Else
g = -u
End If

If ((h And 2) = 0) Then
g = g + v
Else
g = g - v
End If

Return g

End Function
Public Sub New()


Dim i As Long
For i = 0 To 255
p(i) = permutation(i)
p(256 + i) = p(i)
Next i

End Sub
End Class

Share this post


Link to post
Share on other sites
Steve5050    145
Ok,
I got ibebrett and moosedude asking for more information,
yet niether reply.

I still need help.
How to implement this noise.

On anything,I don't care what it is.

Just a hint, something.

Share this post


Link to post
Share on other sites
Dont bother with the noise function...just make a small noise texture and sample it a number of times and combine the results.

You generally need a pixel shader to do this in real-time however--the finxed function pieple doesnt really give you the flexibility (i guess it could be done). If you cant use shaders you might want to try other methods of making clouds.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this