I’m studying the noise.cpp code and have some questions.
Question 1
I see that the frequency is set with the q44, q88 data type (which is defined in lib8tion). I think is is power?
I saw in the code q44(2,0). Is this base, exponent?
So q44(2,0) = 1, q44(2,1) = 2, q44, (2,2) = 4 etc ?
The limit of q44 is (4,4) = 256
The limit of q88 is (8,8) = 16777216
Is it faster? Or can I better multiply with 1, 2, 4 etc. to create different octaves?
Question 2
Another parameter that is used is “skip”. I didn’t get the function of that one. What does it do?
Question 3
In the inoise8 function the outcome of the noise (-70,70) is scaled to 0 - 255. Why is the bitmath operation <<1 needed? Because scale8 scale a number already to 255?
q44/q/88 are fractional types - e.g. the high four bits are to the left of the decimal point and the low four bits are to the right. This is done because floating point math is expensive.
if I remember right it has to do with how points in successive octaves are figured out (a performance optimization, basically each successive octave only computes 1/4th the number of points as the previous octave)
it is because range of the output of inoise8_raw is so low - that line brings it back into a 0-255 range. (the exact values used came from days of running sets and looking at distribution plots$.
Thanks. I have some subsequent questions, because I don’t completely get it.
I don’t really get what fractional types are. How do I have to interpret (2,0)? (Sorry, maybe too much a noob question, but I’m trying to understand). I understand how it works with floating point math and power (http://freespace.virgin.net/hugo.elias/models/m_perlin.htm), but I try to understand the fixed point math replacements you made. Can you give an example how I can compare them with the floating point equivalents.
Question 4
My concrete goal is to fill a 2d array and to start at a certain octave. I’m unsure if I can reach this with the functions you’ve provided. I think with fill_raw_2dnoise8, however I’m unsure.
So for example one array that starts at octave 0 and another array at octave 2 (so frequency (2^2)). If I start at octave 2 the amplitude should be 1 (255 in fixed point world?).
fill_raw_2dnoise8(uint8_t *pData, int width, int height, uint8_t octaves, q44 freq44, fract8 amplitude, int skip, uint16_t x, int scalex, uint16_t y, int scaley, uint16_t time)
Can I simply call this function and change the frequency?
So one call with (2,0) and the other one with (2,2).
How does the amplitude parameter work. I see that a value of 171 is used. Does the amplitude gets “weaker” for each added octave with a multiplier of 171/255 = 0,67?
Hi Kasper, a fractional type works just like a number with a decimal point. If I tell you all the numbers I’m sending you are 1000 times bigger than their actual value, and i tell you 123456, then you know that I am sending you 123.456. It’s the same thing in binary. 4 digits to the right of the decimal point means that 10100101 means 1010.0101, for example. To the right of the decimal point, each 1 represents 2^-N. That number would be 1*2^3 + 0 * 2^2 + 1 * 2^1 + 0 * 2^0 + 0 2^-1 + 12^-2 + 0 *2^-3 + 1 * 2^-4. Does that make sense?