summaryrefslogtreecommitdiffstats
path: root/source/cNoise.h
blob: a0283fc8de85219712331d802b23ad99a5f42fc5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once

// Some settings
#define NOISE_USE_INLINE 1
#define NOISE_USE_SSE 0

// Do not touch
#if NOISE_USE_INLINE
	#ifdef _MSC_VER
		#define __NOISE_INLINE__ __forceinline
	#else
		#define __NOISE_INLINE__ inline
	#endif  // _MSC_VER
#else
	#define __NOISE_INLINE__
#endif

#if NOISE_USE_SSE
# include <emmintrin.h>
#endif





class cNoise
{
public:
	cNoise( unsigned int a_Seed );
	~cNoise();

#if NOISE_USE_SSE
	__m128 SSE_IntNoise2D( int a_X1, int a_Y1, int a_X2, int a_Y2, int a_X3, int a_Y3, int a_X4, int a_Y4 ) const;
#endif

	__NOISE_INLINE__ float IntNoise( int a_X ) const;
	__NOISE_INLINE__ float IntNoise2D( int a_X, int a_Y ) const;
	__NOISE_INLINE__ float IntNoise3D( int a_X, int a_Y, int a_Z ) const;

	float LinearNoise1D( float a_X ) const;
	float CosineNoise1D( float a_X ) const;
	float CubicNoise1D( float a_X ) const;
	float SmoothNoise1D( int a_X ) const;

	float LinearNoise2D( float a_X, float a_Y ) const;
	float CosineNoise2D( float a_X, float a_Y ) const;
	float CubicNoise2D( float a_X, float a_Y ) const;
	float SSE_CubicNoise2D( float a_X, float a_Y ) const;

	float CosineNoise3D( float a_X, float a_Y, float a_Z ) const;
	float CubicNoise3D( float a_X, float a_Y, float a_Z ) const;

	void SetSeed( unsigned int a_Seed ) { m_Seed = a_Seed; }
private:
	__NOISE_INLINE__ float CubicInterpolate( float a_A, float a_B, float a_C, float a_D, float a_Pct ) const;
	__NOISE_INLINE__ float CosineInterpolate( float a_A, float a_B, float a_Pct ) const;
	__NOISE_INLINE__ float LinearInterpolate( float a_A, float a_B, float a_Pct ) const;

#if NOISE_USE_SSE
	__m128 CubicInterpolate4( const __m128 & a_A, const __m128 & a_B, const __m128 & a_C, const __m128 & a_D, float a_Pct ) const;
#endif

	unsigned int m_Seed;
};





#if NOISE_USE_INLINE
# include "cNoise.inc"
#endif