public float EvaluateTriCubic(int x, int y, int z, RandomSeed r) { float value = 0f; for (int d = 2; d < degreeAtKPosMax; d++) { int range = Mathf.FloorToInt(Mathf.Pow(2f, degreeAtKPosMax - d)); int x0 = (x / range) * range; int y0 = (y / range) * range; int z0 = (z / range) * range; float xd = (float)(x % range) / (float)range; float yd = (float)(y % range) / (float)range; float zd = (float)(z % range) / (float)range; float[][][] f = new float[4][][]; for (int i = 0; i < 4; i++) { f[i] = new float[4][]; for (int j = 0; j < 4; j++) { f[i][j] = new float[4]; for (int k = 0; k < 4; k++) { f[i][j][k] = r.Rand(x0 + (i - 1) * range, y0 + (j - 1) * range, z0 + (k - 1) * range, d); } } } float[][] fz = new float[4][]; for (int i = 0; i < 4; i++) { fz[i] = new float[4]; for (int j = 0; j < 4; j++) { fz[i][j] = TERP(zd, f[i][j][0], f[i][j][1], f[i][j][2], f[i][j][3]); } } float[] fy = new float[4]; for (int i = 0; i < 4; i++) { fy[i] = TERP(yd, fz[i][0], fz[i][1], fz[i][2], fz[i][3]); } float fx = TERP(xd, fy[0], fy[1], fy[2], fy[3]); value += fx / Mathf.FloorToInt(Mathf.Pow(2f, d - 2)); } // Note : value belongs to [-1.5f ; +1.5f] value = (value + 1.5f) / 3f; this.minValue = Mathf.Min(this.minValue, value); this.maxValue = Mathf.Max(this.maxValue, value); this.valuesCount++; this.valuesSum += value; return(value); }
static public float EvaluateBiCubic(int x, int y, RandomSeed r) { int degree = 13; float value = 0f; for (int d = 8; d < degree; d++) { int range = Mathf.FloorToInt(Mathf.Pow(2f, degree - d)); int x0 = (x / range) * range; int y0 = (y / range) * range; float xd = (float)(x % range) / (float)range; float yd = (float)(y % range) / (float)range; float[][] f = new float[4][]; for (int i = 0; i < 4; i++) { f[i] = new float[4]; for (int j = 0; j < 4; j++) { f[i][j] = r.Rand(x0 + (i - 1) * range, y0 + (j - 1) * range, d); } } float[] fy = new float[4]; for (int i = 0; i < 4; i++) { fy[i] = TERP(yd, f[i][0], f[i][1], f[i][2], f[i][3]); } float fx = TERP(xd, fy[0], fy[1], fy[2], fy[3]); value += fx / Mathf.FloorToInt(Mathf.Pow(2f, d - 8)); } // Note : value belongs to [-2f ; +2f] return((value + 2f) / 4f); }