Skip to content

Instantly share code, notes, and snippets.

@tuttlem
Created December 31, 2013 06:26
Show Gist options
  • Save tuttlem/8193345 to your computer and use it in GitHub Desktop.
Save tuttlem/8193345 to your computer and use it in GitHub Desktop.
Noise 3
/* Linear interpolation */
float lerp(float a, float b, float x) {
return a * (1 - x) + b * x;
}
/* Trigonometric interpolation */
float terp(float a, float b, float x) {
float ft = x * 3.1415927f;
float f = (1 - cosf(ft)) * 0.5f;
return a * (1 - f) + b * f;
}
/* Noise interpolation */
float interpolateNoise(const float x, const float y) {
int ix = (int)x;
float fx = x - ix;
int iy = (int)y;
float fy = y - iy;
float v1 = smoothNoise(ix, iy),
v2 = smoothNoise(ix + 1, iy),
v3 = smoothNoise(ix, iy + 1),
v4 = smoothNoise(ix + 1, iy + 1);
float i1 = terp(v1, v2, fx),
i2 = terp(v3, v4, fx);
return terp(i1, i2, fy);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment