git-svn-id: svn://db.shs.com.ru/libs@701 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2019-12-13 23:15:59 +00:00
parent cac73a63f1
commit 2136b4d30b
22 changed files with 653 additions and 671 deletions

View File

@@ -19,6 +19,7 @@
#define GL_GLEXT_PROTOTYPES
#include <QOpenGLExtraFunctions>
#include "renderer_base.h"
#include "renderer.h"
#include "qglview.h"
#include "glmesh.h"
#include "gltexture_manager.h"
@@ -38,6 +39,7 @@ RendererBase::RendererBase(QGLView * view_):
textures_manager = new TextureManager(view);
maps_size = QSize(512, 512);
maps_hash = 0;
tex_coeff[0] = tex_coeff[1] = 0;
}
@@ -145,7 +147,7 @@ void RendererBase::reloadMaterials(Scene & scene) {
foreach (Material * m, scene.materials) {
if (m->map_diffuse .hasBitmap()) maps[0] << &(m->map_diffuse );
if (m->map_normal .hasBitmap()) maps[1] << &(m->map_normal );
if (m->map_specular .hasBitmap()) maps[0] << &(m->map_specular );
if (m->map_metalness.hasBitmap()) maps[0] << &(m->map_metalness);
if (m->map_roughness.hasBitmap()) maps[0] << &(m->map_roughness);
if (m->map_emission .hasBitmap()) maps[0] << &(m->map_emission );
if (m->map_relief .hasBitmap()) maps[0] << &(m->map_relief );
@@ -189,7 +191,6 @@ void RendererBase::reloadMaterials(Scene & scene) {
m->_index = cur_materials_.size();
m->_changed = false;
glm.color_diffuse = QColor2QVector(m->color_diffuse );
glm.color_specular = QColor2QVector(m->color_specular);
glm.color_emission = QColor2QVector(m->color_emission);
glm.transparency = m->transparency;
glm.reflectivity = m->reflectivity;
@@ -197,7 +198,7 @@ void RendererBase::reloadMaterials(Scene & scene) {
glm.dispersion = m->dispersion ;
m->map_diffuse .copyToQGLMap(glm.map[mtDiffuse ]);
m->map_normal .copyToQGLMap(glm.map[mtNormal ]);
m->map_specular .copyToQGLMap(glm.map[mtSpecular ]);
m->map_metalness.copyToQGLMap(glm.map[mtMetalness ]);
m->map_roughness.copyToQGLMap(glm.map[mtRoughness]);
m->map_emission .copyToQGLMap(glm.map[mtEmission ]);
m->map_relief .copyToQGLMap(glm.map[mtRelief ]);
@@ -298,3 +299,50 @@ void RendererBase::renderQuad(QOpenGLShaderProgram * prog, Mesh * mesh, Camera *
setUniformCamera(prog, cam, false);
mesh->draw(view, 1);
}
void RendererBase::initCoeffTextures() {
/*const int size = 512;
QVector<float> data_diff(size*size), data_spec(size*size);
double r, c, c2;
int ind = -1;
for (int x = 0; x < size; ++x) {
c = x / double(size - 1);
c = sqrt(c);
c = piMax(1.E-16, c);
c2 = c*c;
for (int y = 0; y < size; ++y) {
r = y / double(size - 1);
double r_d = r;
double r_s = r*r*r;
r_d = piMax(1.E-16, r_d);
r_s = piMax(1.E-16, r_s);
double ndlc = (1. - c2) / c2;
double diff = 2. / (1. + sqrt(1. + (1. - r_d) * ndlc));
double spec = c2 * (r_s + ndlc);
spec = r_s / (spec * spec) / M_PI;
++ind;
data_diff[ind] = piClamp(diff, 1.E-12, 1.E+36);
data_spec[ind] = piClamp(spec, 1.E-12, 1.E+36);
}
}
createCoeffTexture(tex_coeff[0], data_diff, size);
createCoeffTexture(tex_coeff[1], data_spec, size);*/
}
void RendererBase::createCoeffTexture(GLuint & id, const QVector<float> & data, int size) {
QOpenGLExtraFunctions * f = view;
deleteGLTexture(f, id);
f->glGenTextures(1, &id);
f->glBindTexture(GL_TEXTURE_2D, id);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
f->glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, size, size, 0, GL_RED, GL_FLOAT, data.constData());
}