Definition at line 49 of file noise_value.cpp.
Public Member Functions | |
| CRandomGrid3D () | |
Static Public Member Functions | |
| float | evalBiLinear (const CVector &pos) |
| float | evalNearest (const CVector &pos) |
| const CVector & | getLevelPhase (uint level) |
| float | getLevelSize (uint level) |
Static Private Member Functions | |
| void | easeInEaseOut (float &y, float x) |
| float | lookup (uint ux, uint uy, uint uz) |
Static Private Attributes | |
| CVector | _LevelPhase [3] |
| float | _Sizes [3] |
| uint8 | _Texture3d [(1<< 5)*(1<< 5)*(1<< 5)] |
|
|
Definition at line 54 of file noise_value.cpp. References _LevelPhase, _Sizes, _Texture3d, NLMISC::frand(), NL3D_NOISE_GRID_SIZE, NL3D_NOISE_GRID_SIZE_SHIFT, NL3D_NOISE_LEVEL, uint, v, NLMISC::CVector::x, x, NLMISC::CVector::y, y, NLMISC::CVector::z, and z.
00055 {
00056 //seed
00057 srand(0);
00058
00059 // init the grid
00060 for(uint z=0; z<NL3D_NOISE_GRID_SIZE; z++)
00061 {
00062 for(uint y=0; y<NL3D_NOISE_GRID_SIZE; y++)
00063 {
00064 for(uint x=0; x<NL3D_NOISE_GRID_SIZE; x++)
00065 {
00066 uint id= x + (y<<NL3D_NOISE_GRID_SIZE_SHIFT) + (z<<(NL3D_NOISE_GRID_SIZE_SHIFT*2));
00067 // take higher bits of rand gives better result.
00068 uint v= rand() >> 5;
00069 _Texture3d[id]= v&255;
00070 }
00071 }
00072 }
00073
00074 // init sizes.
00075 uint i;
00076 // sum of sizes must be 1, and each level must be /2.
00077 float sizeSum=0;
00078 for(i=0; i<NL3D_NOISE_LEVEL; i++)
00079 {
00080 _Sizes[i]= 1.0f / (1<<i);
00081 sizeSum+= _Sizes[i];
00082 }
00083 // normalize
00084 for(i=0; i<NL3D_NOISE_LEVEL; i++)
00085 {
00086 _Sizes[i]/= sizeSum;
00087 }
00088
00089 // init LevelPhases.
00090 for(i=0; i<NL3D_NOISE_LEVEL; i++)
00091 {
00092 _LevelPhase[i].x= frand(NL3D_NOISE_GRID_SIZE);
00093 _LevelPhase[i].y= frand(NL3D_NOISE_GRID_SIZE);
00094 _LevelPhase[i].z= frand(NL3D_NOISE_GRID_SIZE);
00095 }
00096 // not for level 0.
00097 _LevelPhase[0]= CVector::Null;
00098 }
|
|
||||||||||||
|
Definition at line 191 of file noise_value.cpp. Referenced by evalBiLinear().
|
|
|
Definition at line 119 of file noise_value.cpp. References easeInEaseOut(), lookup(), NL3D_NOISE_GRID_SIZE, NLMISC::NL3D_OO255, NLMISC::OptFastFloor(), sint, uint, NLMISC::CVector::x, x, NLMISC::CVector::y, y, NLMISC::CVector::z, and z.
00120 {
00121 // compute integer part.
00122 sint x= OptFastFloor(pos.x);
00123 sint y= OptFastFloor(pos.y);
00124 sint z= OptFastFloor(pos.z);
00125 // index in texture.
00126 uint ux= x& (NL3D_NOISE_GRID_SIZE-1);
00127 uint uy= y& (NL3D_NOISE_GRID_SIZE-1);
00128 uint uz= z& (NL3D_NOISE_GRID_SIZE-1);
00129 uint ux2= (x+1)& (NL3D_NOISE_GRID_SIZE-1);
00130 uint uy2= (y+1)& (NL3D_NOISE_GRID_SIZE-1);
00131 uint uz2= (z+1)& (NL3D_NOISE_GRID_SIZE-1);
00132 // delta.
00133 float dx2;
00134 float dy2;
00135 float dz2;
00136 easeInEaseOut(dx2, pos.x-x);
00137 easeInEaseOut(dy2, pos.y-y);
00138 easeInEaseOut(dz2, pos.z-z);
00139 float dx= 1-dx2;
00140 float dy= 1-dy2;
00141 float dz= 1-dz2;
00142 // TriLinear in texture3D.
00143 float turb=0;
00144 float dxdy= dx*dy;
00145 turb+= lookup(ux,uy,uz)* dxdy*dz;
00146 turb+= lookup(ux,uy,uz2)* dxdy*dz2;
00147 float dxdy2= dx*dy2;
00148 turb+= lookup(ux,uy2,uz)* dxdy2*dz;
00149 turb+= lookup(ux,uy2,uz2)* dxdy2*dz2;
00150 float dx2dy= dx2*dy;
00151 turb+= lookup(ux2,uy,uz)* dx2dy*dz;
00152 turb+= lookup(ux2,uy,uz2)* dx2dy*dz2;
00153 float dx2dy2= dx2*dy2;
00154 turb+= lookup(ux2,uy2,uz)* dx2dy2*dz;
00155 turb+= lookup(ux2,uy2,uz2)* dx2dy2*dz2;
00156
00157 // End!
00158 return turb*NL3D_OO255;
00159 }
|
|
|
Definition at line 101 of file noise_value.cpp. References lookup(), NL3D_NOISE_GRID_SIZE, NLMISC::NL3D_OO255, NLMISC::OptFastFloor(), sint, uint, NLMISC::CVector::x, x, NLMISC::CVector::y, y, NLMISC::CVector::z, and z.
00102 {
00103 // compute integer part.
00104 sint x= OptFastFloor(pos.x);
00105 sint y= OptFastFloor(pos.y);
00106 sint z= OptFastFloor(pos.z);
00107 // index in texture.
00108 uint ux= x& (NL3D_NOISE_GRID_SIZE-1);
00109 uint uy= y& (NL3D_NOISE_GRID_SIZE-1);
00110 uint uz= z& (NL3D_NOISE_GRID_SIZE-1);
00111
00112 // read the texture.
00113 float turb= lookup(ux,uy,uz);
00114
00115 return turb*NL3D_OO255;
00116 }
|
|
|
Definition at line 169 of file noise_value.cpp. References _LevelPhase, level, and uint.
00170 {
00171 return _LevelPhase[level];
00172 }
|
|
|
Definition at line 163 of file noise_value.cpp. References _Sizes, level, and uint.
|
|
||||||||||||||||
|
Definition at line 184 of file noise_value.cpp. References _Texture3d, NL3D_NOISE_GRID_SIZE_SHIFT, and uint. Referenced by evalBiLinear(), and evalNearest().
00185 {
00186 uint id= ux + (uy<<NL3D_NOISE_GRID_SIZE_SHIFT) + (uz<<(NL3D_NOISE_GRID_SIZE_SHIFT*2));
00187 return _Texture3d[id];
00188 }
|
|
|
Definition at line 204 of file noise_value.cpp. Referenced by CRandomGrid3D(), and getLevelPhase(). |
|
|
Definition at line 203 of file noise_value.cpp. Referenced by CRandomGrid3D(), and getLevelSize(). |
|
|
Definition at line 202 of file noise_value.cpp. Referenced by CRandomGrid3D(), and lookup(). |
1.3.6