Some fixes for spectral mesh
This commit is contained in:
parent
4487c9ac04
commit
d33e2573a9
@ -40,7 +40,7 @@ vec3 hsv_to_rgb(float h, float s, float v)
|
|||||||
|
|
||||||
void main () {
|
void main () {
|
||||||
vec3 materialColor = hsv_to_rgb(zPos, 1, 1);
|
vec3 materialColor = hsv_to_rgb(zPos, 1, 1);
|
||||||
float diffuse = clamp(dot(normalize(norm), -normalize(vec3(0,0,1))), 0, 0.6);
|
float diffuse = clamp(dot(normalize(norm), -normalize(vec3(0,0,1))), 0.2, 0.6);
|
||||||
vec3 color = materialColor*diffuse;
|
vec3 color = materialColor*diffuse;
|
||||||
|
|
||||||
frag_colour = vec4(color, 1.0);
|
frag_colour = vec4(color, 1.0);
|
||||||
|
|||||||
@ -18,7 +18,6 @@ protected:
|
|||||||
std::vector<float> _xs;
|
std::vector<float> _xs;
|
||||||
std::vector<float> _ys;
|
std::vector<float> _ys;
|
||||||
mutable std::vector<glm::vec3> _normals;
|
mutable std::vector<glm::vec3> _normals;
|
||||||
mutable std::array<glm::vec3, 6> _adjacentTriangles;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Mesh(ShaderProgram* shader, std::size_t size);
|
Mesh(ShaderProgram* shader, std::size_t size);
|
||||||
@ -34,7 +33,6 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual float heightMap(std::size_t nx, std::size_t ny) const = 0;
|
virtual float heightMap(std::size_t nx, std::size_t ny) const = 0;
|
||||||
virtual float heightMap(float fx, float fy) const = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,13 @@ SpectralMesh::SpectralMesh(ShaderProgram *shader, std::size_t size): Mesh(shader
|
|||||||
_data = new float[size*size];
|
_data = new float[size*size];
|
||||||
_spectrLine = new float[2*size];
|
_spectrLine = new float[2*size];
|
||||||
_spectrLineComplex = (fftwf_complex*)fftwf_malloc((_size + 1)*sizeof(fftwf_complex));
|
_spectrLineComplex = (fftwf_complex*)fftwf_malloc((_size + 1)*sizeof(fftwf_complex));
|
||||||
|
|
||||||
|
float step = 1.0f/size;
|
||||||
|
for(std::size_t i = 0; i < size; ++i) {
|
||||||
|
_xs[i] = log10f(step*i + 1) - 0.5f;
|
||||||
|
_ys[i] = step*i - 0.5f;
|
||||||
|
std::cout << "[" << _xs[i] << ", " << _ys[i] << "]" << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SpectralMesh::~SpectralMesh() {
|
SpectralMesh::~SpectralMesh() {
|
||||||
@ -18,10 +25,6 @@ float SpectralMesh::heightMap(std::size_t nx, std::size_t ny) const {
|
|||||||
return *(_data + _size*ny + nx);
|
return *(_data + _size*ny + nx);
|
||||||
}
|
}
|
||||||
|
|
||||||
float SpectralMesh::heightMap(float, float) const {
|
|
||||||
return 0.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpectralMesh::addLine(float *line, std::size_t depth) {
|
void SpectralMesh::addLine(float *line, std::size_t depth) {
|
||||||
fftwf_plan plan = fftwf_plan_dft_r2c_1d(2*_size, line, _spectrLineComplex, FFTW_ESTIMATE);
|
fftwf_plan plan = fftwf_plan_dft_r2c_1d(2*_size, line, _spectrLineComplex, FFTW_ESTIMATE);
|
||||||
fftwf_execute(plan);
|
fftwf_execute(plan);
|
||||||
|
|||||||
@ -17,7 +17,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
float heightMap(std::size_t nx, std::size_t ny) const override final;
|
float heightMap(std::size_t nx, std::size_t ny) const override final;
|
||||||
float heightMap(float fx, float fy) const override final;
|
|
||||||
void normalizeArray(float* array, std::size_t size);
|
void normalizeArray(float* array, std::size_t size);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -7,12 +7,6 @@ float WaveMesh::heightMap(std::size_t nx, std::size_t ny) const {
|
|||||||
return cosf(d - _shift)*expf(-d/10.0f)/4;
|
return cosf(d - _shift)*expf(-d/10.0f)/4;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[deprecated]]
|
|
||||||
float WaveMesh::heightMap(float fx, float fy) const {
|
|
||||||
float d = 50*sqrtf(fx*fx + fy*fy);
|
|
||||||
return cosf(d - _shift)*expf(-d/10.0f)/2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WaveMesh::setShift(float shift) {
|
void WaveMesh::setShift(float shift) {
|
||||||
_shift = shift;
|
_shift = shift;
|
||||||
update();
|
update();
|
||||||
|
|||||||
@ -15,7 +15,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
float heightMap(std::size_t nx, std::size_t ny) const override final;
|
float heightMap(std::size_t nx, std::size_t ny) const override final;
|
||||||
float heightMap(float fx, float fy) const override final;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#include "OGL.h"
|
#include "OGL.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "GLObjects/WaveMesh.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@ -149,7 +150,13 @@ void OGL::run() {
|
|||||||
updateFpsCounter();
|
updateFpsCounter();
|
||||||
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
// double time = glfwGetTime();
|
||||||
|
// float shift = (float)fmod(time, 2*3.1415926);
|
||||||
|
|
||||||
for(IGLObject* obj: _glObjects) {
|
for(IGLObject* obj: _glObjects) {
|
||||||
|
// WaveMesh* mesh = dynamic_cast<WaveMesh*>(obj);
|
||||||
|
// mesh->setShift(shift*2);
|
||||||
|
|
||||||
//obj->scale(glm::vec3(1.0f, 1.0f, 1.0f));
|
//obj->scale(glm::vec3(1.0f, 1.0f, 1.0f));
|
||||||
obj->update();
|
obj->update();
|
||||||
obj->draw();
|
obj->draw();
|
||||||
|
|||||||
42
src/main.cpp
42
src/main.cpp
@ -20,32 +20,32 @@ int main(int argc, char** argv) {
|
|||||||
ShaderProgram program("../shaders/vertex.glsl", "../shaders/fragment.glsl");
|
ShaderProgram program("../shaders/vertex.glsl", "../shaders/fragment.glsl");
|
||||||
OGL::instance()->setCurShaderProgram(&program);
|
OGL::instance()->setCurShaderProgram(&program);
|
||||||
|
|
||||||
// SpectralMesh mesh(&program, 512);
|
SpectralMesh mesh(&program, 512);
|
||||||
WaveMesh mesh(&program, 128);
|
// WaveMesh mesh(&program, 128);
|
||||||
mesh.create();
|
mesh.create();
|
||||||
OGL::instance()->addObject(&mesh);
|
OGL::instance()->addObject(&mesh);
|
||||||
|
|
||||||
Camera::instance()->init();
|
Camera::instance()->init();
|
||||||
|
|
||||||
// AudioPlayer player(musicFile);
|
AudioPlayer player(musicFile);
|
||||||
// float* line = new float[2048];
|
float* line = new float[2048];
|
||||||
// memset(line, 0, 2048);
|
memset(line, 0, 2048);
|
||||||
// player.setStreamListener([&mesh, line](float *data, std::size_t framesCount, std::size_t depth, std::size_t channels) {
|
player.setStreamListener([&mesh, line](float *data, std::size_t framesCount, std::size_t depth, std::size_t channels) {
|
||||||
// memmove(line, line + 1024, 1024);
|
memmove(line, line + 1024, 1024);
|
||||||
// if(channels > 1) { // if we have more than one channel, use the first
|
if(channels > 1) { // if we have more than one channel, use the first
|
||||||
// for(std::size_t i = 0, j = 0; i < framesCount; i += channels, ++j) {
|
for(std::size_t i = 0, j = 0; i < framesCount; i += channels, ++j) {
|
||||||
// line[1024 + j] = data[i];
|
line[1024 + j] = data[i];
|
||||||
// }
|
}
|
||||||
// } else {
|
} else {
|
||||||
// memcpy(line + 1024, data, 1024);
|
memcpy(line + 1024, data, 1024);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// mesh.addLine(line, depth);
|
mesh.addLine(line, depth);
|
||||||
// mesh.addLine(line + 256, depth);
|
mesh.addLine(line + 256, depth);
|
||||||
// mesh.addLine(line + 512, depth);
|
mesh.addLine(line + 512, depth);
|
||||||
// mesh.addLine(line + 768, depth);
|
mesh.addLine(line + 768, depth);
|
||||||
// });
|
});
|
||||||
// player.play();
|
player.play();
|
||||||
|
|
||||||
OGL::instance()->run();
|
OGL::instance()->run();
|
||||||
// delete[] line;
|
// delete[] line;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user