From 39ed87570bdb2f86969d4be821c94b722dc71179 Mon Sep 17 00:00:00 2001 From: Joe Ludwig Date: Wed, 26 Jun 2013 15:22:04 -0700 Subject: First version of the SOurce SDK 2013 --- sp/src/mathlib/sparse_convolution_noise.cpp | 218 ++++++++++++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 sp/src/mathlib/sparse_convolution_noise.cpp (limited to 'sp/src/mathlib/sparse_convolution_noise.cpp') diff --git a/sp/src/mathlib/sparse_convolution_noise.cpp b/sp/src/mathlib/sparse_convolution_noise.cpp new file mode 100644 index 00000000..447c5292 --- /dev/null +++ b/sp/src/mathlib/sparse_convolution_noise.cpp @@ -0,0 +1,218 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: noise() primitives. +// +//=====================================================================================// + +#include +#include "basetypes.h" +#include +#include "tier0/dbg.h" +#include "mathlib/mathlib.h" +#include "mathlib/vector.h" +#include "mathlib/noise.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + +// generate high quality noise based upon "sparse convolution". HIgher quality than perlin noise, +// and no direcitonal artifacts. + +#include "noisedata.h" + +#define N_IMPULSES_PER_CELL 5 +#define NORMALIZING_FACTOR 1.0 + +//(0.5/N_IMPULSES_PER_CELL) + +static inline int LatticeCoord(float x) +{ + return ((int) floor(x)) & 0xff; +} + +static inline int Hash4D(int ix, int iy, int iz, int idx) +{ + int ret=perm_a[ix]; + ret=perm_b[(ret+iy) & 0xff]; + ret=perm_c[(ret+iz) & 0xff]; + ret=perm_d[(ret+idx) & 0xff]; + return ret; +} + +#define SQ(x) ((x)*(x)) + +static float CellNoise( int ix, int iy, int iz, float xfrac, float yfrac, float zfrac, + float (*pNoiseShapeFunction)(float) ) +{ + float ret=0; + for(int idx=0;idx