diff --git a/src/projectM-engine/PerlinNoise.cpp b/src/projectM-engine/PerlinNoise.cpp index 5df7ae321..28b934b99 100644 --- a/src/projectM-engine/PerlinNoise.cpp +++ b/src/projectM-engine/PerlinNoise.cpp @@ -6,6 +6,7 @@ */ #include "PerlinNoise.hpp" +#include PerlinNoise::PerlinNoise() { @@ -17,9 +18,27 @@ PerlinNoise::PerlinNoise() for (int y = 0; y < 32;y++) noise_lq_lite[x][y] = Noise(x,y); + int scale = 4; + int width = 12413; + int seed = 61; + for (int x = 0; x < 256;x++) for (int y = 0; y < 256;y++) - noise_hq[x][y] = perlin_noise_2D(x,y,5,1.414); + { + + float disp1= perlin_noise(x*scale,y*scale,width,1,seed,100); + float disp2= perlin_noise(x*scale,y*scale,width,1,seed,25); + float disp3= perlin_noise(x*scale,y*scale,width,1,seed,12.5); + float disp4= perlin_noise(x*scale,y*scale,width,1,seed,6.25); + float disp5= perlin_noise(x*scale,y*scale,width,1,seed,3.125); + float disp6= perlin_noise(x*scale,y*scale,width,1,seed,1.56); + + noise_hq[x][y] = disp1+(disp2*.25)+(disp3*.125)+(disp4*.0625)+(disp5*.03125)+(disp6*.0156); + + + //noise_hq[x][y] = perlin_noise_2D(x,y,5,0.5); + } + } PerlinNoise::~PerlinNoise() diff --git a/src/projectM-engine/PerlinNoise.hpp b/src/projectM-engine/PerlinNoise.hpp index 0e399e59d..d6fdb7712 100644 --- a/src/projectM-engine/PerlinNoise.hpp +++ b/src/projectM-engine/PerlinNoise.hpp @@ -27,7 +27,15 @@ public: private: - static inline int Noise(int x, int y) + + static inline float Noise(int x) + { + int n = (x<<13) ^ x; + return ( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0); + + } + + static inline float Noise(int x, int y) { int n = x + y * 57; n = (n<<13) ^ n; @@ -63,10 +71,10 @@ private: static inline float InterpolatedNoise(float x, float y) { - int integer_X = int(x); + int integer_X = int(x); float fractional_X = x - integer_X; - int integer_Y = int(y); + int integer_Y = int(y); float fractional_Y = y - integer_Y; float v1 = SmoothedNoise(integer_X, integer_Y); @@ -85,18 +93,51 @@ private: { float total = 0; - for (int i = 0; i <= n; i++) + for (int i = 0; i < n; i++) { float frequency = pow(2,i); float amplitude = pow(p,i); - total = total + InterpolatedNoise(x * frequency, y * frequency) * amplitude; + total += InterpolatedNoise(x * frequency, y * frequency) * amplitude; } return total; } + static inline float InterPolation(float a, float b, float c) + { + return a+(b-a)*c*c*(3-2*c); + + } + + static inline float perlin_noise(float x,float y, int width, int octaves, int seed, float periode){ + + float a,b,value,freq,tam_pas,zone_x,zone_y; + int s,box,num,step_x,step_y; + int amplitude=1; + int noisedata; + + freq=1/(float)(periode); + + for ( s=0;s