3* OpenSceneGraph example, osgshaders.
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:
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
22/************************************************************************
24 * Copyright (C) 2002 3Dlabs Inc. Ltd. *
26 ***********************************************************************/
28/* Adapted from osgshaders example by Robert Osfield for use as part of osgUtil.*/
33#include <osg/Texture3D>
34#include <osgUtil/Export>
39class OSGUTIL_EXPORT PerlinNoise
45 void SetNoiseFrequency(int frequency);
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]);
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.
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);
63 osg::Image* create3DNoiseImage(int texSize);
64 osg::Texture3D* create3DNoiseTexture(int texSize );
70 enum { MAXB = 0x100 };
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];
83inline osg::Image* create3DNoiseImage(int texSize)
86 return pn.create3DNoiseImage(texSize);
89inline osg::Texture3D* create3DNoiseTexture(int texSize )
92 return pn.create3DNoiseTexture(texSize);
97#endif // PERLINENOISE_H