[0.18.18] noise.terrace source code request for mysterious behavior

Place to get help with not working mods / modding interface.
Post Reply
mooman219
Burner Inserter
Burner Inserter
Posts: 6
Joined: Fri Apr 10, 2020 10:28 pm
Contact:

[0.18.18] noise.terrace source code request for mysterious behavior

Post by mooman219 »

Context: setting a custom richness_expression for iron-ore in a lua mod using the noise.terrace function produces unexpected output.

Function X

Code: Select all

  ...["iron-ore"].autoplace.richness_expression = noise.define_noise_function(function(x, y, tile, map)
    return 250 + (250 * noise.terrace(x / 32, 0, 1, math.huge))
  end)
Function Y

Code: Select all

  ...["iron-ore"].autoplace.richness_expression = noise.define_noise_function(function(x, y, tile, map)
    return 250 + (250 * noise.terrace(y / 32, 0, 1, math.huge))
  end)
Output in the attachment.

It looks like in the negative X part of the grid, noise.terrace is just wrong despite it not directly consuming the X coordinate at any point in the Y function. I've tried various combinations and the negative x part of the map just exhibits different behavior than I'm expecting. The positive X portion of the map works as expected.

I would like to see the c++ source of the noise.terrace function to help clear up my misconception for what it's supposed to do because it looks like it's bugged out right now. A few members of the discord with source access tried to disambiguate what it does, but all we got was that noise.terrace(value, 0, 1, math.huge) boils down to a floor() function.
Attachments
Function X vs Function Y
Function X vs Function Y
Untitled.png (415.48 KiB) Viewed 906 times

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [0.18.18] noise.terrace source code request for mysterious behavior

Post by posila »

Code: Select all

void NoiseProcedureOps::Terrace::run(NoiseCache& cache) const
{
  float* dest = cache.getFloatRegister(destReg);
  float* source = cache.getFloatRegister(sourceReg);
  float* strength = cache.getFloatRegister(strengthReg);
  for (size_t i = cache.vectorSize; i-- > 0;)
  {
    float stre = strength[i];
    float s = (source[i] - this->stripeOffset) / this->stripeWidth;
    float floor = std::floor(s);
    float phase = s - floor;
    if (phase > stre)
      phase = (phase - stre) / (1 - stre);
    else
      phase = 0;
    dest[i] = (floor + phase) * this->stripeWidth + this->stripeOffset;
  }
}
If I am reading setup correctly, the parameters should be terrace(source, stripeOffset, stripeWidth, strength)

mooman219
Burner Inserter
Burner Inserter
Posts: 6
Joined: Fri Apr 10, 2020 10:28 pm
Contact:

Re: [0.18.18] noise.terrace source code request for mysterious behavior

Post by mooman219 »

Thank you! This is definitely more opaque than I thought it would be, but this is helpful <3

Post Reply

Return to “Modding help”