From 0fda4a58ffb31fd361ff522fadbe44f011bb8fd6 Mon Sep 17 00:00:00 2001 From: deltaoscarmike <37912794+deltaoscarmike@users.noreply.github.com> Date: Mon, 23 Jul 2018 20:31:09 +0200 Subject: [PATCH] GL_LUMINANCE is deprecated, replacement by GL_RGB --- src/libprojectM/Renderer/PerlinNoise.cpp | 75 ++++++++++++------- src/libprojectM/Renderer/PerlinNoise.hpp | 83 ++------------------- src/libprojectM/Renderer/TextureManager.cpp | 12 +-- 3 files changed, 58 insertions(+), 112 deletions(-) diff --git a/src/libprojectM/Renderer/PerlinNoise.cpp b/src/libprojectM/Renderer/PerlinNoise.cpp index a6bda550e..fac88da3d 100644 --- a/src/libprojectM/Renderer/PerlinNoise.cpp +++ b/src/libprojectM/Renderer/PerlinNoise.cpp @@ -11,40 +11,57 @@ PerlinNoise::PerlinNoise() { - for (int x = 0; x < 256;x++) - for (int y = 0; y < 256;y++) - noise_lq[x][y] = noise(x , y); + for (int x = 0; x < 256;x++) { + for (int y = 0; y < 256;y++) { + noise_lq[x][y][0] = noise(x , y); + noise_lq[x][y][1] = noise_lq[x][y][0]; + noise_lq[x][y][2] = noise_lq[x][y][0]; + } + } - for (int x = 0; x < 32;x++) - for (int y = 0; y < 32;y++) - noise_lq_lite[x][y] = noise(4*x,16*y); + for (int x = 0; x < 32;x++) { + for (int y = 0; y < 32;y++) { + noise_lq_lite[x][y][0] = noise(4*x,16*y); + noise_lq_lite[x][y][1] = noise_lq_lite[x][y][0]; + noise_lq_lite[x][y][2] = noise_lq_lite[x][y][0]; + } + } - for (int x = 0; x < 256;x++) - for (int y = 0; y < 256;y++) - noise_mq[x][y] = InterpolatedNoise((float)x/(float)2.0,(float)y/(float)2.0); + for (int x = 0; x < 256;x++) { + for (int y = 0; y < 256;y++) { + noise_mq[x][y][0] = InterpolatedNoise((float)x/(float)2.0,(float)y/(float)2.0); + noise_mq[x][y][1] = noise_mq[x][y][0]; + noise_mq[x][y][2] = noise_mq[x][y][0]; + } + } - for (int x = 0; x < 256;x++) - for (int y = 0; y < 256;y++) - noise_hq[x][y] = InterpolatedNoise((float)x/(float)3.0,(float)y/(float)3.0); + for (int x = 0; x < 256;x++) { + for (int y = 0; y < 256;y++) { + noise_hq[x][y][0] = InterpolatedNoise((float)x/(float)3.0,(float)y/(float)3.0); + noise_hq[x][y][1] = noise_hq[x][y][0]; + noise_hq[x][y][2] = noise_hq[x][y][0]; + } + } - for (int x = 0; x < 32;x++) - for (int y = 0; y < 32;y++) - for (int z = 0; z < 32;z++) - noise_lq_vol[x][y][z] = noise(x,y,z); + for (int x = 0; x < 32;x++) { + for (int y = 0; y < 32;y++) { + for (int z = 0; z < 32;z++) { + noise_lq_vol[x][y][z][0] = noise(x,y,z); + noise_lq_vol[x][y][z][1] = noise_lq_vol[x][y][z][0]; + noise_lq_vol[x][y][z][2] = noise_lq_vol[x][y][z][0]; + } + } + } - for (int x = 0; x < 32;x++) - for (int y = 0; y < 32;y++) - for (int z = 0; z < 32;z++) - noise_hq_vol[x][y][z] = noise(x,y,z);//perlin_noise_3d(x,y,z,6121,7,seed3,0.5,64); - - int seed = rand()%1000; - - int size = 512; - int octaves = sqrt((double)size); - - for (int x = 0; x < size;x++) - for (int y = 0; y < size;y++) - noise_perlin[x][y] = perlin_noise_2d(x,y,6321,octaves,seed,0.5,size/4); + for (int x = 0; x < 32;x++) { + for (int y = 0; y < 32;y++) { + for (int z = 0; z < 32;z++) { + noise_hq_vol[x][y][z][0] = noise(x,y,z); + noise_hq_vol[x][y][z][1] = noise_hq_vol[x][y][z][0]; + noise_hq_vol[x][y][z][2] = noise_hq_vol[x][y][z][0]; + } + } + } } PerlinNoise::~PerlinNoise() diff --git a/src/libprojectM/Renderer/PerlinNoise.hpp b/src/libprojectM/Renderer/PerlinNoise.hpp index e1193d722..a999f899e 100644 --- a/src/libprojectM/Renderer/PerlinNoise.hpp +++ b/src/libprojectM/Renderer/PerlinNoise.hpp @@ -14,13 +14,12 @@ class PerlinNoise { public: - float noise_lq[256][256]; - float noise_lq_lite[32][32]; - float noise_mq[256][256]; - float noise_hq[256][256]; - float noise_perlin[512][512]; - float noise_lq_vol[32][32][32]; - float noise_hq_vol[32][32][32]; + float noise_lq[256][256][3]; + float noise_lq_lite[32][32][3]; + float noise_mq[256][256][3]; + float noise_hq[256][256][3]; + float noise_lq_vol[32][32][32][3]; + float noise_hq_vol[32][32][32][3]; PerlinNoise(); @@ -46,14 +45,6 @@ private: return noise(n); } - static inline float cos_interp(float a, float b, float x) - { - float ft = x * 3.1415927; - float f = (1 - cos(ft)) * .5; - - return a*(1-f) + b*f; - } - static inline float cubic_interp(float v0, float v1, float v2, float v3, float x) { float P = (v3 - v2) - (v0 - v1); @@ -100,53 +91,6 @@ private: } - static inline float perlin_octave_2d(float x,float y, int width, int seed, float period) - { - - float freq=1/(float)(period); - - int num=(int)(width*freq); - int step_x=(int)(x*freq); - int step_y=(int)(y*freq); - float zone_x=x*freq-step_x; - float zone_y=y*freq-step_y; - int box=step_x+step_y*num; - int noisedata=(box+seed); - - float u=cubic_interp(noise(noisedata-num-1),noise(noisedata-num),noise(noisedata-num+1),noise(noisedata-num+2),zone_x); - float a=cubic_interp(noise(noisedata-1),noise(noisedata),noise(noisedata+1),noise(noisedata+2),zone_x); - float b=cubic_interp(noise(noisedata+num -1),noise(noisedata+num),noise(noisedata+1+num),noise(noisedata+2+num),zone_x); - float v=cubic_interp(noise(noisedata+2*num -1),noise(noisedata+2*num),noise(noisedata+1+2*num),noise(noisedata+2+2*num),zone_x); - - float value=cubic_interp(u,a,b,v,zone_y); - - return value; - } - - - static inline float perlin_octave_2d_cos(float x,float y, int width, int seed, float period) - { - - float freq=1/(float)(period); - - int num=(int)(width*freq); - int step_x=(int)(x*freq); - int step_y=(int)(y*freq); - float zone_x=x*freq-step_x; - float zone_y=y*freq-step_y; - int box=step_x+step_y*num; - int noisedata=(box+seed); - - float a=cos_interp(noise(noisedata),noise(noisedata+1),zone_x); - float b=cos_interp(noise(noisedata+num),noise(noisedata+1+num),zone_x); - - float value=cos_interp(a,b,zone_y); - - return value; - } - - - static inline float perlin_octave_3d(float x,float y, float z,int width, int seed, float period) { float freq=1/(float)(period); @@ -204,21 +148,6 @@ private: } - static inline float perlin_noise_2d(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; igetSampler(GL_REPEAT, GL_LINEAR); textures["noise_lq_lite"] = textureNoise_lq_lite; @@ -90,7 +90,7 @@ TextureManager::TextureManager(const std::string _presetsURL, const int texsizeX GLuint noise_texture_lq; glGenTextures(1, &noise_texture_lq); glBindTexture(GL_TEXTURE_2D, noise_texture_lq); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_LUMINANCE, GL_FLOAT, noise.noise_lq); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGB, GL_FLOAT, noise.noise_lq); Texture * textureNoise_lq = new Texture(noise_texture_lq, GL_TEXTURE_2D, 256, 256, false); textureNoise_lq->getSampler(GL_REPEAT, GL_LINEAR); textures["noise_lq"] = textureNoise_lq; @@ -98,7 +98,7 @@ TextureManager::TextureManager(const std::string _presetsURL, const int texsizeX GLuint noise_texture_mq; glGenTextures(1, &noise_texture_mq); glBindTexture(GL_TEXTURE_2D, noise_texture_mq); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_LUMINANCE, GL_FLOAT, noise.noise_mq); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGB, GL_FLOAT, noise.noise_mq); Texture * textureNoise_mq = new Texture(noise_texture_mq, GL_TEXTURE_2D, 256, 256, false); textureNoise_mq->getSampler(GL_REPEAT, GL_LINEAR); textures["noise_mq"] = textureNoise_mq; @@ -106,7 +106,7 @@ TextureManager::TextureManager(const std::string _presetsURL, const int texsizeX GLuint noise_texture_hq; glGenTextures(1, &noise_texture_hq); glBindTexture(GL_TEXTURE_2D, noise_texture_hq); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_LUMINANCE, GL_FLOAT, noise.noise_hq); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGB, GL_FLOAT, noise.noise_hq); Texture * textureNoise_hq = new Texture(noise_texture_hq, GL_TEXTURE_2D, 256, 256, false); textureNoise_hq->getSampler(GL_REPEAT, GL_LINEAR); textures["noise_hq"] = textureNoise_hq; @@ -114,7 +114,7 @@ TextureManager::TextureManager(const std::string _presetsURL, const int texsizeX GLuint noise_texture_lq_vol; glGenTextures( 1, &noise_texture_lq_vol ); glBindTexture( GL_TEXTURE_3D, noise_texture_lq_vol ); - glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 32 ,32 ,32 ,0 ,GL_LUMINANCE ,GL_FLOAT ,noise.noise_lq_vol); + glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 32 ,32 ,32 ,0 ,GL_RGB ,GL_FLOAT ,noise.noise_lq_vol); Texture * textureNoise_lq_vol = new Texture(noise_texture_lq_vol, GL_TEXTURE_3D, 32, 32, false); textureNoise_lq_vol->getSampler(GL_REPEAT, GL_LINEAR); textures["noisevol_lq"] = textureNoise_lq_vol; @@ -122,7 +122,7 @@ TextureManager::TextureManager(const std::string _presetsURL, const int texsizeX GLuint noise_texture_hq_vol; glGenTextures( 1, &noise_texture_hq_vol ); glBindTexture( GL_TEXTURE_3D, noise_texture_hq_vol ); - glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 32, 32, 32, 0, GL_LUMINANCE, GL_FLOAT, noise.noise_hq_vol); + glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 32, 32, 32, 0, GL_RGB, GL_FLOAT, noise.noise_hq_vol); Texture * textureNoise_hq_vol = new Texture(noise_texture_hq_vol, GL_TEXTURE_3D, 32, 32, false); textureNoise_hq_vol->getSampler(GL_REPEAT, GL_LINEAR); textures["noisevol_hq"] = textureNoise_hq_vol;