PolyhedralDev / Terra

Voxel world generation modding platform
MIT License
642 stars 85 forks source link

[Feature] Expose salt as an argument for samplers when used as functions #371

Open Astrashh opened 2 years ago

Astrashh commented 2 years ago

Pre-Request Checklist

Feature Description

Include salt as an argument for sampler function calls when used in paralithic expressions and Terrascript sampler calls.

What Problem Does This Solve?

In many instances, modifying the salt for calls to a sampler is desired. For example manually domain warping in an expression requires uniquely salted samples for translations for each coordinate.

With #345, samplers are relied upon to source randomness in Terrascripts. With salts not being exposed, producing unique sets of random values becomes a very cumbersome task.

A Solution You'd Like

Include an additional argument for function calls, eg: noise(x, y, salt), which gets added to the sampler's salt during function invocation.

Alternative Solutions

The current workarounds are either defining two identical samplers just with salt changed:

expression: |
  noiseToBeWarped(
    x + warpX(x, z) * warpAmp,
    z + warpZ(x, z) * warpAmp
  )

or translating the input coords such that samples are sufficiently different:

expression: |
  noiseToBeWarped(
    x + warp(x, z) * warpAmp,
    z + warp(x, z+1000) * warpAmp
  )

This works fine when there are a small amount of unique sample sets, however does not scale when the same sampler is to be used uniquely in many different places, like a generic pack sampler. Here are a couple examples of workarounds used in the overworld:

https://github.com/PolyhedralDev/TerraOverworldConfig/blob/e5930f884321b4d3da434893248b856b6c310075/biomes/abstract/carving/carving_land.yml#L40-L41

https://github.com/PolyhedralDev/TerraOverworldConfig/blob/e5930f884321b4d3da434893248b856b6c310075/biomes/abstract/terrain/land/mountains-small/eq_eroded_pillars.yml#L45-L46

Additonal Context