small refactoring
This commit is contained in:
@@ -191,7 +191,6 @@ void RendererBase::reloadMaterials(Scene & scene) {
|
||||
qDebug() << "[QGLEngine] Warning: Too many materials! Maximum" << max_materials;
|
||||
break;
|
||||
}
|
||||
//m->load(textures_manager);
|
||||
m->_index = cur_materials_.size();
|
||||
m->_changed = false;
|
||||
glm.color_diffuse = QColor2QVector(m->color_diffuse );
|
||||
@@ -209,8 +208,6 @@ void RendererBase::reloadMaterials(Scene & scene) {
|
||||
cur_materials_ << glm;
|
||||
}
|
||||
//qDebug() << "load" << cur_materials_.size() << "materials";
|
||||
//textures_maps.resize(maps_size, );
|
||||
//cur_materials_[0].color_diffuse = QColor2QVector(Qt::red);
|
||||
buffer_materials.bind(view);
|
||||
buffer_materials.resize(view, cur_materials_.size() * sizeof(QGLMaterial));
|
||||
buffer_materials.load(view, cur_materials_.constData(), cur_materials_.size() * sizeof(QGLMaterial));
|
||||
@@ -247,8 +244,6 @@ void RendererBase::reloadLightsParameters(const QMap<int, QList<Light*>> & light
|
||||
so.decay_intensity[1] = l->decay_linear;
|
||||
so.decay_intensity[2] = l->decay_quadratic;
|
||||
so.decay_intensity[3] = l->intensity;
|
||||
//so.shadow = shadow;
|
||||
//so.shadowColor = shadow;
|
||||
}
|
||||
buffer_lights.bind(view);
|
||||
buffer_lights.resize(view, cur_lights_params_.size() * sizeof(QGLLightParameter));
|
||||
@@ -263,12 +258,11 @@ void RendererBase::reloadLightsPositions(Camera * cam) {
|
||||
QGLLightPosition & so(cur_lights_pos_[i]);
|
||||
Light * l = current_lights[i];
|
||||
QMatrix4x4 m = mat * l->worldTransform();
|
||||
QVector4D pos(0, 0, 0, 1.), dir(QVector3D(0,0,-1), 1);//, dir0(light->dir0), dir1(light->dir1);
|
||||
QVector4D pos(0, 0, 0, 1.), dir(QVector3D(0,0,-1), 1);
|
||||
pos = m * pos;
|
||||
dir = (m * QVector4D(QVector3D(0,0,-1),0)).normalized();//((m * dir) - pos).normalized();
|
||||
dir = (m * QVector4D(QVector3D(0,0,-1),0)).normalized();
|
||||
so.position = pos;
|
||||
so.direction = dir;
|
||||
//so.shadowMatrix = l->shadow_matrix;
|
||||
}
|
||||
buffer_lights_pos.bind(view);
|
||||
buffer_lights_pos.resize(view, cur_lights_pos_.size() * sizeof(QGLLightPosition));
|
||||
@@ -279,7 +273,7 @@ void RendererBase::reloadLightsPositions(Camera * cam) {
|
||||
void RendererBase::markReloadTextures() {
|
||||
maps_hash = 0;
|
||||
textures_manager->clearImageCache();
|
||||
view->scene_->need_reload_materials = true;
|
||||
view->scene()->need_reload_materials = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -305,7 +299,7 @@ void RendererBase::renderQuad(QOpenGLShaderProgram * prog, Mesh * mesh, Camera *
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
float RadicalInverse_VdC(uint bits) {
|
||||
bits = (bits << 16u) | (bits >> 16u);
|
||||
@@ -315,10 +309,13 @@ float RadicalInverse_VdC(uint bits) {
|
||||
bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
|
||||
return float(bits) * 2.3283064365386963e-10; // / 0x100000000
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
QVector2D Hammersley(uint i, uint N) {
|
||||
return QVector2D(float(i)/float(N), RadicalInverse_VdC(i));
|
||||
}
|
||||
|
||||
|
||||
QVector3D ImportanceSampleGGX(QVector2D Xi, QVector3D N, float roughness) {
|
||||
float a = roughness*roughness;
|
||||
float phi = 2.0 * M_PI * Xi[0];
|
||||
@@ -336,12 +333,16 @@ QVector3D ImportanceSampleGGX(QVector2D Xi, QVector3D N, float roughness) {
|
||||
QVector3D sampleVec = tangent * H[0] + bitangent * H[1] + N * H[2];
|
||||
return sampleVec.normalized();
|
||||
}
|
||||
|
||||
|
||||
float GeometrySchlickGGX(float NdotV, float roughness) {
|
||||
float k = (roughness * roughness) / 2.0;
|
||||
float nom = NdotV;
|
||||
float denom = NdotV * (1.0 - k) + k;
|
||||
return nom / denom;
|
||||
}
|
||||
|
||||
|
||||
float GeometrySmith(QVector3D N, QVector3D V, QVector3D L, float roughness) {
|
||||
float NdotV = piMax(QVector3D::dotProduct(N, V), 0.f);
|
||||
float NdotL = piMax(QVector3D::dotProduct(N, L), 0.f);
|
||||
@@ -349,6 +350,8 @@ float GeometrySmith(QVector3D N, QVector3D V, QVector3D L, float roughness) {
|
||||
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
|
||||
return ggx1 * ggx2;
|
||||
}
|
||||
|
||||
|
||||
QVector2D IntegrateBRDF(float NdotV, float roughness) {
|
||||
QVector3D V;
|
||||
V[0] = sqrt(1.f - NdotV*NdotV);
|
||||
@@ -378,49 +381,19 @@ QVector2D IntegrateBRDF(float NdotV, float roughness) {
|
||||
return QVector2D(A, B);
|
||||
}
|
||||
|
||||
|
||||
void RendererBase::initCoeffTextures() {
|
||||
QImage im = QImage(":/coeffs_brdf.png").mirrored();
|
||||
int size = im.width();
|
||||
QVector<QVector2D> data(size*size);
|
||||
int ind = -1;
|
||||
for (int x = 0; x < size; ++x) {
|
||||
//float c = x / double(size - 1) + 1.E-3;
|
||||
for (int y = 0; y < size; ++y) {
|
||||
//float r = y / double(size - 1);
|
||||
QColor p = im.pixelColor(x, y);
|
||||
data[++ind] = QVector2D(p.redF(), p.greenF());//IntegrateBRDF(c, 1.f - r + 1.E-3);
|
||||
data[++ind] = QVector2D(p.redF(), p.greenF());
|
||||
}
|
||||
}
|
||||
createCoeffTexture(tex_coeff[0], data.constData(), size, 2);
|
||||
/*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);*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user