Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Perlin.h
Go to the documentation of this file.
1/*
2--------------------------------------------------------------------------------
3This source file is part of Hydrax.
4Visit ---
5
6Copyright (C) 2008 Xavier Vergu�n Gonz�lez <xavierverguin@hotmail.com>
7 <xavyiy@gmail.com>
8
9This program is free software; you can redistribute it and/or modify it under
10the terms of the GNU Lesser General Public License as published by the Free Software
11Foundation; either version 2 of the License, or (at your option) any later
12version.
13
14This program is distributed in the hope that it will be useful, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17
18You should have received a copy of the GNU Lesser General Public License along with
19this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21http://www.gnu.org/copyleft/lesser.txt.
22--------------------------------------------------------------------------------
23
24Based on the perlin noise code from Claes Johanson thesis:
25http://graphics.cs.lth.se/theses/projects/projgrid/
26--------------------------------------------------------------------------------
27*/
28
29#ifndef _Hydrax_Noise_Perlin_H_
30#define _Hydrax_Noise_Perlin_H_
31
32#include "Noise.h"
33
36
39
40#define n_bits 5
41#define n_size (1<<(n_bits-1))
42#define n_size_m1 (n_size - 1)
43#define n_size_sq (n_size*n_size)
44#define n_size_sq_m1 (n_size_sq - 1)
45
46#define n_packsize 4
47
48#define np_bits (n_bits+n_packsize-1)
49#define np_size (1<<(np_bits-1))
50#define np_size_m1 (np_size-1)
51#define np_size_sq (np_size*np_size)
52#define np_size_sq_m1 (np_size_sq-1)
53
54#define n_dec_bits 12
55#define n_dec_magn 4096
56#define n_dec_magn_m1 4095
57
58#define max_octaves 32
59
60#define noise_frames 256
61#define noise_frames_m1 (noise_frames-1)
62
63#define noise_decimalbits 15
64#define noise_magnitude (1<<(noise_decimalbits-1))
65
66#define scale_decimalbits 15
67#define scale_magnitude (1<<(scale_decimalbits-1))
68
69namespace Hydrax{ namespace Noise
70{
73 class Perlin : public Noise
74 {
75 public:
78 struct Options
79 {
83 float Scale;
85 float Falloff;
87 float Animspeed;
89 float Timemulti;
90
103 Ogre::Vector3 GPU_LODParameters;
104
108 : Octaves(8)
109 , Scale(0.085f)
110 , Falloff(0.49f)
111 , Animspeed(1.4f)
112 , Timemulti(1.27f)
113 , GPU_Strength(2.0f)
114 , GPU_LODParameters(Ogre::Vector3(0.5f, 50, 150000))
115 {
116 }
117
125 Options(const int &_Octaves,
126 const float &_Scale,
127 const float &_Falloff,
128 const float &_Animspeed,
129 const float &_Timemulti)
130 : Octaves(_Octaves)
131 , Scale(_Scale)
132 , Falloff(_Falloff)
133 , Animspeed(_Animspeed)
134 , Timemulti(_Timemulti)
135 , GPU_Strength(2.0f)
136 , GPU_LODParameters(Ogre::Vector3(0.5f, 50, 150000))
137 {
138 }
139
149 Options(const int &_Octaves,
150 const float &_Scale,
151 const float &_Falloff,
152 const float &_Animspeed,
153 const float &_Timemulti,
154 const float &_GPU_Strength,
155 const Ogre::Vector3 &_GPU_LODParameters)
156 : Octaves(_Octaves)
157 , Scale(_Scale)
158 , Falloff(_Falloff)
159 , Animspeed(_Animspeed)
160 , Timemulti(_Timemulti)
161 , GPU_Strength(_GPU_Strength)
162 , GPU_LODParameters(_GPU_LODParameters)
163 {
164 }
165 };
166
169 Perlin();
170
174 Perlin(const Options &Options);
175
178 ~Perlin();
179
182 void create();
183
186 void remove();
187
193
197 void update(const Ogre::Real &timeSinceLastFrame);
198
202 void saveCfg(Ogre::String &Data);
203
207 bool loadCfg(Ogre::ConfigFile &CfgFile);
208
215 float getValue(const float &x, const float &y);
216
221 void setOptions(const Options &Options);
222
226 inline const Options& getOptions() const
227 {
228 return mOptions;
229 }
230
231 private:
234 void _initNoise();
235
238 void _calculeNoise();
239
243
250 int _readTexelLinearDual(const int &u, const int &v, const int &o);
251
257 float _getHeigthDual(float u, float v);
258
266 int _mapSample(const int &u, const int &v, const int &upsamplepower, const int &octave);
267
274
276 double time;
277
280
283 };
284}}
285
288
289#endif
Class to manager GPU normal maps.
Base noise class, Override it for create different ways of create water noise.
Definition Noise.h:43
Perlin noise module class.
Definition Perlin.h:74
void update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
Definition Perlin.cpp:367
void _updateGPUNormalMapResources()
Update gpu normal map resources.
Definition Perlin.cpp:378
int _mapSample(const int &u, const int &v, const int &upsamplepower, const int &octave)
Map sample.
Definition Perlin.cpp:569
bool loadCfg(Ogre::ConfigFile &CfgFile)
Load config.
Definition Perlin.cpp:348
void create()
Create.
Definition Perlin.cpp:63
const Options & getOptions() const
Get current Perlin noise options.
Definition Perlin.h:226
~Perlin()
Destructor.
Definition Perlin.cpp:56
void saveCfg(Ogre::String &Data)
Save config.
Definition Perlin.cpp:335
float getValue(const float &x, const float &y)
Get the especified x/y noise value.
Definition Perlin.cpp:403
float _getHeigthDual(float u, float v)
Read texel linear.
Definition Perlin.cpp:547
Perlin()
Default constructor.
Definition Perlin.cpp:37
void remove()
Remove.
Definition Perlin.cpp:74
int noise[n_size_sq *noise_frames]
Perlin noise variables.
Definition Perlin.h:269
double time
Elapsed time.
Definition Perlin.h:276
void _initNoise()
Initialize noise.
Definition Perlin.cpp:408
int p_noise[np_size_sq *(max_octaves > >(n_packsize-1))]
Definition Perlin.h:271
int _readTexelLinearDual(const int &u, const int &v, const int &o)
Read texel linear dual.
Definition Perlin.cpp:526
GPUNormalMapManager * mGPUNormalMapManager
GPUNormalMapManager pointer.
Definition Perlin.h:279
Options mOptions
Perlin noise options.
Definition Perlin.h:282
int o_noise[n_size_sq *max_octaves]
Definition Perlin.h:270
bool createGPUNormalMapResources(GPUNormalMapManager *g)
Create GPUNormalMap resources.
Definition Perlin.cpp:126
void setOptions(const Options &Options)
Set/Update perlin noise options.
Definition Perlin.cpp:91
void _calculeNoise()
Calcule noise.
Definition Perlin.cpp:447
#define max_octaves
Definition Perlin.h:58
#define np_size_sq
Definition Perlin.h:51
#define n_size_sq
Definition Perlin.h:43
#define n_packsize
Definition Perlin.h:46
#define noise_frames
Definition Perlin.h:60
Struct wich contains Perlin noise module options.
Definition Perlin.h:79
Options(const int &_Octaves, const float &_Scale, const float &_Falloff, const float &_Animspeed, const float &_Timemulti, const float &_GPU_Strength, const Ogre::Vector3 &_GPU_LODParameters)
Constructor.
Definition Perlin.h:149
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
float Animspeed
Animspeed.
Definition Perlin.h:87
float GPU_Strength
GPU Normal map generator parameters Only if GPU normal map generation is active.
Definition Perlin.h:95
float Timemulti
Timemulti.
Definition Perlin.h:89
Options()
Default constructor.
Definition Perlin.h:107
Options(const int &_Octaves, const float &_Scale, const float &_Falloff, const float &_Animspeed, const float &_Timemulti)
Constructor.
Definition Perlin.h:125