Performing some experiments with Perlin Noise, I've been looking for a suitable (and reasonably fast) repetitive noise function. As almost all my work was based on the article written by Hugo Elias I've decided not to use the function presented there and to go on my own. RNG algorithm (discussed here) was only one of my achievements during this research. But (for all those, who did not have anything in common with Perlin Noise) what I needed was a "repetitive" pseudo random number generator ("repetitive" - an algorithm which returns always the same "pseudo random" value for a given input value in 1D or for a given pair of input values in 2D). Here's the final function I wrote:

Noise2D		PROC	intX:DWORD, intY:DWORD

push EBX
push EDX
mov EAX,00BB38435h
mul intX
mov EBX,EAX
mov EAX,03619636Bh
mul intY
add EAX,EBX
pop EDX
pop EBX

push ECX
mov CL,AL
rol EAX,CL
mov CL,AL
rol EAX,CL
mov CL,AL
rol EAX,CL
pop ECX
ret

Noise2D ENDP


Results are shown in Perlin0.jpg. I've tried with only one ROL, but it seems to be not enough (results, shown in Perlin1.jpg, build a noticeable pattern - what's not the point of the noise function).

Presented function may be easily converted to return floating point values (range 0.0 - 1.0 or any other) - just as in floating point version of RNG algorithm. Hopefully - it will be usefull for one of you ;)

Cheers, Mikael
Attachments:
Posted on 2005-08-24 04:03:58 by MikaelC
nice work, MikaelC. This is certanly one of the topics I always wanted to
work on, but never got time to do it. Btw, what about your code style, what
happened to the spaces ? :)
Dom
Posted on 2005-08-25 08:32:07 by Dom
Nice to hear that it was a bit usefull. But what about my code style? I've always been using tabs instead of spaces (AFAIR) ;) Well - honestly - I'm a little bit pedantic about the code layout (lenght of names, indents, aligments, a.s.o.) - and this could be a real pain in ... sometimes ;)

Cheers.
Posted on 2005-08-25 12:20:21 by MikaelC
which compiler takes pushEBX instead of push EBX ?
regards, dom
Posted on 2005-08-26 04:20:51 by Dom
Seems, that I've lost the point... Did I write "pushEBX" or did I eat a space anywhere?  :sad:
Posted on 2005-08-26 08:04:01 by MikaelC
Oh it is just that IE does not display tabs properly. Try taking a looking at this page in IE.  ;)
Posted on 2005-08-26 08:34:56 by roticv
hehe a display error???? (like FF with aarabic and related accents ;)).
Posted on 2005-08-26 10:06:20 by rea
Oh it is just that IE does not display tabs properly. Try taking a looking at this page in IE.

Supposed so, but wasn't sure ;) Because of FF, I don't use IE anymore...
Posted on 2005-08-26 19:16:59 by MikaelC
Hi, a little new arround here, but a few years ago I wrote a random number generator which uses only modulo and addition (If the limit you choose for your values is 8, 16, 32 bits then the modulo goes away of course).

Problem is I've no long got the code - It was lost in a disk crash a few years ago, but the algorythm goes like this:

1) Seed a 17 value array with pseudo random numbers.
2) Set two pointers pointing to slots 0 and 10
3) When a number is read, read the values at the two pointers, place it at the first pointer, inc pointers (Wrapping round at the end of the array), and return the calculated value.

This produced some very impressive results for me (I was writing a game which required a large number of random values) and it appears to be very, very fast.

YMMV.

Posted on 2005-09-04 12:08:22 by Haqa
Haga, do you mean sth like:
; rArray   - 17 elements initialy set to (hardcoded?) random values
; rOffset0 - pointer #1 (initialy set to [00])
; rOffset1 - pointer #2 (initialy set to [10])

random  PROC    USES EBX ECX

  mov  EBX,
  mov  ECX,
  mov  EAX,
  add  EAX,

  inc  EBX
  inc  ECX
  mov  [00],EAX
  cmp  EBX,17
  jnz  @F
  xor  EBX,EBX
@@:
  cmp  ECX,17
  jnz  @F
  xor  ECX,ECX
@@:
  mov  ,EBX
  mov  ,ECX
  ret

random  ENDP
Posted on 2005-09-05 03:45:51 by MikaelC

Haga, do you mean sth like:
; rArray   - 17 elements initialy set to (hardcoded?) random values
; rOffset0 - pointer #1 (initialy set to [00])
; rOffset1 - pointer #2 (initialy set to [10])

random  PROC    USES EBX ECX

   mov  EBX,
   mov  ECX,
   mov  EAX,
   add  EAX,

   inc  EBX
   inc  ECX
   mov  [00],EAX
   cmp  EBX,17
   jnz  @F
   xor  EBX,EBX
@@:
   cmp  ECX,17
   jnz  @F
   xor  ECX,ECX
@@:
   mov  ,EBX
   mov  ,ECX
   ret

random  ENDP



Almost (please bear in mind that I am still learning X86 ASM, when I wrote this, it was in 6502 ASM), but the line

   mov  [00],EAX

should be

  mov , EAX


I think.

(I'm at work at the moment, and I don't have my compiler stuff with me, but it looks right)

Oh, and there is no point hardcoding the initial p'rands unless you want predictable p'rands out of this function. You could use a slower function to seed this, read from the time stream, grab a chunk of stack ... something that is not predictable. if you then run the function a random number of times (Say, wait for the user to hit a key), then you get to a pretty non-predictable p'rand set, which stands up to Chi^2 testing reasonably well (At least, it beat the rnd functions back when I first wrote it).

Haqa...
Posted on 2005-09-05 10:58:42 by Haqa
Just taking a look, the pair of inc's needs to be after the mov [...],eax:

  mov  EAX,
  add  EAX,
  mov  ,EAX
  inc  EBX
  inc  ECX
  cmp  EBX,17


Otherwise, each time round the loop you end up with the same results (ISTR)

Haqa...
Posted on 2005-09-05 16:16:57 by Haqa

Almost (please bear in mind that I am still learning X86 ASM, when I wrote this, it was in 6502 ASM), but the line

  mov  [00],EAX

should be

  mov , EAX


I think.

Yes, it should (I've just noticed that you've written "place it at the first pointer" not "place it at the first slot"). And this means, that:

Just taking a look, the pair of inc's needs to be after the mov [...],eax

The inc'es shall be placed after the store ;)

Cheers.
Posted on 2005-09-05 16:42:27 by MikaelC
Ok, took me a while, but I finally worked the bugs out, and created static... hehe :)

Is the attached what you were looking for?



Ok, and then when I get the right RAP file... oops

Left click = start static...
Right click = stop static...
Posted on 2005-09-07 18:51:48 by Haqa