public WorleyNoise(int seed, float frequency, float perterbAmp, float cellularJitter, DistanceFunction distanceFunction, CellularReturnType cellularReturnType, Distance2EdgeBorder distance2EdgeBorder) { this.seed = seed; this.frequency = frequency; this.perterbAmp = perterbAmp; this.cellularJitter = cellularJitter; this.distanceFunction = distanceFunction; this.cellularReturnType = cellularReturnType; this.distance2EdgeBorder = distance2EdgeBorder; topologyUtil = new TopologyUtil().Construct(); cell_2D = new CELL_2D(); X_PRIME = 1619; Y_PRIME = 31337; }
/// <summary> /// Sets return type from cellular noise calculations - /// Default: Distance /// </summary> /// <param name="cellularReturnType"></param> public void SetCellularReturnType(CellularReturnType cellularReturnType) { NativeSetCellularReturnType(nativePointer, (int)cellularReturnType); }
private static float SingleCellular(int seed, CellularDistanceFunction distanceFunction, CellularReturnType returnType, float frequency, float jitter, float x, float y, float z) { int xr = FastRound(x * frequency); int yr = FastRound(y * frequency); int zr = FastRound(z * frequency); float distance = 999999f; int xc = 0, yc = 0, zc = 0; switch (distanceFunction) { case CellularDistanceFunction.Euclidean: for (int xi = xr - 1; xi <= (xr + 1); xi++) { for (int yi = yr - 1; yi <= (yr + 1); yi++) { for (int zi = zr - 1; zi <= (zr + 1); zi++) { Vector3 vec = Cell3D[Hash3D(seed, xi, yi, zi) & 255]; float vecX = (xi - x) + (vec.X * jitter); float vecY = (yi - y) + (vec.Y * jitter); float vecZ = (zi - z) + (vec.Z * jitter); float newDistance = (vecX * vecX) + (vecY * vecY) + (vecZ * vecZ); if (newDistance < distance) { distance = newDistance; xc = xi; yc = yi; zc = zi; } } } } break; case CellularDistanceFunction.Manhattan: for (int xi = xr - 1; xi <= (xr + 1); xi++) { for (int yi = yr - 1; yi <= (yr + 1); yi++) { for (int zi = zr - 1; zi <= (zr + 1); zi++) { Vector3 vec = Cell3D[Hash3D(seed, xi, yi, zi) & 255]; float vecX = (xi - x) + (vec.X * jitter); float vecY = (yi - y) + (vec.Y * jitter); float vecZ = (zi - z) + (vec.Z * jitter); float newDistance = Math.Abs(vecX) + Math.Abs(vecY) + Math.Abs(vecZ); if (newDistance < distance) { distance = newDistance; xc = xi; yc = yi; zc = zi; } } } } break; case CellularDistanceFunction.Natural: for (int xi = xr - 1; xi <= (xr + 1); xi++) { for (int yi = yr - 1; yi <= (yr + 1); yi++) { for (int zi = zr - 1; zi <= (zr + 1); zi++) { Vector3 vec = Cell3D[Hash3D(seed, xi, yi, zi) & 255]; float vecX = (xi - x) + (vec.X * jitter); float vecY = (yi - y) + (vec.Y * jitter); float vecZ = (zi - z) + (vec.Z * jitter); float newDistance = Math.Abs(vecX) + Math.Abs(vecY) + Math.Abs(vecZ) + ((vecX * vecX) + (vecY * vecY) + (vecZ * vecZ)); if (newDistance < distance) { distance = newDistance; xc = xi; yc = yi; zc = zi; } } } } break; default: throw new ArgumentOutOfRangeException(nameof(distanceFunction), distanceFunction, null); } switch (returnType) { case CellularReturnType.CellValue: return(ValCoord3D(seed, xc, yc, zc)); case CellularReturnType.Distance: return(distance); case CellularReturnType.NoiseLookup: break; case CellularReturnType.Distance2: break; case CellularReturnType.Distance2Add: break; case CellularReturnType.Distance2Sub: break; case CellularReturnType.Distance2Mul: break; case CellularReturnType.Distance2Div: break; default: return(0); } return(0f); }
public static float GetCellular(int seed, CellularDistanceFunction distanceFunction, CellularReturnType returnType, float frequency, float jitter, Vector3 xyz) => SingleCellular(seed, distanceFunction, returnType, frequency, jitter, xyz.X, xyz.Y, xyz.Z);
public void SetCellularReturnType(CellularReturnType cellularReturnType) { SetCellularReturnType(noisePointer, (int)cellularReturnType); }
public Voronoi(float frequency, CellularReturnType returnType, CellularDistanceFunction distanceFunction) { Frequency = frequency; ReturnType = returnType; DistanceFunction = distanceFunction; }