mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 22:31:52 +00:00
Make seed affect pseudoerosion hasing
This commit is contained in:
+9
-18
@@ -47,22 +47,14 @@ public class PseudoErosionSampler extends NoiseFunction {
|
|||||||
this.maxCellDistSqRecip = 1 / maxCellDistSq;
|
this.maxCellDistSqRecip = 1 / maxCellDistSq;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float hash(float x, float y) {
|
public static float hashX(float seed, float n) {
|
||||||
float xx = x * HASH_X + HASH_Y;
|
|
||||||
float yy = y * HASH_Y + HASH_X;
|
|
||||||
|
|
||||||
// Swapped the components here
|
// Swapped the components here
|
||||||
return 16 * (xx * yy * (xx + yy));
|
float nx = HASH_X * n * seed;
|
||||||
}
|
|
||||||
|
|
||||||
public static float hashX(float n) {
|
|
||||||
// Swapped the components here
|
|
||||||
float nx = HASH_X * n;
|
|
||||||
return -1.0f + 2.0f * fract(nx);
|
return -1.0f + 2.0f * fract(nx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float hashY(float n) {
|
public static float hashY(float seed, float n) {
|
||||||
float ny = HASH_Y * n;
|
float ny = HASH_Y * n * seed;
|
||||||
return -1.0f + 2.0f * fract(ny);
|
return -1.0f + 2.0f * fract(ny);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +62,7 @@ public class PseudoErosionSampler extends NoiseFunction {
|
|||||||
return (x - (float)Math.floor(x));
|
return (x - (float)Math.floor(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
public float[] erosion(float x, float y, float dirX, float dirY) {
|
public float[] erosion(int seed, float x, float y, float dirX, float dirY) {
|
||||||
int gridX = Math.round(x);
|
int gridX = Math.round(x);
|
||||||
int gridY = Math.round(y);
|
int gridY = Math.round(y);
|
||||||
float noise = 0.0f;
|
float noise = 0.0f;
|
||||||
@@ -80,10 +72,9 @@ public class PseudoErosionSampler extends NoiseFunction {
|
|||||||
|
|
||||||
for (int cellX = gridX - 1; cellX <= gridX + 1; cellX++) {
|
for (int cellX = gridX - 1; cellX <= gridX + 1; cellX++) {
|
||||||
for (int cellY = gridY - 1; cellY <= gridY + 1; cellY++) {
|
for (int cellY = gridY - 1; cellY <= gridY + 1; cellY++) {
|
||||||
// TODO - Make seed affect hashing
|
float cellHash = hash(seed, cellX, cellY);
|
||||||
float cellHash = hash(cellX, cellY);
|
float cellOffsetX = (float) (hashX(seed, cellHash) * jitter);
|
||||||
float cellOffsetX = (float) (hashX(cellHash) * jitter);
|
float cellOffsetY = (float) (hashY(seed, cellHash) * jitter);
|
||||||
float cellOffsetY = (float) (hashY(cellHash) * jitter);
|
|
||||||
float cellOriginDeltaX = (x - cellX) + cellOffsetX;
|
float cellOriginDeltaX = (x - cellX) + cellOffsetX;
|
||||||
float cellOriginDeltaY = (y - cellY) + cellOffsetY;
|
float cellOriginDeltaY = (y - cellY) + cellOffsetY;
|
||||||
float cellOriginDistSq = cellOriginDeltaX * cellOriginDeltaX + cellOriginDeltaY * cellOriginDeltaY;
|
float cellOriginDistSq = cellOriginDeltaX * cellOriginDeltaX + cellOriginDeltaY * cellOriginDeltaY;
|
||||||
@@ -135,7 +126,7 @@ public class PseudoErosionSampler extends NoiseFunction {
|
|||||||
|
|
||||||
// Stack erosion octaves
|
// Stack erosion octaves
|
||||||
for (int i = 0; i < octaves; i++) {
|
for (int i = 0; i < octaves; i++) {
|
||||||
float[] erosionResult = erosion(
|
float[] erosionResult = erosion((int) seed,
|
||||||
x * freq * (float) erosionFrequency,
|
x * freq * (float) erosionFrequency,
|
||||||
y * freq * (float) erosionFrequency,
|
y * freq * (float) erosionFrequency,
|
||||||
baseDirX + dirY * (float) branchStrength,
|
baseDirX + dirY * (float) branchStrength,
|
||||||
|
|||||||
Reference in New Issue
Block a user