ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/noise.h
(Generate patch)

Comparing deliantra/server/include/noise.h (file contents):
Revision 1.8 by root, Tue Apr 26 03:18:07 2011 UTC vs.
Revision 1.9 by root, Tue Apr 26 14:41:35 2011 UTC

28 28
29#include "global.h" 29#include "global.h"
30 30
31typedef blitz::TinyVector<float,2> vec2d; 31typedef blitz::TinyVector<float,2> vec2d;
32typedef blitz::TinyVector<float,3> vec3d; 32typedef blitz::TinyVector<float,3> vec3d;
33
34/////////////////////////////////////////////////////////////////////////////
35
36template<int N, typename T = uint8_t>
37struct permutation
38{
39 T pmap[N];
40
41 template<class random_generator>
42 void seed (random_generator &rng);
43
44 T operator ()(T v)
45 {
46 return pmap[v & (N - 1)];
47 }
48};
49
50template<class vec_t>
51struct noise_gen;
52
53// modelled after 2d/3d kensler noise without projection
54template<>
55struct noise_gen<vec2d>
56{
57 static vec2d::T_numtype abs_avg() { return 0.2231; } // avg(abs(noise))
58
59 permutation<256, uint8_t> rvmap[2];
60
61 noise_gen<vec2d> (uint32_t seed);
62 vec2d::T_numtype operator() (vec2d P);
63};
64
65template<>
66struct noise_gen<vec3d>
67{
68 static vec3d::T_numtype abs_avg() { return 0.415; } // avg(abs(noise))
69
70 permutation<256, uint8_t> rvmap[3];
71
72 noise_gen<vec3d> (uint32_t seed);
73 vec2d::T_numtype operator() (vec3d P);
74
75 // noise projected on a surface with normal n
76 vec2d::T_numtype operator() (vec3d P, vec3d N);
77};
78 33
79template<class vec_t, int a, int b> 34template<class vec_t, int a, int b>
80struct rotate_nn 35struct rotate_nn
81{ 36{
82 typename vec_t::T_numtype s, c; 37 typename vec_t::T_numtype s, c;
109template<class vec_t> 64template<class vec_t>
110struct rotate_yz : rotate_nn<vec_t, 1, 2> 65struct rotate_yz : rotate_nn<vec_t, 1, 2>
111{ 66{
112}; 67};
113 68
69/////////////////////////////////////////////////////////////////////////////
70
71template<int N, typename T = uint8_t>
72struct permutation
73{
74 T pmap[N];
75
76 void seed (seedable_rand_gen &rng);
77
78 T operator ()(T v) func_pure
79 {
80 return pmap[v & (N - 1)];
81 }
82};
83
84/////////////////////////////////////////////////////////////////////////////
85
86template<class vec_t>
87struct noise_gen_base
88{
89 permutation<256, uint8_t> rvmap[vec_t::numElements];
90
91 void seed (seedable_rand_gen &rng);
92 void seed (seed_t seed);
93
94 typename vec_t::T_numtype operator ()(vec_t P) func_pure;
95};
96
97template<class vec_t>
98struct noise_gen;
99
100// modelled after 2d/3d kensler noise without projection
101template<>
102struct noise_gen<vec2d>
103: noise_gen_base<vec2d>
104{
105 static vec2d::T_numtype abs_avg() { return 0.2231; } // avg(abs(noise))
106};
107
108template<>
109struct noise_gen<vec3d>
110: noise_gen_base<vec3d>
111{
112 static vec3d::T_numtype abs_avg() { return 0.415; } // avg(abs(noise))
113
114 using noise_gen_base<vec3d>::operator ();
115
116 // noise projected on a surface with normal n
117 vec2d::T_numtype operator() (vec3d P, vec3d N) func_pure;
118};
119
120template<class vec_T>
121struct perturb_gen
122{
123 //TODO
124};
125
114template<class vec_t> 126template<class vec_t>
115struct frac_gen 127struct frac_gen
116: noise_gen<vec_t> 128: noise_gen<vec_t>
117{ 129{
118 enum { MAX_OCTAVES = 32 }; 130 enum { MAX_OCTAVES = 32 };
121 133
122 value_t h, lac, ex[MAX_OCTAVES]; 134 value_t h, lac, ex[MAX_OCTAVES];
123 value_t fbm_mul[MAX_OCTAVES]; 135 value_t fbm_mul[MAX_OCTAVES];
124 rotate_xy<vec_t> rot[MAX_OCTAVES]; 136 rotate_xy<vec_t> rot[MAX_OCTAVES];
125 137
138 frac_gen (value_t hurst_expo = .5, value_t lacunarity = 2, uint32_t seed = 0);
139
126 value_t noise (vec_t P) 140 value_t noise (vec_t P) func_pure
127 { 141 {
128 return operator() (P); 142 return operator() (P);
129 } 143 }
130 144
131 frac_gen (value_t hurst_expo = .5, value_t lacunarity = 2);
132
133 value_t fBm (vec_t P, int octaves); 145 value_t fBm (vec_t P, int octaves) func_pure;
134 value_t turbulence (vec_t P, int octaves); 146 value_t turbulence (vec_t P, int octaves) func_pure;
135 value_t multifractal (vec_t P, int octaves, value_t offset = 1); 147 value_t multifractal (vec_t P, int octaves, value_t offset = 1) func_pure;
136 value_t heterofractal (vec_t P, int octaves, value_t offset = 1); 148 value_t heterofractal (vec_t P, int octaves, value_t offset = 1) func_pure;
137 value_t hybridfractal (vec_t P, int octaves, value_t offset = 1, value_t gain = 1); 149 value_t hybridfractal (vec_t P, int octaves, value_t offset = 1, value_t gain = 1) func_pure;
138 value_t ridgedmultifractal (vec_t P, int octaves, value_t offset = 1, value_t gain = 8); 150 value_t ridgedmultifractal (vec_t P, int octaves, value_t offset = 1, value_t gain = 8) func_pure;
139 value_t billowfractal (vec_t P, int octaves, value_t offset = 1, value_t gain = 2); 151 value_t billowfractal (vec_t P, int octaves, value_t offset = 1, value_t gain = 2) func_pure;
140 value_t terrain (vec_t P, int octaves); 152 value_t terrain (vec_t P, int octaves) func_pure;
141 value_t terrain2 (vec_t P, int octaves); 153 value_t terrain2 (vec_t P, int octaves) func_pure;
142}; 154};
143 155
144#endif 156#endif
145 157

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines