oops accidentally left some experimental changes

This commit is contained in:
Zoë Gidiere committed 2023-10-07 14:14:04 -06:00
1 parent 3d571d4bf2
commit 2f1b8690ff
1 file changed
+35 -16
@@ -235,8 +235,8 @@ public class PseudoErosionSampler implements NoiseSampler {
// Precompute cell positions and lookup values // Precompute cell positions and lookup values
double[] cellData = new double[PRECOMPUTE_SIZE * PRECOMPUTE_SIZE * 3]; double[] cellData = new double[PRECOMPUTE_SIZE * PRECOMPUTE_SIZE * 3];
for (int xi = -PRECOMPUTE_RADIUS; xi <= PRECOMPUTE_RADIUS; xi++) { for(int xi = -PRECOMPUTE_RADIUS; xi <= PRECOMPUTE_RADIUS; xi++) {
for (int yi = -PRECOMPUTE_RADIUS; yi <= PRECOMPUTE_RADIUS; yi++) { for(int yi = -PRECOMPUTE_RADIUS; yi <= PRECOMPUTE_RADIUS; yi++) {
int jitterIdx = jitterIdx2D(seed, gridX + xi, gridY + yi); int jitterIdx = jitterIdx2D(seed, gridX + xi, gridY + yi);
double jitterX = RAND_VECS_2D[jitterIdx] * cellularJitter; double jitterX = RAND_VECS_2D[jitterIdx] * cellularJitter;
double jitterY = RAND_VECS_2D[jitterIdx | 1] * cellularJitter; double jitterY = RAND_VECS_2D[jitterIdx | 1] * cellularJitter;
@@ -258,24 +258,43 @@ public class PseudoErosionSampler implements NoiseSampler {
} }
} }
// Iterate over nearby cells and compute the minimum distance // Iterate over nearby cells
for (int i = 0; i < cellData.length; i += 3) { for(int xi = -NEARBY_CELLS_RADIUS; xi <= NEARBY_CELLS_RADIUS; xi++) {
double cellX = cellData[i]; for(int yi = -NEARBY_CELLS_RADIUS; yi <= NEARBY_CELLS_RADIUS; yi++) {
double cellY = cellData[i + 1];
// Find cell position with the lowest lookup value within moore neighborhood of neighbor
// Compute SDF for the line between the current cell position and the surrounding cell with the lowest lookup double lowestLookup = Double.MAX_VALUE;
double lowestLookup = Double.MAX_VALUE; double connectedCellX = 0;
for (int j = 0; j < cellData.length; j += 3) { double connectedCellY = 0;
double connectedCellX = cellData[j]; for(int xni = xi - MAX_CONNECTION_RADIUS; xni <= xi + MAX_CONNECTION_RADIUS; xni++) {
double connectedCellY = cellData[j + 1]; for(int yni = yi - MAX_CONNECTION_RADIUS; yni <= yi + MAX_CONNECTION_RADIUS; yni++) {
int linearIndex = ((xni + PRECOMPUTE_RADIUS) * PRECOMPUTE_SIZE + (yni + PRECOMPUTE_RADIUS)) * 3;
double lookup = cellData[linearIndex + 2];
if(lookup < lowestLookup) {
lowestLookup = lookup;
connectedCellX = cellData[linearIndex];
connectedCellY = cellData[linearIndex + 1];
}
}
}
int linearIndex = ((xi + PRECOMPUTE_RADIUS) * PRECOMPUTE_SIZE + (yi + PRECOMPUTE_RADIUS)) * 3;
double cellX = cellData[linearIndex];
double cellY = cellData[linearIndex + 1];
// Calculate SDF for line between the current cell position and the surrounding cell with the lowest lookup
double distance = lineSdf2D(x, y, cellX, cellY, connectedCellX, connectedCellY); double distance = lineSdf2D(x, y, cellX, cellY, connectedCellX, connectedCellY);
lowestLookup = Math.min(lowestLookup, distance);
// Set final return to the lowest computed distance
finalDistance = Math.min(finalDistance, distance);
} }
// Set final return to the lowest computed distance
finalDistance = Math.min(finalDistance, lowestLookup);
} }
// Shows grid
// if(fastAbs(x-round(x)) > 0.5d - 0.01d || fastAbs(y-round(y)) > 0.5d - 0.01d) {
// return 0;
// }
return finalDistance; return finalDistance;
} }