mojira.dev
MC-303360

Flat-cached shifted noise density functions are recalculated for every Y level

Issue:

In the attached data pack, I substitute the default shiftX and shiftZ density functions with the custom noise functions. All are wrapped in a “flat_cache” density function that is supposed to be used for “flat” noises for the noise router for biome selection, and also used to generate a terrain spline which also supposed to be flat.

Expected behaviour:

Because we use “flat cache”, the noise router values should not be different for different Y. Also, the values should actually be cached only once per X/Z.

Actual behaviour:

Different Continentalness, Erosion and other noise router params for different Y levels - see screenshots. Why are these calculated differently for every Y if “flat_cache” is used? Isn't it supposed to be calculated for Y=0 only?

Potential impact of the fix:

If shifted noise result values are actually cached as “flat” for x/z only, we get a good performance gain when not recalculating them for every Y. Given that shiftX and shiftZ functions are used for many noise router functions, we can get a significant performance gain.
This change should not affect existing world generation results in the sense of produced chunks: the outcome will be the same for the default world generation, as it uses a different approach for shifX and shiftZ functions that effectively always use y=0, but actually does not mean it is not recalculated.

Details:

I recently tried playing around with terrain distortion in my custom data pack and found something that I think looks very weird. I do not know if this is a bug or not. I think, if it is a bug, it may help with a great performance improvement for the world generation.

(I know I can specify zero for "y_scale" for the shift noise, but this would not mean it is not recalculated for every Y. Or am I wrong? Looking at performance, it is still recalculated.)

When I define density functions for shifted noise shift X or shift Z params, they are recalculated for every Y, no matter what 2d caching is defined (flat or 2d).

Example for shiftX:

{
  "type": "minecraft:flat_cache",
  "argument": {
    "type": "minecraft:cache_2d",
    "argument": {
      "type": "minecraft:mul",
      "argument1": 4.0,
      "argument2": {
        "type": "minecraft:noise",
        "noise": "minecraft:offset",
        "xz_scale": 0.25,
        "y_scale": 1.0
      }
    }
  }
}


Example of use:

{
  "type": "minecraft:flat_cache",
  "argument": {
    "type": "minecraft:shifted_noise",
    "noise": "minecraft:continentalness",
    "shift_x": {
      "type": "minecraft:flat_cache",
      "argument": {
        "type": "minecraft:cache_2d",
        "argument": {
          "type": "minecraft:mul",
          "argument1": 4.0,
          "argument2": {
            "type": "minecraft:noise",
            "noise": "minecraft:offset",
            "xz_scale": 0.25,
            "y_scale": 1.0
          }
        }
      }
    },
    "shift_y": 0.0,
    "shift_z": "minecraft:shift_z",
    "xz_scale": 0.25,
    "y_scale": 0.0
  }
}


The last density function is recalculated for every Y level with a different value, completely ignoring that we want to have a “flat” cache defined in both places (here and a shift).

(I know I can specify zero for "y_scale" for the shift noise, but this would not mean it is not recalculated for every Y. Or am I wrong?)

Why I think it affects performance:
1. There is no visible performance difference when I use "y_scale": 0.0 vs "y_scale": 1.0 for the shift noise.
2. When substituting noise router functions and using noises without shifts at all, world generation goes much faster. It looks like adding a shift slows down the calculations really a lot, and one of the reasons might be that “shifted noise” router functions are recalculated for every Y, despite the “flat cache“ specified.
3. Popular data packs, like Terralith and Tectonic, use shifted noise functions a lot, and they are mostly in “flat” cache context. However, they show quite a bad performance reported by many players. I suspect the described behaviour of the “shifted noise” density function is one of the reasons for bad performance.

Environment

Vanilla + data pack

Attachments

Comments 0

No comments.

tomdill

gegy

Confirmed

Platform

Normal

Data Packs, Performance, World generation

1.21.10, 25w42a

26.3 Snapshot 10

Retrieved