Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample code for only generating enough noise octaves to know the sign of the final value (simplified from a small WIP MC mod of mine)
private double computeGoodEnoughNoise(int worldX, int worldY, int worldZ, double startingValue) {
// Final noise value begins with the threshold.
double value = startingValue; // e.g. -heightThreshold (negative)
double freq = BASE_FREQUENCY; // e.g. 1.0/256.0
double amp = BASE_AMPLITUDE; // e.g. 64.0
for (int i = 0; i < nOctaves && actualValue > -uncertaintyBounds[i] && actualValue < uncertaintyBounds[i]; i++) {
value += octaves[i].noise3_XZBeforeY(worldX * hScale * freq, worldY * vScale * freq, worldZ * hScale * freq) * amp;
freq *= 2.0;
amp /= 2.0;
}
return actualValue;
}
/////////////////////////////////
// Pregenerate this in a constructor, or somewhere.
// for nOctaves=4, this would generate
// { BASE_AMPLITUDE * (1.0 + 0.5 + 0.25 + 0.125), BASE_AMPLITUDE * (0.5 + 0.25 + 0.125), BASE_AMPLITUDE * (0.25 + 0.125), BASE_AMPLITUDE * (0.125) };
uncertaintyBounds = new double[nOctaves];
{
double boundBase = 0.0;
for (int i = nOctaves - 1; i >= 0; i--) {
boundBase += 1.0 / (1 << i);
uncertaintyBounds[i] = OUTPUT_NOISE_MAIN_AMPLITUDE * boundBase;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment