?? perlinscalar.java
字號:
public static final float pnoise(float xi, float period) {
float x = (xi % period) + ((xi < 0) ? period : 0);
return ((period - x) * noise(x) + x * noise(x - period)) / period;
}
public static final float pnoise(float xi, float yi, float w, float h) {
float x = (xi % w) + ((xi < 0) ? w : 0);
float y = (yi % h) + ((yi < 0) ? h : 0);
float w_x = w - x;
float h_y = h - y;
float x_w = x - w;
float y_h = y - h;
return (noise(x, y) * (w_x) * (h_y) + noise(x_w, y) * (x) * (h_y) + noise(x_w, y_h) * (x) * (y) + noise(x, y_h) * (w_x) * (y)) / (w * h);
}
public static final float pnoise(float xi, float yi, float zi, float w, float h, float d) {
float x = (xi % w) + ((xi < 0) ? w : 0);
float y = (yi % h) + ((yi < 0) ? h : 0);
float z = (zi % d) + ((zi < 0) ? d : 0);
float w_x = w - x;
float h_y = h - y;
float d_z = d - z;
float x_w = x - w;
float y_h = y - h;
float z_d = z - d;
float xy = x * y;
float h_yXd_z = h_y * d_z;
float h_yXz = h_y * z;
float w_xXy = w_x * y;
return (noise(x, y, z) * (w_x) * h_yXd_z + noise(x, y_h, z) * w_xXy * (d_z) + noise(x_w, y, z) * (x) * h_yXd_z + noise(x_w, y_h, z) * (xy) * (d_z) + noise(x_w, y_h, z_d) * (xy) * (z) + noise(x, y, z_d) * (w_x) * h_yXz + noise(x, y_h, z_d) * w_xXy * (z) + noise(x_w, y, z_d) * (x) * h_yXz) / (w * h * d);
}
public static final float pnoise(float xi, float yi, float zi, float ti, float w, float h, float d, float p) {
float x = (xi % w) + ((xi < 0) ? w : 0);
float y = (yi % h) + ((yi < 0) ? h : 0);
float z = (zi % d) + ((zi < 0) ? d : 0);
float t = (ti % p) + ((ti < 0) ? p : 0);
float w_x = w - x;
float h_y = h - y;
float d_z = d - z;
float p_t = p - t;
float x_w = x - w;
float y_h = y - h;
float z_d = z - d;
float t_p = t - p;
float xy = x * y;
float d_zXp_t = (d_z) * (p_t);
float zXp_t = z * (p_t);
float zXt = z * t;
float d_zXt = d_z * t;
float w_xXy = w_x * y;
float w_xXh_y = w_x * h_y;
float xXh_y = x * h_y;
return (noise(x, y, z, t) * (w_xXh_y) * d_zXp_t + noise(x_w, y, z, t) * (xXh_y) * d_zXp_t + noise(x_w, y_h, z, t) * (xy) * d_zXp_t + noise(x, y_h, z, t) * (w_xXy) * d_zXp_t + noise(x_w, y_h, z_d, t) * (xy) * (zXp_t) + noise(x, y, z_d, t) * (w_xXh_y) * (zXp_t) + noise(x, y_h, z_d, t) * (w_xXy) * (zXp_t) + noise(x_w, y, z_d, t) * (xXh_y) * (zXp_t) + noise(x, y, z, t_p) * (w_xXh_y) * (d_zXt) + noise(x_w, y, z, t_p) * (xXh_y) * (d_zXt) + noise(x_w, y_h, z, t_p) * (xy) * (d_zXt) + noise(x, y_h, z, t_p) * (w_xXy) * (d_zXt) + noise(x_w, y_h, z_d, t_p) * (xy) * (zXt) + noise(x, y, z_d, t_p) * (w_xXh_y) * (zXt) + noise(x, y_h, z_d, t_p) * (w_xXy) * (zXt) + noise(x_w, y, z_d, t_p) * (xXh_y) * (zXt)) / (w * h * d * t);
}
public static final float pnoise(Point2 p, float periodx, float periody) {
return pnoise(p.x, p.y, periodx, periody);
}
public static final float pnoise(Point3 p, Vector3 period) {
return pnoise(p.x, p.y, p.z, period.x, period.y, period.z);
}
public static final float pnoise(Point3 p, float t, Vector3 pperiod, float tperiod) {
return pnoise(p.x, p.y, p.z, t, pperiod.x, pperiod.y, pperiod.z, tperiod);
}
public static final float spnoise(float xi, float period) {
float x = (xi % period) + ((xi < 0) ? period : 0);
return (((period - x) * snoise(x) + x * snoise(x - period)) / period);
}
public static final float spnoise(float xi, float yi, float w, float h) {
float x = (xi % w) + ((xi < 0) ? w : 0);
float y = (yi % h) + ((yi < 0) ? h : 0);
float w_x = w - x;
float h_y = h - y;
float x_w = x - w;
float y_h = y - h;
return ((snoise(x, y) * (w_x) * (h_y) + snoise(x_w, y) * (x) * (h_y) + snoise(x_w, y_h) * (x) * (y) + snoise(x, y_h) * (w_x) * (y)) / (w * h));
}
public static final float spnoise(float xi, float yi, float zi, float w, float h, float d) {
float x = (xi % w) + ((xi < 0) ? w : 0);
float y = (yi % h) + ((yi < 0) ? h : 0);
float z = (zi % d) + ((zi < 0) ? d : 0);
float w_x = w - x;
float h_y = h - y;
float d_z = d - z;
float x_w = x - w;
float y_h = y - h;
float z_d = z - d;
float xy = x * y;
float h_yXd_z = h_y * d_z;
float h_yXz = h_y * z;
float w_xXy = w_x * y;
return ((snoise(x, y, z) * (w_x) * h_yXd_z + snoise(x, y_h, z) * w_xXy * (d_z) + snoise(x_w, y, z) * (x) * h_yXd_z + snoise(x_w, y_h, z) * (xy) * (d_z) + snoise(x_w, y_h, z_d) * (xy) * (z) + snoise(x, y, z_d) * (w_x) * h_yXz + snoise(x, y_h, z_d) * w_xXy * (z) + snoise(x_w, y, z_d) * (x) * h_yXz) / (w * h * d));
}
public static final float spnoise(float xi, float yi, float zi, float ti, float w, float h, float d, float p) {
float x = (xi % w) + ((xi < 0) ? w : 0);
float y = (yi % h) + ((yi < 0) ? h : 0);
float z = (zi % d) + ((zi < 0) ? d : 0);
float t = (ti % p) + ((ti < 0) ? p : 0);
float w_x = w - x;
float h_y = h - y;
float d_z = d - z;
float p_t = p - t;
float x_w = x - w;
float y_h = y - h;
float z_d = z - d;
float t_p = t - p;
float xy = x * y;
float d_zXp_t = (d_z) * (p_t);
float zXp_t = z * (p_t);
float zXt = z * t;
float d_zXt = d_z * t;
float w_xXy = w_x * y;
float w_xXh_y = w_x * h_y;
float xXh_y = x * h_y;
return ((snoise(x, y, z, t) * (w_xXh_y) * d_zXp_t + snoise(x_w, y, z, t) * (xXh_y) * d_zXp_t + snoise(x_w, y_h, z, t) * (xy) * d_zXp_t + snoise(x, y_h, z, t) * (w_xXy) * d_zXp_t + snoise(x_w, y_h, z_d, t) * (xy) * (zXp_t) + snoise(x, y, z_d, t) * (w_xXh_y) * (zXp_t) + snoise(x, y_h, z_d, t) * (w_xXy) * (zXp_t) + snoise(x_w, y, z_d, t) * (xXh_y) * (zXp_t) + snoise(x, y, z, t_p) * (w_xXh_y) * (d_zXt) + snoise(x_w, y, z, t_p) * (xXh_y) * (d_zXt) + snoise(x_w, y_h, z, t_p) * (xy) * (d_zXt) + snoise(x, y_h, z, t_p) * (w_xXy) * (d_zXt) + snoise(x_w, y_h, z_d, t_p) * (xy) * (zXt) + snoise(x, y, z_d, t_p) * (w_xXh_y) * (zXt) + snoise(x, y_h, z_d, t_p) * (w_xXy) * (zXt) + snoise(x_w, y, z_d, t_p) * (xXh_y) * (zXt)) / (w * h * d * t));
}
public static final float spnoise(Point2 p, float periodx, float periody) {
return spnoise(p.x, p.y, periodx, periody);
}
public static final float spnoise(Point3 p, Vector3 period) {
return spnoise(p.x, p.y, p.z, period.x, period.y, period.z);
}
public static final float spnoise(Point3 p, float t, Vector3 pperiod, float tperiod) {
return spnoise(p.x, p.y, p.z, t, pperiod.x, pperiod.y, pperiod.z, tperiod);
}
private static final float fade(float t) {
return t * t * t * (t * (t * 6 - 15) + 10);
}
private static final float lerp(float t, float a, float b) {
return a + t * (b - a);
}
private static final float grad(int hash, float x) {
int h = hash & 0x1;
return x * G1[h];
}
private static final float grad(int hash, float x, float y) {
int h = hash & 0x3;
return x * G2[h][0] + y * G2[h][1];
}
private static final float grad(int hash, float x, float y, float z) {
int h = hash & 15;
return x * G3[h][0] + y * G3[h][1] + z * G3[h][2];
}
private static final float grad(int hash, float x, float y, float z, float w) {
int h = hash & 31;
return x * G4[h][0] + y * G4[h][1] + z * G4[h][2] + w * G4[h][3];
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -