OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PerlinNoise.h
Go to the documentation of this file.
1 /* -*-c++-*-
2 *
3 * OpenSceneGraph example, osgshaders.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18 * THE SOFTWARE.
19 */
20 
21 
22 /************************************************************************
23  * *
24  * Copyright (C) 2002 3Dlabs Inc. Ltd. *
25  * *
26  ***********************************************************************/
27 
28 /* Adapted from osgshaders example by Robert Osfield for use as part of osgUtil.*/
29 
30 #ifndef PERLINENOISE_H
31 #define PERLINENOISE_H
32 
33 #include <osg/Texture3D>
34 #include <osgUtil/Export>
35 
36 namespace osgUtil
37 {
38 
40 {
41 public:
42 
43  PerlinNoise();
44 
45  void SetNoiseFrequency(int frequency);
46 
47  double noise1(double arg);
48  double noise2(double vec[2]);
49  double noise3(double vec[3]);
50  void normalize2(double vec[2]);
51  void normalize3(double vec[3]);
52 
53  /*
54  In what follows "alpha" is the weight when the sum is formed.
55  Typically it is 2, As this approaches 1 the function is noisier.
56  "beta" is the harmonic scaling/spacing, typically 2.
57  */
58 
59  double PerlinNoise1D(double x,double alpha, double beta, int n);
60  double PerlinNoise2D(double x,double y,double alpha, double beta, int n);
61  double PerlinNoise3D(double x,double y,double z,double alpha, double beta, int n);
62 
63  osg::Image* create3DNoiseImage(int texSize);
64  osg::Texture3D* create3DNoiseTexture(int texSize );
65 
66 protected:
67 
68  void initNoise(void);
69 
70  enum { MAXB = 0x100 };
71 
72  int p[MAXB + MAXB + 2];
73  double g3[MAXB + MAXB + 2][3];
74  double g2[MAXB + MAXB + 2][2];
75  double g1[MAXB + MAXB + 2];
76 
77  int start;
78  int B;
79  int BM;
80 
81 };
82 
83 inline osg::Image* create3DNoiseImage(int texSize)
84 {
85  PerlinNoise pn;
86  return pn.create3DNoiseImage(texSize);
87 }
88 
89 inline osg::Texture3D* create3DNoiseTexture(int texSize )
90 {
91  PerlinNoise pn;
92  return pn.create3DNoiseTexture(texSize);
93 }
94 
95 }
96 
97 #endif // PERLINENOISE_H
osg::Texture3D * create3DNoiseTexture(int texSize)
Definition: PerlinNoise.h:89
osg::Texture3D * create3DNoiseTexture(int texSize)
osg::Image * create3DNoiseImage(int texSize)
Definition: PerlinNoise.h:83
osg::Image * create3DNoiseImage(int texSize)
#define OSGUTIL_EXPORT
Definition: Export.h:40
Shader generator framework.
Definition: RenderInfo.h:20