mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Use double-precision on all noise-related functions.
This commit is contained in:
@@ -140,7 +140,7 @@ double Noise1234::grad( int hash, double x, double y, double z, double t ) {
|
||||
//---------------------------------------------------------------------
|
||||
/** 1D float Perlin noise, SL "noise()"
|
||||
*/
|
||||
float Noise1234::noise( double x )
|
||||
double Noise1234::noise( double x )
|
||||
{
|
||||
int ix0, ix1;
|
||||
double fx0, fx1;
|
||||
@@ -156,13 +156,13 @@ float Noise1234::noise( double x )
|
||||
|
||||
n0 = grad( perm[ ix0 ], fx0 );
|
||||
n1 = grad( perm[ ix1 ], fx1 );
|
||||
return 0.188f * ( LERP( s, n0, n1 ) );
|
||||
return 0.188 * ( LERP( s, n0, n1 ) );
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
/** 1D float Perlin periodic noise, SL "pnoise()"
|
||||
*/
|
||||
float Noise1234::pnoise( double x, int px )
|
||||
double Noise1234::pnoise( double x, int px )
|
||||
{
|
||||
int ix0, ix1;
|
||||
double fx0, fx1;
|
||||
@@ -178,14 +178,14 @@ float Noise1234::pnoise( double x, int px )
|
||||
|
||||
n0 = grad( perm[ ix0 ], fx0 );
|
||||
n1 = grad( perm[ ix1 ], fx1 );
|
||||
return 0.188f * ( LERP( s, n0, n1 ) );
|
||||
return 0.188 * ( LERP( s, n0, n1 ) );
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
/** 2D float Perlin noise.
|
||||
*/
|
||||
float Noise1234::noise( double x, double y )
|
||||
double Noise1234::noise( double x, double y )
|
||||
{
|
||||
int ix0, iy0, ix1, iy1;
|
||||
double fx0, fy0, fx1, fy1;
|
||||
@@ -213,13 +213,13 @@ float Noise1234::noise( double x, double y )
|
||||
nx1 = grad(perm[ix1 + perm[iy1]], fx1, fy1);
|
||||
n1 = LERP(t, nx0, nx1);
|
||||
|
||||
return 0.507f * ( LERP( s, n0, n1 ) );
|
||||
return 0.507 * ( LERP( s, n0, n1 ) );
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
/** 2D float Perlin periodic noise.
|
||||
*/
|
||||
float Noise1234::pnoise( double x, double y, int px, int py )
|
||||
double Noise1234::pnoise( double x, double y, int px, int py )
|
||||
{
|
||||
int ix0, iy0, ix1, iy1;
|
||||
double fx0, fy0, fx1, fy1;
|
||||
@@ -247,14 +247,14 @@ float Noise1234::pnoise( double x, double y, int px, int py )
|
||||
nx1 = grad(perm[ix1 + perm[iy1]], fx1, fy1);
|
||||
n1 = LERP(t, nx0, nx1);
|
||||
|
||||
return 0.507f * ( LERP( s, n0, n1 ) );
|
||||
return 0.507 * ( LERP( s, n0, n1 ) );
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
/** 3D float Perlin noise.
|
||||
*/
|
||||
float Noise1234::noise( double x, double y, double z )
|
||||
double Noise1234::noise( double x, double y, double z )
|
||||
{
|
||||
int ix0, iy0, ix1, iy1, iz0, iz1;
|
||||
double fx0, fy0, fz0, fx1, fy1, fz1;
|
||||
@@ -301,13 +301,13 @@ float Noise1234::noise( double x, double y, double z )
|
||||
|
||||
n1 = LERP( t, nx0, nx1 );
|
||||
|
||||
return 0.936f * ( LERP( s, n0, n1 ) );
|
||||
return 0.936 * ( LERP( s, n0, n1 ) );
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
/** 3D float Perlin periodic noise.
|
||||
*/
|
||||
float Noise1234::pnoise( double x, double y, double z, int px, int py, int pz )
|
||||
double Noise1234::pnoise( double x, double y, double z, int px, int py, int pz )
|
||||
{
|
||||
int ix0, iy0, ix1, iy1, iz0, iz1;
|
||||
double fx0, fy0, fz0, fx1, fy1, fz1;
|
||||
@@ -354,7 +354,7 @@ float Noise1234::pnoise( double x, double y, double z, int px, int py, int pz )
|
||||
|
||||
n1 = LERP( t, nx0, nx1 );
|
||||
|
||||
return 0.936f * ( LERP( s, n0, n1 ) );
|
||||
return 0.936 * ( LERP( s, n0, n1 ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -362,7 +362,7 @@ float Noise1234::pnoise( double x, double y, double z, int px, int py, int pz )
|
||||
/** 4D float Perlin noise.
|
||||
*/
|
||||
|
||||
float Noise1234::noise( double x, double y, double z, double w )
|
||||
double Noise1234::noise( double x, double y, double z, double w )
|
||||
{
|
||||
int ix0, iy0, iz0, iw0, ix1, iy1, iz1, iw1;
|
||||
double fx0, fy0, fz0, fw0, fx1, fy1, fz1, fw1;
|
||||
@@ -439,14 +439,14 @@ float Noise1234::noise( double x, double y, double z, double w )
|
||||
|
||||
n1 = LERP( t, nx0, nx1 );
|
||||
|
||||
return 0.87f * ( LERP( s, n0, n1 ) );
|
||||
return 0.87 * ( LERP( s, n0, n1 ) );
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
/** 4D float Perlin periodic noise.
|
||||
*/
|
||||
|
||||
float Noise1234::pnoise( double x, double y, double z, double w,
|
||||
double Noise1234::pnoise( double x, double y, double z, double w,
|
||||
int px, int py, int pz, int pw )
|
||||
{
|
||||
int ix0, iy0, iz0, iw0, ix1, iy1, iz1, iw1;
|
||||
@@ -524,7 +524,7 @@ float Noise1234::pnoise( double x, double y, double z, double w,
|
||||
|
||||
n1 = LERP( t, nx0, nx1 );
|
||||
|
||||
return 0.87f * ( LERP( s, n0, n1 ) );
|
||||
return 0.87 * ( LERP( s, n0, n1 ) );
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
@@ -32,17 +32,17 @@ class Noise1234 {
|
||||
|
||||
/** 1D, 2D, 3D and 4D float Perlin noise, SL "noise()"
|
||||
*/
|
||||
static float noise( double x );
|
||||
static float noise( double x, double y );
|
||||
static float noise( double x, double y, double z );
|
||||
static float noise( double x, double y, double z, double w );
|
||||
static double noise( double x );
|
||||
static double noise( double x, double y );
|
||||
static double noise( double x, double y, double z );
|
||||
static double noise( double x, double y, double z, double w );
|
||||
|
||||
/** 1D, 2D, 3D and 4D float Perlin periodic noise, SL "pnoise()"
|
||||
*/
|
||||
static float pnoise( double x, int px );
|
||||
static float pnoise( double x, double y, int px, int py );
|
||||
static float pnoise( double x, double y, double z, int px, int py, int pz );
|
||||
static float pnoise( double x, double y, double z, double w,
|
||||
static double pnoise( double x, int px );
|
||||
static double pnoise( double x, double y, int px, int py );
|
||||
static double pnoise( double x, double y, double z, int px, int py, int pz );
|
||||
static double pnoise( double x, double y, double z, double w,
|
||||
int px, int py, int pz, int pw );
|
||||
|
||||
private:
|
||||
|
||||
@@ -145,7 +145,7 @@ static unsigned char simplex[64][4] = {
|
||||
{2,1,0,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,1,0,2},{0,0,0,0},{3,2,0,1},{3,2,1,0}};
|
||||
|
||||
// 1D simplex noise
|
||||
float SimplexNoise1234::noise(double x) {
|
||||
double SimplexNoise1234::noise(double x) {
|
||||
|
||||
int i0 = FASTFLOOR(x);
|
||||
int i1 = i0 + 1;
|
||||
@@ -163,12 +163,12 @@ float SimplexNoise1234::noise(double x) {
|
||||
n1 = t1 * t1 * grad(perm[i1 & 0xff], x1);
|
||||
// The maximum value of this noise is 8*(3/4)^4 = 2.53125
|
||||
// A factor of 0.395 will scale to fit exactly within [-1,1]
|
||||
return 0.395f * (n0 + n1);
|
||||
return 0.395 * (n0 + n1);
|
||||
|
||||
}
|
||||
|
||||
// 2D simplex noise
|
||||
float SimplexNoise1234::noise(double x, double y) {
|
||||
double SimplexNoise1234::noise(double x, double y) {
|
||||
|
||||
#define F2 0.366025403 // F2 = 0.5*(sqrt(3.0)-1.0)
|
||||
#define G2 0.211324865 // G2 = (3.0-Math.sqrt(3.0))/6.0
|
||||
@@ -231,11 +231,11 @@ float SimplexNoise1234::noise(double x, double y) {
|
||||
|
||||
// Add contributions from each corner to get the final noise value.
|
||||
// The result is scaled to return values in the interval [-1,1].
|
||||
return 45.23f * (n0 + n1 + n2); // TODO: The scale factor is preliminary!
|
||||
return 45.23 * (n0 + n1 + n2); // TODO: The scale factor is preliminary!
|
||||
}
|
||||
|
||||
// 3D simplex noise
|
||||
float SimplexNoise1234::noise(double x, double y, double z) {
|
||||
double SimplexNoise1234::noise(double x, double y, double z) {
|
||||
|
||||
// Simple skewing factors for the 3D case
|
||||
#define F3 0.333333333
|
||||
@@ -329,12 +329,12 @@ float SimplexNoise1234::noise(double x, double y, double z) {
|
||||
|
||||
// Add contributions from each corner to get the final noise value.
|
||||
// The result is scaled to stay just inside [-1,1]
|
||||
return 32.74f * (n0 + n1 + n2 + n3); // TODO: The scale factor is preliminary!
|
||||
return 32.74 * (n0 + n1 + n2 + n3); // TODO: The scale factor is preliminary!
|
||||
}
|
||||
|
||||
|
||||
// 4D simplex noise
|
||||
float SimplexNoise1234::noise(double x, double y, double z, double w) {
|
||||
double SimplexNoise1234::noise(double x, double y, double z, double w) {
|
||||
|
||||
// The skewing and unskewing factors are hairy again for the 4D case
|
||||
#define F4 0.309016994 // F4 = (Math.sqrt(5.0)-1.0)/4.0
|
||||
@@ -465,6 +465,6 @@ float SimplexNoise1234::noise(double x, double y, double z, double w) {
|
||||
}
|
||||
|
||||
// Sum up and scale the result to cover the range [-1,1]
|
||||
return 27.3f * (n0 + n1 + n2 + n3 + n4); // TODO: The scale factor is preliminary!
|
||||
return 27.3 * (n0 + n1 + n2 + n3 + n4); // TODO: The scale factor is preliminary!
|
||||
}
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
@@ -34,10 +34,10 @@ class SimplexNoise1234 {
|
||||
|
||||
/** 1D and 2D float Perlin noise
|
||||
*/
|
||||
static float noise( double x );
|
||||
static float noise( double x, double y );
|
||||
static float noise( double x, double y, double z );
|
||||
static float noise( double x, double y, double z, double w);
|
||||
static double noise( double x );
|
||||
static double noise( double x, double y );
|
||||
static double noise( double x, double y, double z );
|
||||
static double noise( double x, double y, double z, double w);
|
||||
|
||||
private:
|
||||
static unsigned char perm[];
|
||||
|
||||
@@ -83,14 +83,14 @@ float linearToGamma(float c);
|
||||
*
|
||||
* @return Noise value in the range of [0, 1].
|
||||
**/
|
||||
static float simplexNoise1(double x);
|
||||
static float simplexNoise2(double x, double y);
|
||||
static float simplexNoise3(double x, double y, double z);
|
||||
static float simplexNoise4(double x, double y, double z, double w);
|
||||
static float perlinNoise1(double x);
|
||||
static float perlinNoise2(double x, double y);
|
||||
static float perlinNoise3(double x, double y, double z);
|
||||
static float perlinNoise4(double x, double y, double z, double w);
|
||||
static double simplexNoise1(double x);
|
||||
static double simplexNoise2(double x, double y);
|
||||
static double simplexNoise3(double x, double y, double z);
|
||||
static double simplexNoise4(double x, double y, double z, double w);
|
||||
static double perlinNoise1(double x);
|
||||
static double perlinNoise2(double x, double y);
|
||||
static double perlinNoise3(double x, double y, double z);
|
||||
static double perlinNoise4(double x, double y, double z, double w);
|
||||
|
||||
|
||||
class Math : public Module
|
||||
@@ -136,44 +136,44 @@ private:
|
||||
}; // Math
|
||||
|
||||
|
||||
static inline float simplexNoise1(double x)
|
||||
static inline double simplexNoise1(double x)
|
||||
{
|
||||
return SimplexNoise1234::noise(x) * 0.5f + 0.5f;
|
||||
return SimplexNoise1234::noise(x) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
static inline float simplexNoise2(double x, double y)
|
||||
static inline double simplexNoise2(double x, double y)
|
||||
{
|
||||
return SimplexNoise1234::noise(x, y) * 0.5f + 0.5f;
|
||||
return SimplexNoise1234::noise(x, y) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
static inline float simplexNoise3(double x, double y, double z)
|
||||
static inline double simplexNoise3(double x, double y, double z)
|
||||
{
|
||||
return SimplexNoise1234::noise(x, y, z) * 0.5f + 0.5f;
|
||||
return SimplexNoise1234::noise(x, y, z) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
static inline float simplexNoise4(double x, double y, double z, double w)
|
||||
static inline double simplexNoise4(double x, double y, double z, double w)
|
||||
{
|
||||
return SimplexNoise1234::noise(x, y, z, w) * 0.5f + 0.5f;
|
||||
return SimplexNoise1234::noise(x, y, z, w) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
static inline float perlinNoise1(double x)
|
||||
static inline double perlinNoise1(double x)
|
||||
{
|
||||
return Noise1234::noise(x) * 0.5f + 0.5f;
|
||||
return Noise1234::noise(x) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
static inline float perlinNoise2(double x, double y)
|
||||
static inline double perlinNoise2(double x, double y)
|
||||
{
|
||||
return Noise1234::noise(x, y) * 0.5f + 0.5f;
|
||||
return Noise1234::noise(x, y) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
static inline float perlinNoise3(double x, double y, double z)
|
||||
static inline double perlinNoise3(double x, double y, double z)
|
||||
{
|
||||
return Noise1234::noise(x, y, z) * 0.5f + 0.5f;
|
||||
return Noise1234::noise(x, y, z) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
static inline float perlinNoise4(double x, double y, double z, double w)
|
||||
static inline double perlinNoise4(double x, double y, double z, double w)
|
||||
{
|
||||
return Noise1234::noise(x, y, z, w) * 0.5f + 0.5f;
|
||||
return Noise1234::noise(x, y, z, w) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
} // math
|
||||
|
||||
@@ -326,7 +326,7 @@ int w_noise(lua_State *L)
|
||||
for (int i = 0; i < nargs; i++)
|
||||
args[i] = luaL_checknumber(L, i + 1);
|
||||
|
||||
float val = 0.0f;
|
||||
double val = 0.0;
|
||||
|
||||
switch (nargs)
|
||||
{
|
||||
@@ -356,7 +356,7 @@ int w_perlinNoise(lua_State* L)
|
||||
for (int i = 0; i < nargs; i++)
|
||||
args[i] = luaL_checknumber(L, i + 1);
|
||||
|
||||
float val = 0.0f;
|
||||
double val = 0.0;
|
||||
|
||||
switch (nargs)
|
||||
{
|
||||
@@ -386,7 +386,7 @@ int w_simplexNoise(lua_State* L)
|
||||
for (int i = 0; i < nargs; i++)
|
||||
args[i] = luaL_checknumber(L, i + 1);
|
||||
|
||||
float val = 0.0f;
|
||||
double val = 0.0;
|
||||
|
||||
switch (nargs)
|
||||
{
|
||||
@@ -411,14 +411,14 @@ int w_simplexNoise(lua_State* L)
|
||||
// C functions in a struct, necessary for the FFI versions of math functions.
|
||||
struct FFI_Math
|
||||
{
|
||||
float (*snoise1)(double x);
|
||||
float (*snoise2)(double x, double y);
|
||||
float (*snoise3)(double x, double y, double z);
|
||||
float (*snoise4)(double x, double y, double z, double w);
|
||||
float (*pnoise1)(double x);
|
||||
float (*pnoise2)(double x, double y);
|
||||
float (*pnoise3)(double x, double y, double z);
|
||||
float (*pnoise4)(double x, double y, double z, double w);
|
||||
double (*snoise1)(double x);
|
||||
double (*snoise2)(double x, double y);
|
||||
double (*snoise3)(double x, double y, double z);
|
||||
double (*snoise4)(double x, double y, double z, double w);
|
||||
double (*pnoise1)(double x);
|
||||
double (*pnoise2)(double x, double y);
|
||||
double (*pnoise3)(double x, double y, double z);
|
||||
double (*pnoise4)(double x, double y, double z, double w);
|
||||
|
||||
float (*gammaToLinear)(float c);
|
||||
float (*linearToGamma)(float c);
|
||||
|
||||
@@ -93,14 +93,14 @@ if not status then return end
|
||||
pcall(ffi.cdef, [[
|
||||
typedef struct FFI_Math
|
||||
{
|
||||
float (*snoise1)(double x);
|
||||
float (*snoise2)(double x, double y);
|
||||
float (*snoise3)(double x, double y, double z);
|
||||
float (*snoise4)(double x, double y, double z, double w);
|
||||
float (*pnoise1)(double x);
|
||||
float (*pnoise2)(double x, double y);
|
||||
float (*pnoise3)(double x, double y, double z);
|
||||
float (*pnoise4)(double x, double y, double z, double w);
|
||||
double (*snoise1)(double x);
|
||||
double (*snoise2)(double x, double y);
|
||||
double (*snoise3)(double x, double y, double z);
|
||||
double (*snoise4)(double x, double y, double z, double w);
|
||||
double (*pnoise1)(double x);
|
||||
double (*pnoise2)(double x, double y);
|
||||
double (*pnoise3)(double x, double y, double z);
|
||||
double (*pnoise4)(double x, double y, double z, double w);
|
||||
|
||||
float (*gammaToLinear)(float c);
|
||||
float (*linearToGamma)(float c);
|
||||
@@ -108,7 +108,7 @@ typedef struct FFI_Math
|
||||
]])
|
||||
|
||||
local ffifuncs = ffi.cast("FFI_Math **", ffifuncspointer_str)[0]
|
||||
|
||||
local love = require("love")
|
||||
|
||||
-- Overwrite some regular love.math functions with FFI implementations.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user