Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ShNoise.hpp

Go to the documentation of this file.
00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2005 Serious Hack Inc.
00004 // 
00005 // This software is provided 'as-is', without any express or implied
00006 // warranty. In no event will the authors be held liable for any damages
00007 // arising from the use of this software.
00008 // 
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it
00011 // freely, subject to the following restrictions:
00012 // 
00013 // 1. The origin of this software must not be misrepresented; you must
00014 // not claim that you wrote the original software. If you use this
00015 // software in a product, an acknowledgment in the product documentation
00016 // would be appreciated but is not required.
00017 // 
00018 // 2. Altered source versions must be plainly marked as such, and must
00019 // not be misrepresented as being the original software.
00020 // 
00021 // 3. This notice may not be removed or altered from any source
00022 // distribution.
00024 #ifndef SHUTIL_NOISE_HPP 
00025 #define SHUTIL_NOISE_HPP 
00026 
00027 #include "ShAttrib.hpp"
00028 #include "ShArray.hpp"
00029 #include "ShTypeInfo.hpp"
00030 
00031 // @todo type remove these later when noise becomes part of standard library 
00032 #define CT1T2 typename ShCommonType<T1, T2>::type
00033 
00034 namespace ShUtil {
00035 
00036 
00037 using namespace SH;
00038 
00047 template<int M, typename T, int P = 16>
00048 class ShNoise 
00049 {
00050   public:
00055     template<int K>
00056     static ShGeneric<M, T> perlin(const ShGeneric<K, T> &p, bool useTexture);
00057 
00059     template<int K>
00060     static ShGeneric<M, T> cellnoise(const ShGeneric<K, T> &p, bool useTexture);
00061 
00062   private:
00063     static ShAttrib<1, SH_CONST, T> constP, invP;
00064     static bool m_init;
00065     static ShArray3D<ShAttrib<M, SH_TEMP, T, SH_COLOR> > noiseTex; 
00066 
00067     static void init();
00068 };
00069 
00070 #ifndef WIN32
00071 
00072 // Returns summed octaves of Perlin improved noise
00073 // @{
00074 template<int N, int M, typename T>
00075 ShGeneric<N, T> perlin(const ShGeneric<M, T> &p, bool useTexture = true);
00076 
00077 template<int N, int M, int K, typename T1, typename T2>
00078 ShGeneric<N, CT1T2> perlin(const ShGeneric<M, T1> &p, const ShGeneric<K, T2> &amp, bool useTexture = true);
00079 // @}
00080 
00081 // Returns summed octaves of signed Perlin improved noise
00082 // @{
00083 template<int N, int M, typename T>
00084 ShGeneric<N, T> sperlin(const ShGeneric<M, T> &p, bool useTexture = true);
00085 
00086 template<int N, int M, int K, typename T1, typename T2>
00087 ShGeneric<N, CT1T2> sperlin(const ShGeneric<M, T1> &p, const ShGeneric<K, T2> &amp, bool useTexture = true);
00088 // @}
00089 
00090 // Returns summed octaves of cell noise 
00091 // @{
00092 template<int N, int M, typename T>
00093 ShGeneric<N, T> cellnoise(const ShGeneric<M, T> &p, bool useTexture = true);
00094 
00095 template<int N, int M, int K, typename T1, typename T2>
00096 ShGeneric<N, CT1T2> cellnoise(const ShGeneric<M, T1> &p, const ShGeneric<K, T2> &amp, 
00097     bool useTexture = true);
00098 // @}
00099 
00100 // Returns summed octaves of signed cell noise 
00101 // @{
00102 template<int N, int M, typename T>
00103 ShGeneric<N, T> scellnoise(const ShGeneric<M, T> &p, bool useTexture = true);
00104 
00105 template<int N, int M, int K, typename T1, typename T2>
00106 ShGeneric<N, CT1T2> scellnoise(const ShGeneric<M, T1> &p, const ShGeneric<K, T2> &amp,
00107     bool useTexture = true); 
00108 // @}
00109 
00110 // Returns M octaves of turbulence in N-dimensional space (currently 1 <= N <= 4,
00111 // 1 <= M <= 2, 1 <= K <= 4 is supported)
00112 // The ith octave has double the frequency of the (i-1)th octave and 
00113 // is weighted by amp(i).
00114 // 
00115 // The maximum M size supported is determined by the color depth of the noise texture.
00116 // The reason it is set at 2 right now is  
00117 //
00118 // useTexture determines whether procedureal hash is used or texture lookup
00119 // @{
00120 template<int N, int M, typename T>
00121 ShGeneric<N, T> turbulence(const ShGeneric<M, T> &p, bool useTexture = true);
00122 
00123 template<int N, int M, int K, typename T1, typename T2>
00124 ShGeneric<N, CT1T2> turbulence(const ShGeneric<M, T1> &p, const ShGeneric<K, T2> &amp, 
00125     bool useTexture = true);
00126 // @}
00127 
00131 template<int N, int M, typename T>
00132 ShGeneric<N, T> sturbulence(const ShGeneric<M, T> &p, bool useTexture = true);
00133 
00134 template<int N, int M, int K, typename T1, typename T2>
00135 ShGeneric<N, CT1T2> sturbulence(const ShGeneric<M, T1> &p, const ShGeneric<K, T2> &amp, 
00136     bool useTexture = true);
00137 // @}
00138 
00139 #endif // ifndef WIN32
00140 
00141 }
00142 #include "ShNoiseImpl.hpp" 
00143 
00144 //@todo type remove these later
00145 #undef CT1T2
00146 #endif

Generated on Thu Apr 21 17:32:48 2005 for Sh by  doxygen 1.4.2