Skip to content

fix perlin init for up to 16 octaves#12

Merged
xpple merged 2 commits into
xpple:masterfrom
lithodoradiffusa:master
May 5, 2026
Merged

fix perlin init for up to 16 octaves#12
xpple merged 2 commits into
xpple:masterfrom
lithodoradiffusa:master

Conversation

@lithodoradiffusa
Copy link
Copy Markdown

Extended hardcoded arrays for octave hashes, amplitudes, persistance and lacunarity to 17 elements
which fixes jagged noise initialisation (16 octaves)

v. basic test code:
some heights are still +/- 1 out, but previously were up to +/- 40 in jagged peaks.

#include <stdint.h>
#include <stdio.h>

#include "cubiomes/biomes.h"
#include "cubiomes/finders.h"
#include "cubiomes/terrainnoise.h"

int DIM = DIM_OVERWORLD;
int VERS = MC_NEWEST;
int LARGE = 0;

// Jagged peaks biome
// from in-game 1.21.11 on seed 5590
int xs[11] = {370, 341, 240, 228, 292, 278, 263, 423, 452, 434, 2000};
int zs[11] = {266, 251, 176, 168, 148, 281, 284, 162, 164, 152, 2000};
int ys[11] = {253, 206, 226, 205, 220, 211, 195, 197, 160, 184, 79};

int getY(TerrainNoise *tn, Pos3 pos) {
  int cellX, cellY, cellZ;
  cellX = pos.x >> 2;
  cellY = pos.y >> 3;
  cellZ = pos.z >> 2;

  double ybuf00[49];
  double ybuf01[49];
  double ybuf10[49];
  double ybuf11[49];
  int blocks[384];
  sampleNoiseColumn(tn, cellX, cellZ, ybuf00);
  sampleNoiseColumn(tn, cellX, cellZ + 1, ybuf01);
  sampleNoiseColumn(tn, cellX + 1, cellZ, ybuf10);
  sampleNoiseColumn(tn, cellX + 1, cellZ + 1, ybuf11);
  int height =
      generateColumn(pos.x, pos.z, blocks, ybuf00, ybuf01, ybuf10, ybuf11, 1);
  height -= 64;

  /*
   * print jaggedNoise and jagged spline value
   *
  float np_param[4];
  sampleNoiseParameters(&tn->g.bn, cellX, cellZ, np_param);

  double depth = getSpline(tn->g.bn.sp, np_param) - 0.50375f;
  double factor = getSpline(tn->factorSpline, np_param);
  double jagged = sampleDoublePerlin(&tn->noises[OTP_JAGGED],
                                     (double)cellX * (1 << 2) * 1500.0, 0.0,
                                     (double)cellZ * (1 << 2) * 1500.0);

  double jspline = jagged >= 0.0 ? jagged : jagged / 2.0;
  jspline *= getSpline(tn->jaggednessSpline, np_param);
  printf("jagged = %f -> %f\n", jagged, jspline);
  */
  return height;
}
int main() {
  uint64_t seed = 5590;

  TerrainNoise tn;
  setupTerrainNoise(&tn, VERS, 0);
  initTerrainNoise(&tn, seed, DIM);

  printf("seed = %" PRId64 "\n");
  for (int i = 0; i < 11; i++) {
    Pos3 pos = {xs[i], ys[i], zs[i]};
    printf("(%d %d %d) :", pos.x, pos.y, pos.z);

    int height = getY(&tn, pos);
    printf("real %d =?= %d calc ( %s%d )\n", pos.y, height,
           (height < pos.y) ? "" : "+", height - pos.y);
  }
  return 0;
}

@xpple
Copy link
Copy Markdown
Owner

xpple commented May 5, 2026

Thanks a lot!

@xpple xpple merged commit 60768f9 into xpple:master May 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants