Noise expressions

This subforum contains all the issues which we already resolved.
Post Reply
betrok
Fast Inserter
Fast Inserter
Posts: 101
Joined: Wed Feb 28, 2018 12:08 pm
Contact:

Noise expressions

Post 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

betrok
Fast Inserter
Fast Inserter
Posts: 101
Joined: Wed Feb 28, 2018 12:08 pm
Contact:

Re: Noise expressions

Post 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.

betrok
Fast Inserter
Fast Inserter
Posts: 101
Joined: Wed Feb 28, 2018 12:08 pm
Contact:

Re: Noise expressions

Post 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?"

TOGoS
Former Staff
Former Staff
Posts: 93
Joined: Fri Jun 24, 2016 2:29 pm
Contact:

Re: Noise expressions

Post 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.

betrok
Fast Inserter
Fast Inserter
Posts: 101
Joined: Wed Feb 28, 2018 12:08 pm
Contact:

Re: Noise expressions

Post 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.
Attachments
factorio-current.log
(3.41 KiB) Downloaded 126 times

TOGoS
Former Staff
Former Staff
Posts: 93
Joined: Fri Jun 24, 2016 2:29 pm
Contact:

Re: Noise expressions

Post 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.

betrok
Fast Inserter
Fast Inserter
Posts: 101
Joined: Wed Feb 28, 2018 12:08 pm
Contact:

Re: Noise expressions

Post 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.

TOGoS
Former Staff
Former Staff
Posts: 93
Joined: Fri Jun 24, 2016 2:29 pm
Contact:

Re: Noise expressions

Post 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).

TOGoS
Former Staff
Former Staff
Posts: 93
Joined: Fri Jun 24, 2016 2:29 pm
Contact:

Re: Noise expressions

Post 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

betrok
Fast Inserter
Fast Inserter
Posts: 101
Joined: Wed Feb 28, 2018 12:08 pm
Contact:

Re: Noise expressions

Post 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.

TOGoS
Former Staff
Former Staff
Posts: 93
Joined: Fri Jun 24, 2016 2:29 pm
Contact:

Re: Noise expressions

Post 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. :)

betrok
Fast Inserter
Fast Inserter
Posts: 101
Joined: Wed Feb 28, 2018 12:08 pm
Contact:

Re: Noise expressions

Post 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.

Post Reply

Return to “Resolved Problems and Bugs”