RigsofRods
Soft-body Physics Simulation
Perlin.cpp
Go to the documentation of this file.
1 /*
2 --------------------------------------------------------------------------------
3 This source file is part of Hydrax.
4 Visit ---
5 
6 Copyright (C) 2008 Xavier Vergu�n Gonz�lez <xavierverguin@hotmail.com>
7  <xavyiy@gmail.com>
8 
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
12 version.
13 
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License along with
19 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21 http://www.gnu.org/copyleft/lesser.txt.
22 --------------------------------------------------------------------------------
23 
24 Based on the perlin noise code from Claes Johanson thesis:
25 http://graphics.cs.lth.se/theses/projects/projgrid/
26 --------------------------------------------------------------------------------
27 */
28 
29 #include <Perlin.h>
30 
31 #include <Hydrax.h>
32 
33 #define _def_PackedNoise true
34 
35 namespace Hydrax{namespace Noise
36 {
38  : Noise("Perlin", true)
39  , time(0)
40  , r_noise(0)
41  , magnitude(n_dec_magn * 0.085f)
42  , mGPUNormalMapManager(0)
43  {
44  }
45 
47  : Noise("Perlin", true)
48  , mOptions(Options)
49  , time(0)
50  , r_noise(0)
51  , magnitude(n_dec_magn * Options.Scale)
52  , mGPUNormalMapManager(0)
53  {
54  }
55 
57  {
58  remove();
59 
60  HydraxLOG(getName() + " destroyed.");
61  }
62 
64  {
65  if (isCreated())
66  {
67  return;
68  }
69 
70  Noise::create();
71  _initNoise();
72  }
73 
75  {
77  {
79  }
80 
81  if (!isCreated())
82  {
83  return;
84  }
85 
86  time = 0;
87 
88  Noise::remove();
89  }
90 
92  {
93  if (isCreated())
94  {
95  int Octaves_ = Options.Octaves;
96  mOptions = Options;
97  mOptions.Octaves = Octaves_;
98 
100  {
102  getTechnique(0)->getPass(0)->
103  getVertexProgramParameters()->
104  setNamedConstant("uScale", Options.Scale);
105 
107  getTechnique(0)->getPass(0)->
108  getFragmentProgramParameters()->
109  setNamedConstant("uStrength", Options.GPU_Strength);
110 
112  getTechnique(0)->getPass(0)->
113  getFragmentProgramParameters()->
114  setNamedConstant("uLODParameters", Options.GPU_LODParameters);
115  }
116  }
117  else
118  {
119  mOptions = Options;
121  }
122 
124  }
125 
127  {
129  {
130  return false;
131  }
132 
134 
135  // Create our perlin textures
136  Ogre::TexturePtr mPerlinTexture0
137  = Ogre::TextureManager::getSingleton().
138  createManual("_Hydrax_Perlin_Noise0",
139  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
140  Ogre::TEX_TYPE_2D,
141  np_size, np_size, 0,
142  Ogre::PF_L16,
143  Ogre::TU_DYNAMIC_WRITE_ONLY);
144 
145  Ogre::TexturePtr mPerlinTexture1
146  = Ogre::TextureManager::getSingleton().
147  createManual("_Hydrax_Perlin_Noise1",
148  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
149  Ogre::TEX_TYPE_2D,
150  np_size, np_size, 0,
151  Ogre::PF_L16,
152  Ogre::TU_DYNAMIC_WRITE_ONLY);
153 
154  mGPUNormalMapManager->addTexture(mPerlinTexture0);
155  mGPUNormalMapManager->addTexture(mPerlinTexture1);
156 
157  // Create our normal map generator material
158 
159  MaterialManager *mMaterialManager = g->getHydrax()->getMaterialManager();
160 
161  Ogre::String VertexProgramData, FragmentProgramData;
162  Ogre::GpuProgramParametersSharedPtr VP_Parameters, FP_Parameters;
163  Ogre::String EntryPoints[2] = {"main_vp", "main_fp"};
164  Ogre::String GpuProgramsData[2]; Ogre::String GpuProgramNames[2];
165 
166  // Vertex program
167 
168  switch (g->getHydrax()->getShaderMode())
169  {
171  {
172  VertexProgramData +=
173  Ogre::String(
174  "void main_vp(\n") +
175  // IN
176  "float4 iPosition : POSITION,\n" +
177  // OUT
178  "out float4 oPosition : POSITION,\n" +
179  "out float3 oPosition_ : TEXCOORD0,\n" +
180  "out float4 oWorldUV : TEXCOORD1,\n" +
181  "out float oScale : TEXCOORD2,\n" +
182  "out float3 oCameraPos : TEXCOORD3,\n" +
183  "out float3 oCameraToPixel : TEXCOORD4,\n" +
184  // UNIFORM
185  "uniform float4x4 uWorldViewProj,\n" +
186  "uniform float4x4 uWorld, \n" +
187  "uniform float3 uCameraPos,\n"+
188  "uniform float uScale)\n" +
189  "{\n" +
190  "oPosition = mul(uWorldViewProj, iPosition);\n" +
191  "oPosition_ = iPosition.xyz;\n" +
192  "float2 Scale = uScale*mul(uWorld, iPosition).xz*0.0078125;\n" +
193  "oWorldUV.xy = Scale;\n" +
194  "oWorldUV.zw = Scale*16;\n" +
195  "oScale = uScale;\n" +
196  "oCameraPos = uCameraPos,\n" +
197  "oCameraToPixel = iPosition - uCameraPos;\n"+
198  "}\n";
199  }
200  break;
201 
203  {}
204  break;
205  }
206 
207  // Fragment program
208 
209  switch (g->getHydrax()->getShaderMode())
210  {
212  {
213  FragmentProgramData +=
214  Ogre::String(
215  "void main_fp(\n") +
216  // IN
217  "float3 iPosition : TEXCOORD0,\n" +
218  "float4 iWorldCoord : TEXCOORD1,\n" +
219  "float iScale : TEXCOORD2,\n" +
220  "float3 iCameraPos : TEXCOORD3,\n" +
221  "float3 iCameraToPixel : TEXCOORD4,\n" +
222  // OUT
223  "out float4 oColor : COLOR,\n" +
224  // UNIFORM
225  "uniform float uStrength,\n" +
226  "uniform float3 uLODParameters,\n" + // x: Initial derivation, y: Final derivation, z: Step
227  "uniform float3 uCameraPos,\n" +
228  "uniform sampler2D uNoise0 : register(s0),\n" +
229  "uniform sampler2D uNoise1 : register(s1))\n" +
230  "{\n" +
231  "float Distance = length(iCameraToPixel);\n" +
232  "float Attenuation = saturate(Distance/uLODParameters.z);\n" +
233 
234  "uLODParameters.x += (uLODParameters.y-uLODParameters.x)*Attenuation;\n"+
235  "uLODParameters.x *= iScale;\n" +
236 
237  "float AngleAttenuation = 1/abs(normalize(iCameraToPixel).y);\n"+
238  "uLODParameters.x *= AngleAttenuation;\n"+
239 
240  "float2 dx = float2(uLODParameters.x*0.0078125, 0);\n" +
241  "float2 dy = float2(0, dx.x);\n" +
242 
243  "float3 p_dx, m_dx, p_dy, m_dy;\n" +
244 
245  "p_dx = float3(\n" +
246  // x+
247  "iPosition.x+uLODParameters.x,\n" +
248  // y+
249  "tex2D(uNoise0, iWorldCoord.xy+dx).x + tex2D(uNoise1, iWorldCoord.zw+dx*16).x,\n" +
250  // z
251  "iPosition.z);\n" +
252 
253  "m_dx = float3(\n" +
254  // x-
255  "iPosition.x-uLODParameters.x,\n" +
256  // y-
257  "tex2D(uNoise0, iWorldCoord.xy-dx).x + tex2D(uNoise1, iWorldCoord.zw-dx*16).x,\n" +
258  // z
259  "iPosition.z);\n" +
260 
261  "p_dy = float3(\n" +
262  // x
263  "iPosition.x,\n" +
264  // y+
265  "tex2D(uNoise0, iWorldCoord.xy+dy).x + tex2D(uNoise1, iWorldCoord.zw+dy*16).x,\n" +
266  // z+
267  "iPosition.z+uLODParameters.x);\n" +
268 
269  "m_dy = float3(\n" +
270  // x
271  "iPosition.x,\n" +
272  // y-
273  "tex2D(uNoise0, iWorldCoord.xy-dy).x + tex2D(uNoise1, iWorldCoord.zw-dy*16).x,\n" +
274  // z-
275  "iPosition.z-uLODParameters.x);\n" +
276 
277  "uStrength *= (1-Attenuation);\n" +
278  "p_dx.y *= uStrength; m_dx.y *= uStrength;\n" +
279  "p_dy.y *= uStrength; m_dy.y *= uStrength;\n" +
280 
281  "float3 normal = normalize(cross(p_dx-m_dx, p_dy-m_dy));\n" +
282 
283  "oColor = float4(saturate(1-(0.5+0.5*normal)),1);\n" +
284  "}\n";
285 
286  }
287  break;
288 
290  {}
291  break;
292  }
293 
294  // Build our material
295 
296  Ogre::MaterialPtr &mNormalMapMaterial = mGPUNormalMapManager->getNormalMapMaterial();
297  mNormalMapMaterial = Ogre::MaterialManager::getSingleton().create("_Hydrax_GPU_Normal_Map_Material", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
298 
299  Ogre::Pass *Technique0_Pass0 = mNormalMapMaterial->getTechnique(0)->getPass(0);
300 
301  Technique0_Pass0->setLightingEnabled(false);
302  Technique0_Pass0->setCullingMode(Ogre::CULL_NONE);
303  Technique0_Pass0->setDepthWriteEnabled(true);
304  Technique0_Pass0->setDepthCheckEnabled(true);
305 
306  GpuProgramsData[0] = VertexProgramData; GpuProgramsData[1] = FragmentProgramData;
307  GpuProgramNames[0] = "_Hydrax_GPU_Normal_Map_VP"; GpuProgramNames[1] = "_Hydrax_GPU_Normal_Map_FP";
308 
309  mMaterialManager->fillGpuProgramsToPass(Technique0_Pass0, GpuProgramNames, g->getHydrax()->getShaderMode(), EntryPoints, GpuProgramsData);
310 
311  VP_Parameters = Technique0_Pass0->getVertexProgramParameters();
312 
313  VP_Parameters->setNamedAutoConstant("uWorldViewProj", Ogre::GpuProgramParameters::ACT_WORLDVIEWPROJ_MATRIX);
314  VP_Parameters->setNamedAutoConstant("uWorld", Ogre::GpuProgramParameters::ACT_WORLD_MATRIX);
315  VP_Parameters->setNamedAutoConstant("uCameraPos", Ogre::GpuProgramParameters::ACT_CAMERA_POSITION_OBJECT_SPACE);
316  VP_Parameters->setNamedConstant("uScale", mOptions.Scale);
317 
318  FP_Parameters = Technique0_Pass0->getFragmentProgramParameters();
319 
320  FP_Parameters->setNamedConstant("uStrength", mOptions.GPU_Strength);
321  FP_Parameters->setNamedConstant("uLODParameters", mOptions.GPU_LODParameters);
322 
323  Technique0_Pass0->createTextureUnitState(mGPUNormalMapManager->getTexture(0)->getName(), 0)
324  ->setTextureAddressingMode(Ogre::TextureUnitState::TAM_MIRROR);
325  Technique0_Pass0->createTextureUnitState(mGPUNormalMapManager->getTexture(1)->getName(), 1)
326  ->setTextureAddressingMode(Ogre::TextureUnitState::TAM_MIRROR);
327 
328  mNormalMapMaterial->load();
329 
331 
332  return true;
333  }
334 
335  void Perlin::saveCfg(Ogre::String &Data)
336  {
337  Noise::saveCfg(Data);
338 
339  Data += CfgFileManager::_getCfgString("Perlin_Octaves", mOptions.Octaves);
340  Data += CfgFileManager::_getCfgString("Perlin_Scale", mOptions.Scale);
341  Data += CfgFileManager::_getCfgString("Perlin_Falloff", mOptions.Falloff);
342  Data += CfgFileManager::_getCfgString("Perlin_Animspeed", mOptions.Animspeed);
343  Data += CfgFileManager::_getCfgString("Perlin_Timemulti", mOptions.Timemulti);
344  Data += CfgFileManager::_getCfgString("Perlin_GPU_Strength", mOptions.GPU_Strength);
345  Data += CfgFileManager::_getCfgString("Perlin_GPU_LODParameters", mOptions.GPU_LODParameters); Data += "\n";
346  }
347 
348  bool Perlin::loadCfg(Ogre::ConfigFile &CfgFile)
349  {
350  if (!Noise::loadCfg(CfgFile))
351  {
352  return false;
353  }
354 
355  setOptions(
356  Options(CfgFileManager::_getIntValue(CfgFile,"Perlin_Octaves"),
357  CfgFileManager::_getFloatValue(CfgFile,"Perlin_Scale"),
358  CfgFileManager::_getFloatValue(CfgFile,"Perlin_Falloff"),
359  CfgFileManager::_getFloatValue(CfgFile,"Perlin_Animspeed"),
360  CfgFileManager::_getFloatValue(CfgFile,"Perlin_Timemulti"),
361  CfgFileManager::_getFloatValue(CfgFile,"Perlin_GPU_Strength"),
362  CfgFileManager::_getVector3Value(CfgFile,"Perlin_GPU_LODParameters")));
363 
364  return true;
365  }
366 
367  void Perlin::update(const Ogre::Real &timeSinceLastFrame)
368  {
369  time += timeSinceLastFrame*mOptions.Animspeed;
370  _calculeNoise();
371 
373  {
375  }
376  }
377 
379  {
380  unsigned short *Data;
381  int Offset;
382  Ogre::HardwarePixelBufferSharedPtr PixelBuffer;
383 
384  for (int k = 0; k < 2; k++)
385  {
386  Offset = np_size_sq*k;
387  PixelBuffer = mGPUNormalMapManager->getTexture(k)->getBuffer();
388 
389  PixelBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);
390  const Ogre::PixelBox& PixelBox = PixelBuffer->getCurrentLock();
391 
392  Data = reinterpret_cast<unsigned short*>(PixelBox.data);
393 
394  for (int u = 0; u < np_size_sq; u++)
395  {
396  Data[u] = 32768+p_noise[u+Offset];//std::cout << p_noise[u+Offset] << std::endl;
397  }
398 
399  PixelBuffer->unlock();
400  }
401  }
402 
403  float Perlin::getValue(const float &x, const float &y)
404  {
405  return _getHeigthDual(x, y);
406  }
407 
409  {
410  // Create noise (uniform)
411  float tempnoise[n_size_sq*noise_frames], temp;
412 
413  int i, frame, v, u,
414  v0, v1, v2, u0, u1, u2, f;
415 
416  for(i=0; i<(n_size_sq*noise_frames); i++)
417  {
418  temp = static_cast<float>(rand())/RAND_MAX;
419  tempnoise[i] = 4*(temp - 0.5f);
420  }
421 
422  for(frame=0; frame<noise_frames; frame++)
423  {
424  for(v=0; v<n_size; v++)
425  {
426  for(u=0; u<n_size; u++)
427  {
428  v0 = ((v-1)&n_size_m1)*n_size;
429  v1 = v*n_size;
430  v2 = ((v+1)&n_size_m1)*n_size;
431  u0 = ((u-1)&n_size_m1);
432  u1 = u;
433  u2 = ((u+1)&n_size_m1);
434  f = frame*n_size_sq;
435 
436  temp = (1.0f/14.0f) *
437  (tempnoise[f + v0 + u0] + tempnoise[f + v0 + u1] + tempnoise[f + v0 + u2] +
438  tempnoise[f + v1 + u0] + 6.0f*tempnoise[f + v1 + u1] + tempnoise[f + v1 + u2] +
439  tempnoise[f + v2 + u0] + tempnoise[f + v2 + u1] + tempnoise[f + v2 + u2]);
440 
441  noise[frame*n_size_sq + v*n_size + u] = noise_magnitude*temp;
442  }
443  }
444  }
445  }
446 
448  {
449  int i, o, v, u,
450  multitable[max_octaves],
451  amount[3],
452  iImage;
453 
454  unsigned int image[3];
455 
456  float sum = 0.0f,
457  f_multitable[max_octaves];
458 
459  double dImage, fraction;
460 
461  // calculate the strength of each octave
462  for(i=0; i<mOptions.Octaves; i++)
463  {
464  f_multitable[i] = powf(mOptions.Falloff,1.0f*i);
465  sum += f_multitable[i];
466  }
467 
468  for(i=0; i<mOptions.Octaves; i++)
469  {
470  f_multitable[i] /= sum;
471  }
472 
473  for(i=0; i<mOptions.Octaves; i++)
474  {
475  multitable[i] = scale_magnitude*f_multitable[i];
476  }
477 
478  double r_timemulti = 1.0;
479  const float PI_3 = Ogre::Math::PI/3;
480 
481  for(o=0; o<mOptions.Octaves; o++)
482  {
483  fraction = modf(time*r_timemulti,&dImage);
484  iImage = static_cast<int>(dImage);
485 
486  amount[0] = scale_magnitude*f_multitable[o]*(pow(sin((fraction+2)*PI_3),2)/1.5);
487  amount[1] = scale_magnitude*f_multitable[o]*(pow(sin((fraction+1)*PI_3),2)/1.5);
488  amount[2] = scale_magnitude*f_multitable[o]*(pow(sin((fraction )*PI_3),2)/1.5);
489 
490  image[0] = (iImage ) & noise_frames_m1;
491  image[1] = (iImage+1) & noise_frames_m1;
492  image[2] = (iImage+2) & noise_frames_m1;
493 
494  for (i=0; i<n_size_sq; i++)
495  {
496  o_noise[i + n_size_sq*o] = (
497  ((amount[0] * noise[i + n_size_sq * image[0]])>>scale_decimalbits) +
498  ((amount[1] * noise[i + n_size_sq * image[1]])>>scale_decimalbits) +
499  ((amount[2] * noise[i + n_size_sq * image[2]])>>scale_decimalbits));
500  }
501 
502  r_timemulti *= mOptions.Timemulti;
503  }
504 
505  if(_def_PackedNoise)
506  {
507  int octavepack = 0;
508  for(o=0; o<mOptions.Octaves; o+=n_packsize)
509  {
510  for(v=0; v<np_size; v++)
511  {
512  for(u=0; u<np_size; u++)
513  {
514  p_noise[v*np_size+u+octavepack*np_size_sq] = o_noise[(o+3)*n_size_sq + (v&n_size_m1)*n_size + (u&n_size_m1)];
515  p_noise[v*np_size+u+octavepack*np_size_sq] += _mapSample( u, v, 3, o);
516  p_noise[v*np_size+u+octavepack*np_size_sq] += _mapSample( u, v, 2, o+1);
517  p_noise[v*np_size+u+octavepack*np_size_sq] += _mapSample( u, v, 1, o+2);
518  }
519  }
520 
521  octavepack++;
522  }
523  }
524  }
525 
526  int Perlin::_readTexelLinearDual(const int &u, const int &v,const int &o)
527  {
528  int iu, iup, iv, ivp, fu, fv,
529  ut01, ut23, ut;
530 
531  iu = (u>>n_dec_bits)&np_size_m1;
532  iv = ((v>>n_dec_bits)&np_size_m1)*np_size;
533 
534  iup = ((u>>n_dec_bits) + 1)&np_size_m1;
535  ivp = (((v>>n_dec_bits) + 1)&np_size_m1)*np_size;
536 
537  fu = u & n_dec_magn_m1;
538  fv = v & n_dec_magn_m1;
539 
540  ut01 = ((n_dec_magn-fu)*r_noise[iv + iu] + fu*r_noise[iv + iup])>>n_dec_bits;
541  ut23 = ((n_dec_magn-fu)*r_noise[ivp + iu] + fu*r_noise[ivp + iup])>>n_dec_bits;
542  ut = ((n_dec_magn-fv)*ut01 + fv*ut23) >> n_dec_bits;
543 
544  return ut;
545  }
546 
547  float Perlin::_getHeigthDual(float u, float v)
548  {
549  // Pointer to the current noise source octave
550  r_noise = p_noise;
551 
552  int ui = u*magnitude,
553  vi = v*magnitude,
554  i,
555  value = 0,
556  hoct = mOptions.Octaves / n_packsize;
557 
558  for(i=0; i<hoct; i++)
559  {
560  value += _readTexelLinearDual(ui,vi,0);
561  ui = ui << n_packsize;
562  vi = vi << n_packsize;
563  r_noise += np_size_sq;
564  }
565 
566  return static_cast<float>(value)/noise_magnitude;
567  }
568 
569  int Perlin::_mapSample(const int &u, const int &v, const int &upsamplepower, const int &octave)
570  {
571  int magnitude = 1<<upsamplepower,
572 
573  pu = u >> upsamplepower,
574  pv = v >> upsamplepower,
575 
576  fu = u & (magnitude-1),
577  fv = v & (magnitude-1),
578 
579  fu_m = magnitude - fu,
580  fv_m = magnitude - fv,
581 
582  o = fu_m*fv_m*o_noise[octave*n_size_sq + ((pv) &n_size_m1)*n_size + ((pu) &n_size_m1)] +
583  fu* fv_m*o_noise[octave*n_size_sq + ((pv) &n_size_m1)*n_size + ((pu+1)&n_size_m1)] +
584  fu_m*fv* o_noise[octave*n_size_sq + ((pv+1)&n_size_m1)*n_size + ((pu) &n_size_m1)] +
585  fu* fv* o_noise[octave*n_size_sq + ((pv+1)&n_size_m1)*n_size + ((pu+1)&n_size_m1)];
586 
587  return o >> (upsamplepower+upsamplepower);
588  }
589 }}
Hydrax::Noise::Perlin::getValue
float getValue(const float &x, const float &y)
Get the especified x/y noise value.
Definition: Perlin.cpp:403
Hydrax::Noise::Perlin::o_noise
int o_noise[n_size_sq *max_octaves]
Definition: Perlin.h:270
Hydrax::GPUNormalMapManager::getTexture
Ogre::TexturePtr & getTexture(const int &Index)
Get a texture.
Definition: GPUNormalMapManager.h:111
Hydrax::Noise::Noise::remove
virtual void remove()
Remove.
Definition: Noise.cpp:47
Hydrax::Noise::Perlin::noise
int noise[n_size_sq *noise_frames]
Perlin noise variables.
Definition: Perlin.h:269
Hydrax::Noise::Perlin::r_noise
int * r_noise
Definition: Perlin.h:272
scale_magnitude
#define scale_magnitude
Definition: Perlin.h:67
n_size_sq
#define n_size_sq
Definition: Perlin.h:43
Hydrax::Noise::Perlin::remove
void remove()
Remove.
Definition: Perlin.cpp:74
y
float y
Definition: (ValueTypes) quaternion.h:6
Hydrax::Noise::Noise::createGPUNormalMapResources
virtual bool createGPUNormalMapResources(GPUNormalMapManager *g)
Create GPUNormalMap resources.
Definition: Noise.cpp:52
Hydrax::MaterialManager::SM_GLSL
@ SM_GLSL
Definition: MaterialManager.h:95
Hydrax::Noise::Noise::create
virtual void create()
Create.
Definition: Noise.cpp:42
Hydrax::GPUNormalMapManager::getNormalMapMaterial
Ogre::MaterialPtr & getNormalMapMaterial()
Get the normal map material.
Definition: GPUNormalMapManager.h:102
Hydrax::Noise::Perlin::Options::Octaves
int Octaves
Octaves.
Definition: Perlin.h:81
Hydrax
Definition: CfgFileManager.cpp:28
Hydrax::Noise::Perlin::_getHeigthDual
float _getHeigthDual(float u, float v)
Read texel linear.
Definition: Perlin.cpp:547
Hydrax::Hydrax::getMaterialManager
MaterialManager * getMaterialManager()
Get Hydrax::MaterialManager.
Definition: Hydrax.h:325
Hydrax.h
Hydrax::Noise::Perlin::Options::Falloff
float Falloff
Falloff.
Definition: Perlin.h:85
Hydrax::Noise::Perlin::createGPUNormalMapResources
bool createGPUNormalMapResources(GPUNormalMapManager *g)
Create GPUNormalMap resources.
Definition: Perlin.cpp:126
n_packsize
#define n_packsize
Definition: Perlin.h:46
Hydrax::MaterialManager
Material/Shader manager class.
Definition: MaterialManager.h:44
Hydrax::Noise::Noise::removeGPUNormalMapResources
virtual void removeGPUNormalMapResources(GPUNormalMapManager *g)
Remove GPUNormalMap resources.
Definition: Noise.cpp:71
Hydrax::Noise::Noise::loadCfg
virtual bool loadCfg(Ogre::ConfigFile &CfgFile)
Load config.
Definition: Noise.cpp:87
Hydrax::Noise::Noise::saveCfg
virtual void saveCfg(Ogre::String &Data)
Save config.
Definition: Noise.cpp:81
noise_frames_m1
#define noise_frames_m1
Definition: Perlin.h:61
Hydrax::GPUNormalMapManager::addTexture
void addTexture(Ogre::TexturePtr &Texture)
Create a texture.
Definition: GPUNormalMapManager.h:119
Hydrax::GPUNormalMapManager
Class to manager GPU normal maps.
Definition: GPUNormalMapManager.h:45
Hydrax::Noise::Perlin::saveCfg
void saveCfg(Ogre::String &Data)
Save config.
Definition: Perlin.cpp:335
Hydrax::Hydrax::getShaderMode
const MaterialManager::ShaderMode & getShaderMode() const
Get current shader mode.
Definition: Hydrax.h:405
_def_PackedNoise
#define _def_PackedNoise
Definition: Perlin.cpp:33
Hydrax::CfgFileManager::_getVector3Value
static Ogre::Vector3 _getVector3Value(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
Get vector3 value.
Definition: CfgFileManager.cpp:489
np_size
#define np_size
Definition: Perlin.h:49
Hydrax::Noise::Perlin::magnitude
float magnitude
Definition: Perlin.h:273
Perlin.h
Hydrax::Noise::Perlin::Options::GPU_Strength
float GPU_Strength
GPU Normal map generator parameters Only if GPU normal map generation is active.
Definition: Perlin.h:95
Hydrax::Noise::Perlin::_initNoise
void _initNoise()
Initialize noise.
Definition: Perlin.cpp:408
Hydrax::Noise::Noise::getName
const Ogre::String & getName() const
Get noise name.
Definition: Noise.h:92
Hydrax::Noise::Perlin::Options::Timemulti
float Timemulti
Timemulti.
Definition: Perlin.h:89
Hydrax::MaterialManager::fillGpuProgramsToPass
bool fillGpuProgramsToPass(Ogre::Pass *Pass, const Ogre::String GpuProgramNames[2], const ShaderMode &SM, const Ogre::String EntryPoints[2], const Ogre::String Data[2])
Fill GPU vertex and fragment program to a pass.
Definition: MaterialManager.cpp:239
Hydrax::MaterialManager::SM_HLSL
@ SM_HLSL
Definition: MaterialManager.h:91
Hydrax::Noise::Noise
Base noise class, Override it for create different ways of create water noise.
Definition: Noise.h:42
noise_magnitude
#define noise_magnitude
Definition: Perlin.h:64
Hydrax::Noise::Perlin::_calculeNoise
void _calculeNoise()
Calcule noise.
Definition: Perlin.cpp:447
np_size_m1
#define np_size_m1
Definition: Perlin.h:50
n_dec_magn
#define n_dec_magn
Definition: Perlin.h:55
Hydrax::Noise::Perlin::time
double time
Elapsed time.
Definition: Perlin.h:276
HydraxLOG
#define HydraxLOG(msg)
Definition: Application.h:59
noise_frames
#define noise_frames
Definition: Perlin.h:60
n_dec_bits
#define n_dec_bits
Definition: Perlin.h:54
Hydrax::Noise::Perlin::_mapSample
int _mapSample(const int &u, const int &v, const int &upsamplepower, const int &octave)
Map sample.
Definition: Perlin.cpp:569
Hydrax::Noise::Perlin::mGPUNormalMapManager
GPUNormalMapManager * mGPUNormalMapManager
GPUNormalMapManager pointer.
Definition: Perlin.h:279
Hydrax::Noise::Perlin::Options::Animspeed
float Animspeed
Animspeed.
Definition: Perlin.h:87
Hydrax::Noise::Perlin::_updateGPUNormalMapResources
void _updateGPUNormalMapResources()
Update gpu normal map resources.
Definition: Perlin.cpp:378
Hydrax::GPUNormalMapManager::getHydrax
Hydrax * getHydrax()
Get the Hydrax parent pointer.
Definition: GPUNormalMapManager.h:94
Hydrax::Noise::Perlin::update
void update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
Definition: Perlin.cpp:367
Hydrax::CfgFileManager::_getCfgString
static Ogre::String _getCfgString(const Ogre::String &Name, const int &Value)
Definition: CfgFileManager.cpp:155
Hydrax::Noise::Perlin::Perlin
Perlin()
Default constructor.
Definition: Perlin.cpp:37
scale_decimalbits
#define scale_decimalbits
Definition: Perlin.h:66
np_size_sq
#define np_size_sq
Definition: Perlin.h:51
Hydrax::Noise::Perlin::mOptions
Options mOptions
Perlin noise options.
Definition: Perlin.h:282
Hydrax::Noise::Perlin::_readTexelLinearDual
int _readTexelLinearDual(const int &u, const int &v, const int &o)
Read texel linear dual.
Definition: Perlin.cpp:526
Hydrax::Noise::Noise::areGPUNormalMapResourcesCreated
const bool & areGPUNormalMapResourcesCreated() const
Are GPU normal map resources created?
Definition: Noise.h:116
Hydrax::GPUNormalMapManager::create
void create()
Create.
Definition: GPUNormalMapManager.cpp:47
Hydrax::Noise::Perlin::loadCfg
bool loadCfg(Ogre::ConfigFile &CfgFile)
Load config.
Definition: Perlin.cpp:348
Hydrax::Noise::Perlin::Options::GPU_LODParameters
Ogre::Vector3 GPU_LODParameters
LOD Parameters, in order to obtain a smooth normal map we need to decrease the detail level when the ...
Definition: Perlin.h:103
Hydrax::Noise::Perlin::Options::Scale
float Scale
Scale.
Definition: Perlin.h:83
Hydrax::Noise::Perlin::Options
Struct wich contains Perlin noise module options.
Definition: Perlin.h:78
n_size
#define n_size
Definition: Perlin.h:41
n_dec_magn_m1
#define n_dec_magn_m1
Definition: Perlin.h:56
Hydrax::Noise::Perlin::p_noise
int p_noise[np_size_sq *(max_octaves >>(n_packsize-1))]
Definition: Perlin.h:271
Hydrax::Noise::Perlin::create
void create()
Create.
Definition: Perlin.cpp:63
n_size_m1
#define n_size_m1
Definition: Perlin.h:42
Hydrax::CfgFileManager::_getIntValue
static int _getIntValue(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
Get int value.
Definition: CfgFileManager.cpp:432
Hydrax::Noise::Noise::isCreated
const bool & isCreated() const
Is created() called?
Definition: Noise.h:100
Hydrax::Noise::Perlin::setOptions
void setOptions(const Options &Options)
Set/Update perlin noise options.
Definition: Perlin.cpp:91
Hydrax::MaterialManager::SM_CG
@ SM_CG
Definition: MaterialManager.h:93
max_octaves
#define max_octaves
Definition: Perlin.h:58
Hydrax::CfgFileManager::_getFloatValue
static Ogre::Real _getFloatValue(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
Get float value.
Definition: CfgFileManager.cpp:446
Hydrax::Noise::Perlin::~Perlin
~Perlin()
Destructor.
Definition: Perlin.cpp:56
x
float x
Definition: (ValueTypes) quaternion.h:5
Hydrax::Noise::Noise::isGPUNormalMapSupported
const bool & isGPUNormalMapSupported() const
Is GPU Normal map generation supported.
Definition: Noise.h:108