mirror of
https://github.com/projectM-visualizer/projectm.git
synced 2026-03-04 06:25:08 +00:00
more noise
git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/trunk@1088 6778bc44-b910-0410-a7a0-be141de4315d
This commit is contained in:
@ -7,37 +7,30 @@
|
||||
|
||||
#include "PerlinNoise.hpp"
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
PerlinNoise::PerlinNoise()
|
||||
{
|
||||
for (int x = 0; x < 256;x++)
|
||||
for (int y = 0; y < 256;y++)
|
||||
noise_lq[x][y] = Noise(x,y);
|
||||
noise_lq[x][y] = InterpolatedNoise(x,y);
|
||||
|
||||
for (int x = 0; x < 32;x++)
|
||||
for (int y = 0; y < 32;y++)
|
||||
noise_lq_lite[x][y] = Noise(x,y);
|
||||
|
||||
int scale = 4;
|
||||
int width = 12413;
|
||||
int seed = 61;
|
||||
|
||||
int seed = rand();
|
||||
|
||||
for (int x = 0; x < 256;x++)
|
||||
for (int y = 0; y < 256;y++)
|
||||
{
|
||||
noise_mq[x][y] = perlin_noise_loop(x,y,12413,7,seed,0.5,32);
|
||||
|
||||
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);
|
||||
for (int x = 0; x < 256;x++)
|
||||
for (int y = 0; y < 256;y++)
|
||||
noise_hq[x][y] = perlin_noise_loop(x,y,12413,7,seed,0.5,64);
|
||||
|
||||
|
||||
//noise_hq[x][y] = perlin_noise_2D(x,y,5,0.5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -28,12 +28,11 @@ public:
|
||||
private:
|
||||
|
||||
|
||||
static inline float Noise(int x)
|
||||
static inline float Noise( int x)
|
||||
{
|
||||
int n = (x<<13) ^ x;
|
||||
return ( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
|
||||
|
||||
}
|
||||
x = (x<<13)^x;
|
||||
return (((x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 2147483648.0);
|
||||
}
|
||||
|
||||
static inline float Noise(int x, int y)
|
||||
{
|
||||
@ -45,8 +44,8 @@ private:
|
||||
|
||||
static inline float cos_interp(float a, float b, float x)
|
||||
{
|
||||
int ft = x * 3.1415927;
|
||||
int f = (1 - cos(ft)) * .5;
|
||||
float ft = x * 3.1415927;
|
||||
float f = (1 - cos(ft)) * .5;
|
||||
|
||||
return a*(1-f) + b*f;
|
||||
}
|
||||
@ -111,32 +110,44 @@ private:
|
||||
|
||||
}
|
||||
|
||||
static inline float perlin_noise(float x,float y, int width, int octaves, int seed, float periode){
|
||||
static inline float perlin_noise(float x,float y, int width, 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 box,num,step_x,step_y;
|
||||
|
||||
int noisedata;
|
||||
|
||||
freq=1/(float)(periode);
|
||||
freq=1/(float)(periode);
|
||||
|
||||
for ( s=0;s<octaves;s++)
|
||||
{
|
||||
num=(int)(width*freq);
|
||||
step_x=(int)(x*freq);
|
||||
step_y=(int)(y*freq);
|
||||
zone_x=x*freq-step_x;
|
||||
zone_y=y*freq-step_y;
|
||||
box=step_x+step_y*num;
|
||||
noisedata=(box+seed);
|
||||
a=InterPolation(Noise(noisedata),Noise(noisedata+1),zone_x);
|
||||
b=InterPolation(Noise(noisedata+num),Noise(noisedata+1+num),zone_x);
|
||||
value=InterPolation(a,b,zone_y)*amplitude;
|
||||
|
||||
}
|
||||
num=(int)(width*freq);
|
||||
step_x=(int)(x*freq);
|
||||
step_y=(int)(y*freq);
|
||||
zone_x=x*freq-step_x;
|
||||
zone_y=y*freq-step_y;
|
||||
box=step_x+step_y*num;
|
||||
noisedata=(box+seed);
|
||||
a=InterPolation(Noise(noisedata),Noise(noisedata+1),zone_x);
|
||||
b=InterPolation(Noise(noisedata+num),Noise(noisedata+1+num),zone_x);
|
||||
value=InterPolation(a,b,zone_y);
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
static inline float perlin_noise_loop(int x, int y, int width, int octaves, int seed, float persistance, float basePeriod)
|
||||
{
|
||||
float p = persistance;
|
||||
float val = 0.0;
|
||||
|
||||
for (int i = 0; i<octaves;i++)
|
||||
{
|
||||
val += perlin_noise(x,y,width,seed,basePeriod) * p;
|
||||
|
||||
basePeriod *= 0.5;
|
||||
p *= persistance;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
@ -114,15 +114,15 @@ PerlinNoise noise;
|
||||
|
||||
glGenTextures( 1, &noise_texture_lq );
|
||||
glBindTexture( GL_TEXTURE_2D, noise_texture_lq );
|
||||
glTexImage2D(GL_TEXTURE_2D,0,1,256,256,0,GL_LUMINANCE,GL_FLOAT,noise.noise_lq);
|
||||
glTexImage2D(GL_TEXTURE_2D,0,4,256,256,0,GL_LUMINANCE,GL_FLOAT,noise.noise_lq);
|
||||
|
||||
glGenTextures( 1, &noise_texture_lq_lite );
|
||||
glBindTexture( GL_TEXTURE_2D, noise_texture_lq_lite );
|
||||
glTexImage2D(GL_TEXTURE_2D,0,1,32,32,0,GL_LUMINANCE,GL_FLOAT,noise.noise_lq_lite);
|
||||
glTexImage2D(GL_TEXTURE_2D,0,4,32,32,0,GL_LUMINANCE,GL_FLOAT,noise.noise_lq_lite);
|
||||
|
||||
glGenTextures( 1, &noise_texture_hq );
|
||||
glBindTexture( GL_TEXTURE_2D, noise_texture_hq );
|
||||
glTexImage2D(GL_TEXTURE_2D,0,1,256,256,0,GL_LUMINANCE,GL_FLOAT,noise.noise_hq);
|
||||
glTexImage2D(GL_TEXTURE_2D,0,4,256,256,0,GL_LUMINANCE,GL_FLOAT,noise.noise_hq);
|
||||
|
||||
#endif
|
||||
}
|
||||
@ -278,7 +278,7 @@ void Renderer::SetupCgVariables(CGprogram program, const PipelineContext &contex
|
||||
cgGLSetParameter4f(cgGetNamedParameter(program, "texsize"), renderTarget->texsize, renderTarget->texsize, 1/(float)renderTarget->texsize,1/(float)renderTarget->texsize);
|
||||
cgGLSetParameter4f(cgGetNamedParameter(program, "aspect"), aspect,1,1/aspect,1);
|
||||
|
||||
cgGLSetTextureParameter(cgGetNamedParameter(program, "sampler_noise_lq"),noise_texture_lq_lite);
|
||||
cgGLSetTextureParameter(cgGetNamedParameter(program, "sampler_noise_lq"),noise_texture_lq);
|
||||
cgGLEnableTextureParameter(cgGetNamedParameter(program, "sampler_noise_lq"));
|
||||
|
||||
cgGLSetTextureParameter(cgGetNamedParameter(program, "sampler_noise_lq_lite"),noise_texture_lq_lite);
|
||||
@ -438,8 +438,6 @@ void Renderer::RenderFrame(const Pipeline* pipeline, const PipelineContext &pipe
|
||||
cgGLBindProgram(myCgWarpProgram);
|
||||
checkForCgError("binding warp program");
|
||||
|
||||
|
||||
|
||||
SetupCgVariables(myCgWarpProgram, pipelineContext);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user