Last active
January 29, 2020 23:35
-
-
Save KdotJPG/f8a072ed73aac51aef8f6d40d3ae825c to your computer and use it in GitHub Desktop.
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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