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 / Noise Calculation Fail

Author
Message
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 30th Nov 2013 16:55
Why doesn't this work:

DBP equivalent of a simple noise function:


The problem seems to be this line: x = (x<<13)^x. The bit shift seems to work as it should but the squaring is what's the issue where x is greater than 2 it'll just result in the same value.

My question is why does it do this and what should it be doing?

I imagine it just results in an integers max range but if this is the case, why doesn't this appear to be apparent in other languages since it's the same calculation?

"Get in the Van!" - Van B
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Nov 2013 19:51
Quote: "My question is why does it do this and what should it be doing?"


My guess is that's it's working as it should but not as you expect.

What values of x are you using? For example, if x is 555 (a suitably arbitrary integer) then (x<<13) seems to be returned as the large positive value 4546560. Your code is then trying to calculate a ginormous positive value 4546560^555 which is way outside the limits of integers. I doubt you'll get sensible results from that at all.

Are you sure you've interpreted the original algorithm correctly? For example, what are the type and likely range for an input x?



Powered by Free Banners
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 30th Nov 2013 20:15 Edited at: 30th Nov 2013 20:17
If you look at a noise function this is formula is what you'll find. It's insane looking at it, have no idea how it's works, something to do with prime numbers but this is what everyone seems to use for calculating noise in this way. Believe me, there nothing wrong with the code, it's a straight port, problem is it just doesn't work in DBP, but I have no clue how it would work in the first place because if you simply do the math, it hits the integer limit in the first line.

Main source people use for this:
Perlin Noise

But the actual formula is just a random number generator and that returns a value between -1 to 1 based off an integer passed to it.

"Get in the Van!" - Van B
Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 30th Nov 2013 22:52
I suppose since it just generates basically "random" noise it doesn't matter if you get an overflow that wraps around. It could though, it depends where the overflow happens.

Although, the "^" actually means XOR in most languages rather than "raised to". Give that a try


"Why do programmers get Halloween and Christmas mixed up?"
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Dec 2013 13:32
Quote: "Believe me, there nothing wrong with the code"


Ha!

Quote: "Although, the "^" actually means XOR in most languages rather than "raised to". Give that a try "


Sounds like a good idea. There's no point copying code from another language verbatim - you obviously need to replace any operators or other special symbols by their DBPro equivalent.



Powered by Free Banners
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 2nd Dec 2013 01:13
Ahh man, never knew that was XOR in other languages! Looks like I'm gonna have to expand my knowledge of operators! Also I went for Simplex Noise cause of the obvious benefits over classic noise in the end.

"Get in the Van!" - Van B
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Dec 2013 12:53
Quote: "Ahh man, never knew that was XOR in other languages!"


Neither did I. It's just one more annoying detail to keep us awake at night.



Powered by Free Banners
WLGfx
17
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 10th Dec 2013 18:15
Or cheat and use this: http://forum.thegamecreators.com/?m=forum_view&t=189861&b=18

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Login to post a reply

Server time is: 2025-05-17 06:56:58
Your offset time is: 2025-05-17 06:56:58