目录
Noise generators
Random number generators
Noise generators
- 噪波生成函数,noise、wnoise、vnoise、onoise、snoise、anoise;
- 每一个函数表示生成噪波的不同算法;
每个噪波相对成本:
- Perlin noise(noise),1;
- Original perlin noise(onoise),1.1;
- worley noise(wnoise),1.8;
- Sparse Convolution noise(snoise),2.1;
- Alligator noise(anoise),2.3;
noise
- 有两种Perlin噪波,此为非周期噪波,周期噪波是pnoise;
- 取值范围0~1,中位值为0.5;发布取决于维度,更高的维度接近高斯发布;
//基于1D位置 float noise(float pos) vector noise(float pos) //基于2D位置 float noise(float posx, float posy) vector noise(float posx, float posy) //基于3D位置 float noise(vector pos) vector noise(vector pos) //基于4D位置 float noise(vector4 pos) vector noise(vector4 pos)
anoise
- 生成“alligator” 噪波(cellular noise类型),类型wnoise;
- 当前无法使用worley函数模拟“alligator” 噪波,但可获得类似外观;
- 取值范围0~1,仅支持3D noise;
float anoise(vector pos) vector anoise(vector pos) float anoise(vector pos, int turbulence, float rough, float atten) vector anoise(vector pos, int turbulence, float rough, float atten) float anoise(vector pos, int periodX, int periodY, int periodZ) vector anoise(vector pos, int periodX, int periodY, int periodZ) float anoise(vector pos, int periodX, int periodY, int periodZ, int turbulence, float rough, float atten) vector anoise(vector pos, int periodX, int periodY, int periodZ, int turbulence, float rough, float atten)
onoise
- 类似wnoise、vnoise(效率略低,特征不同);
- 取值范围-1~1,仅支持3D noise;
float onoise(vector pos) vector onoise(vector pos) float onoise(vector pos, int turbulence, float rough, float atten) vector onoise(vector pos, int turbulence, float rough, float atten) float onoise(vector pos, int periodX, int periodY, int periodZ) vector onoise(vector pos, int periodX, int periodY, int periodZ) float onoise(vector pos, int periodX, int periodY, int periodZ, int turbulence, float rough, float atten) vector onoise(vector pos, int periodX, int periodY, int periodZ, int turbulence, float rough, float atten)
snoise
- 类似于wnoise,基于所有最近点的权重;
- 取值范围-1.7~1.7,仅支持3D noise;
float snoise(vector pos) vector snoise(vector pos) float snoise(vector pos, int turbulence, float rough, float atten) vector snoise(vector pos, int turbulence, float rough, float atten) float snoise(vector pos, int periodX, int periodY, int periodZ) vector snoise(vector pos, int periodX, int periodY, int periodZ) float snoise(vector pos, int periodX, int periodY, int periodZ, int turbulence, float rough, float atten) vector snoise(vector pos, int periodX, int periodY, int periodZ, int turbulence, float rough, float atten)
wnoise
- 生成Worley(蜂窝)噪波;
//生成1D noise void wnoise(float position, int &seed, float &f1, float &f2) void wnoise(float position, int &seed, float &f1, float &f2, float &f3, float &f4) //生成周期1D noise void wnoise(float position, int &seed, float &f1, float &f2, int peiod) void wnoise(float position, int &seed, float &f1, float &f2, float &f4, float &f4, int period) //生成2D noise void wnoise(float posx, float posy, int &seed, float &f1, float &f2) void wnoise(float posx, float posy, int &seed, float &f1, float &f2, float &f3, float &f4) //生成周期2D noise void wnoise(float posx, float posy, int &seed, float &f1, float &f2, int periodx, int periody) void wnoise(float posx, float posy, int &seed, float &f1, float &f2, float &f3, float &f4, int periodx, int periody) //生成2D noise void wnoise(vector2 position, int &seed, float &f1, float &f2) void wnoise(vector2 position, int &seed, float &f1, float &f2, float &f3, float &f4) //生成周期2D noise void wnoise(vector2 position, int &seed, float &f1, float &f2, int periodx, int periody) void wnoise(vector2 position, int &seed, float &f1, float &f2, float &f3, float &f4, int periodx, int periody) //生成3D noise void wnoise(vector position, int &seed, float &f1, float &f2) void wnoise(vector position, int &seed, float &f1, float &f2, float &f3, float &f4) //生成周期3D noise void wnoise(vector position, int &seed, float &f1, float &f2, int periodx, int periody, int periodx) void wnoise(vector position, int &seed, float &f1, float &f2, float &f3, float &f4, int periodx, int periody, int periodz) //生成4D noise void wnoise(vector4 position, int &seed, float &f1, float &f2) void wnoise(vector4 position, int &seed, float &f1, float &f2, float &f3, float &f4) //生成周期4D noise void wnoise(vector4 position, int &seed, float &f1, float &f2, int periodx, int periody, int periodz, int periodw) void wnoise(vector4 position, int &seed, float &f1, float &f2, float &f3, float &f4, int periodx, int periody, int periodz, int periodw)
vnoise
- 生成Voronoi(蜂窝)噪波;
- 此函数与wnoise结果相近,但比wnosie稍贵;由于返回真实的点位置,可客服wnoise的一些伪影;
//生成1D noise void vnoise(float position, float jitter, int &seed, float &f1, float &f2, float &pos1, float &pos2) //生成周期1D noise void vnoise(float position, float jitter, int &seed, float &f1, float &f2, float &pos1, float &pos2, int period) //生成2D noise void vnoise(float posx, float posy, float jittx, float jitty, int &seed, float &f1, float &f2, float &pos1x, float &pos1y, float &pos2x, float &pos2y) //生成周期2D noise void vnoise(float posx, float posy, float jittx, float jitty, int &seed, float &f1, float &f2, float &pos1x, float &pos1y, float &pos2x, float &pos2, int periodx, int periody) //生成3D noise void vnoise(vector position, vector jitter, int &seed, float &f1, float &f2, vector &pos1, vector &pos2) //生成周期3D noise void vnoise(vector position, vector jitter, int &seed, float &f1, float &f2, vector &pos1, vector &pos2, int periodx, int periody, int periodz) void vnoise(vector position, vector jitter, int &seed, float &f1, float &f2, vector &pos1, vector &pos2, vector period) //生成4D noise void vnoise(vector4 position, vector4 jitter, int &seed, float &f1, float &f2, vector4 &pos1, vector4 &pos2) //生成周期4D noise void vnoise(vector4 position, vector4 jitter, int &seed, float &f1, float &f2, vector4 &pos1, vector4 &pos2, int periodx, int periody, int periodz, int periodw) void vnoise(vector4 position, vector4 jitter, int &seed, float &f1, float &f2, vector4 &pos1, vector4 &pos2, vector4 period)
pnoise
- 有两种Perlin噪波,此为周期噪波,非周期噪波是noise;
- 发布取决于维度,更高的维度接近高斯发布;
float|vector pnoise(float x, int px) float|vector pnoise(vector x, vector p) float|vector pnoise(vector4 xyzt, vector4 p) float|vector pnoise(float x, float y, int px, int py) float|vector pnoise(vector xyz, int px, int py, int pz) float|vector pnoise(vector4 xyzt, int px, int py, int pz, int pt)
xnoise
- 非常接近Perlin noise;
- 取值范围0~1,中位值为0.5;发布取决于维度,更高的维度接近高斯发布;
float xnoise(float x) vector xnoise(float x) float xnoise(float x, float y) vector xnoise(float x, float y) float xnoise(vector xyz) vector xnoise(vector xyz) float xnoise(vector4 xyzt) vector xnoise(vector4 xyzt)
curlnoise
vector curlnoise(vector xyz) vector curlnoise(vector4 xyzt)
flownoise
- 取值范围0~1,中位值为0.5;发布取决于维度,更高的维度接近高斯发布;
float flownoise(vector xyz, float flow) vector flownoise(vector xyz, float flow) float flownoise(vector4 xyzt, float flow) vector flownoise(vector4 xyzt, float flow) float flownoise(float x, float y, float flow) vector flownoise(float x, float y, float flow)
Random number generators
random
- random基于空间内的位置(1~4维度)生成一个随机数字;
- random不像noise会平滑的插值;
- random()是非常有效的方法,类似noise(floor(position));
//基于1D位置,生成对应噪波 float random(float|int position) vector random(float|int position) vector2 random(int position) vector4 random(float|int position) //基于2D位置,生成对应噪波 float random(float|int xpos, float|int ypos) vector random(float|int xpos, float|int ypos) vector4 random(float|int xpos, float|int ypos) //基于3D位置,生成对应噪波 float random(vector position) vector random(vector position) vector4 random(vector position) //基于4D位置,生成对应噪波 float random(vector4 position) vector random(vector4 position) vector4 random(vector4 position)
nrandom
- nrandom是一个非确定的随机函数;生成的数值在0~1之间;
- 如按相同顺序调用,将生成相同的随机数序列;
- 由于没有种子,不可能重复多次生成相同的随机数或序列;
float nrandom(...) vector2 nrandom(...) vector nrandom(...) vector4 nrandom(...)
//修改给定变量值,随机值0~1 void nrandom(float &x, float &y, ...)
rand
- 根据seed,生成在 [0, 1) 的随机值;
float rand(float seed) vector2 rand(float seed) vector rand(float seed) vector4 rand(float seed) float rand(float seed, float seed2) vector2 rand(float seed, float seed2) vector rand(float seed, float seed2) vector4 rand(float seed, float seed2) float rand(vector2 seed) vector2 rand(vector2 seed) vector rand(vector2 seed) vector4 rand(vector2 seed) float rand(vector seed) vector2 rand(vector seed) vector rand(vector seed) vector4 rand(vector seed) float rand(vector4 seed) vector2 rand(vector4 seed) vector rand(vector4 seed) vector4 rand(vector4 seed)
注,如需统一各个分量,可使用float()进行转化;
vector pos = 1; float seed = 0; pos *= float(rand(seed));
hscript_rand
- hscript_rand生成与Hscript rand()相同的结果;对不同的浮点种子,此函数生成不同的随机值;这不同于random(将浮点参数转化为整数种子);
- vex表达式hscript_rand与rand不同;
- hscript_rand在不同硬件或操作系统上结果可能不同;
float|vector|vector4 hscript_rand(float seed)