Author Topic: Generating Noise  (Read 3062 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Generating Noise
« on: December 15, 2010, 01:57:27 PM »

Noise functions are slightly different from Rnd functions in that when you give it a series of numbers - say 1,2,3,4,5 the values returned must have no discernable relation to each other. This is a bit more demanding requirement than seeding a Rnd function.

The value returned  depends entirely on the value passed to it . The noise function has no seeded sequence to remember.

I found these work well enough for graphical noise generation:


Code: [Select]
  '------------------------------
  Function Noise(sys i) As Single
  '==============================
  Static As Single f, d=1/0x7fffffff
  mov eax,i
  xor eax,35353535
  imul eax,eax
  ror eax,17
  imul eax,i
  ror eax,7
  push eax
  fild dWord [esp]
  add esp,4
  fmul dWord d
  fstp dWord _return
  End Function


  '----------------------------
  Function Noisei(sys i) As sys
  '============================
  mov eax,i
  xor eax,35353535
  imul eax,eax
  ror eax,17
  imul eax,i
  ror eax,7
  mov _return,eax
  End Function


Charles

kryton9

  • Guest
Re: Generating Noise
« Reply #1 on: December 15, 2010, 05:37:11 PM »
I was playing with the Gauss example and changing the values, I couldn't figure out how to change the dark color. I could change the yellowish color and height of the terrain.

Can you paste a screenshot of the output of your noise function Charles. Thanks in advance.

Charles Pegge

  • Guest
Re: Generating Noise
« Reply #2 on: December 15, 2010, 11:52:13 PM »
Kent,

This part of the NoisyGauss procedure creates the texture. The asm code effectively feeds a noise byte to the red and green channels. You can control what goes into the color V without using this asm code

If you increase the value of texs the texture will become finer. and increasing en will give you a denser height map. The color tone: light to dark is controlled by the noisy part of height map so that the peaks are lightest and the crevices are darkest. Normals are calculated from the noisy part of the height map (ignoring the hump). This is a simple way to simulate local shadow. when y goes negative the normals flip to the underside and the crevices are lit by ambient light only.

As you can see there are a large number of permutations to play with. It would be fun to control the various parameters dynamically when creating models.

There is a demo of the noise function in the latest thinBasic Oxygen (examples\graphical.) It is used in conjunction with TBGL vertex arrays

Code: [Select]

  '
  'TEXTURE DATA
  '
  static vv
  static sys tx1[0x1000]
  '
  if not vv
    for i=1 to 0x1000
      v=noiseb i
      mov eax,v
      shl eax,8
      mov al,v
      mov v,eax
      tx1[i]=v
    next
    vv=1
    MakeTexture tn1,&tx1,0x40,0x40
  end if
  '
  glBindTexture GL_TEXTURE_2D,tn1

Charles
« Last Edit: December 16, 2010, 04:13:24 AM by Charles Pegge »