Page 1 of 1

Noise expressions

Posted: Sat Mar 10, 2018 4:29 pm
by betrok
I have to admit, that i fail to master this black magic on my own. It's time to go cry^W^W ask for help here.

All documentation, which i managed to find, is limited to this gist and actual game files.
Well, practice is the best of all instructors, here we go:

Code: Select all

data:extend{
	{
		type = "noise-expression",
		name = "default-elevation",
		expression = noise.define_noise_function(
			function(x, y, tile, map)
				return make_basis_noise_function(map.seed, 11)(x, y)
			end
		),
	}
}
So far so good, fine noise(outside start area), mostly within [0,1], sometimes down/up to -0.5/1.5(result of smoothing?).
I will try to offset values:

Code: Select all

function(x, y, tile, map)
	return make_basis_noise_function(map.seed, 11)(x, y) - 0.5
end
Boom! Constant -0.5 everywhere. Did I do something wrong? Probably...
But

Code: Select all

function(x, y, tile, map)
	return make_basis_noise_function(map.seed, 11)(x, y, 0.5, 1) - 0.5
end
Single difference is inscale value and noise is here again.

Can someone explain what's going on?

//sidenote: make_basis_noise_function() is single place where outscale argument is before inscale, even its anonymous return looks opposite.
//sorry for my poor english

Re: Noise expressions

Posted: Mon Mar 12, 2018 7:51 pm
by betrok
Hm, may be it is unclear what i'm talking about.

Main problem is that basis noise becomes just zero everywhere suddenly when inscale >= 1 and any addition arithmetic is involved.
So

Code: Select all

make_basis_noise_function(map.seed, 11)(x, y, 2, 1)
works fine by its own,

Code: Select all

make_basis_noise_function(map.seed, 11)(x, y, 0.5, 1) + 10
is alrigth as well, but

Code: Select all

make_basis_noise_function(map.seed, 11)(x, y, 2, 1) + 10
results in nothing but constant 10.
It looks pretty much like a bug for me.

Besides that i'm interested in actual spects for factorio-basis-noise: basic amplitude, period and may be smoothing logic as well.

Re: Noise expressions

Posted: Tue Mar 13, 2018 10:26 am
by betrok
I tried to play around little more and ended up with even higher level of puzzlement.

Code: Select all

make_multioctave_noise_function(map.seed, 11, 2)(x, y, 1, 1)
provides me constant 0.4,

Code: Select all

make_multioctave_noise_function(map.seed, 11, 2)(x, y, 1, 1) + 1
results in actual noise.
At this point i have nothing but "Wat?"

Re: Noise expressions

Posted: Fri Mar 16, 2018 3:04 pm
by TOGoS
Thanks for testing! At first glance your -0.5 does appear to be a bug in the compiler. I'll see if I can reproduce this and figure out what's up in the next few days.

Re: Noise expressions

Posted: Sat Mar 17, 2018 11:44 am
by betrok
I'm looking forward for it.

In case problem is installation-specific(though vanilla map looks fine): i'm using steam version on arch linux.
Common log in attachment, "bwater" is my test mod.

Re: Noise expressions

Posted: Thu Mar 29, 2018 9:04 pm
by TOGoS
Sorry I haven't got around to looking at this yet. All of my time has been going into the overhaul for 0.17, which might end up inadvertently fixing this problem since it by necessity involves a bit of 'battening down the hatches' around compiling of noise expressions.

Re: Noise expressions

Posted: Sat Mar 31, 2018 4:28 pm
by betrok
That's somewhat sad...
In other hand i have to admit that changes in expressions logic might be unacceptable at current 0.16 state.
Hopefully 0.17 will become public experimental soon.

Re: Noise expressions

Posted: Tue Apr 03, 2018 7:21 pm
by TOGoS
Took some time to look into this. There is a bug in our noise compiler (already addressed for 0.17; I'll backport it to 0.16), but it's not what you think it is.

Your examples where you get a constant value from noise(x,y) or using integer >= 1 input multipliers are actually working correctly. It just so happens that our noise function returns 0 at integer inputs ((0,0), (0,2), and so on), which (at least for 0.16) are where the noise values for tiles come from (for 0.17 I may change this to sample at the tiles' centers, instead). Your first attempt, where you got something other than zeroes out of the noise function, was the one that demonstrated the bug!

I suggest using smaller input scales such as 1/8. Higher input scale means higher frequency noise, and noise with frequency >= 1 is not very useful except as sort of a hashing function, in which case try using a number that is not 1 / any integer. 7/8, for example (which would give you zeroes only every 7 tiles instead of on every tile).

Re: Noise expressions

Posted: Tue Apr 03, 2018 7:45 pm
by TOGoS
betrok wrote://sidenote: make_basis_noise_function() is single place where outscale argument is before inscale, even its anonymous return looks opposite.
I'm not too happy with the argument order, either. I'm transitioning to using tables as inputs to the functions that return noise expressions for that reason. e.g. make_multioctave_modulated_noise_function

Re: Noise expressions

Posted: Tue Apr 03, 2018 9:48 pm
by betrok
Sometimes things aren't exactly what they seem. :)
Thanks for fix.
TOGoS wrote:It just so happens that our noise function returns 0 at integer inputs ((0,0), (0,2), and so on)
Interesting. Could you shed some more light on noise specs?
And another litle request: i think it will be good idea to move make_*_noise_function's to lualib/noise to avoid copypaste.

Re: Noise expressions

Posted: Mon Apr 09, 2018 5:29 am
by TOGoS
betrok wrote:
TOGoS wrote:It just so happens that our noise function returns 0 at integer inputs ((0,0), (0,2), and so on)
Interesting. Could you shed some more light on noise specs?
And another litle request: i think it will be good idea to move make_*_noise_function's to lualib/noise to avoid copypaste.
I inherited the basis function from Cube, and I haven't looked too closely at the details of how it works because I haven't had to. I didn't even realize about the integer inputs always giving zero until you reported it. But it also wasn't surprising -- coherent noise functions tend to have spots like that. e.g. Perlin Noise looks very nice until you apply slope shading to its output, and then you notice a grid of lines.

Anyway, Cube wrote part of an FFF about it back in the day: https://www.factorio.com/blog/post/fff-112

Actually now that I read that it doesn't explain much, either. It does something based on interpolating between 4 vectors at the corners of each grid cell. If you're really curious I suppose you could hunt down Cube and ask him.

My plan is to eventually make convenient functions for constructing basis noise expressions available from the noise util library, but it's better to let people copypasta than to export a bad API, which, as you noticed, is what the current set of noise function constructors are. :)

Re: Noise expressions

Posted: Mon Apr 09, 2018 8:17 am
by betrok
TOGoS wrote:If you're really curious I suppose you could hunt down Cube and ask him.
Based on notes in FFF I have to hunt down Ken Perlin himself, because he is probably only person who really knows how all this works %)
But there are links to articles and even phyton prototype, maybe I will try to get into it later.