bug fix
parent
dfcad45b8c
commit
262eb0e19f
|
@ -1,10 +1,15 @@
|
||||||
#version 450 core
|
#version 450 core
|
||||||
|
|
||||||
|
|
||||||
uniform sampler2D texture_basecolor;
|
uniform sampler2D texture_basecolor;
|
||||||
uniform sampler2D texture_metallic_roughness;
|
uniform sampler2D texture_metallic_roughness;
|
||||||
uniform sampler2D texture_normal;
|
uniform sampler2D texture_normal;
|
||||||
|
|
||||||
|
uniform bool texture_basecolor_available = false;
|
||||||
|
uniform bool texture_metallic_roughness_available = false;
|
||||||
|
uniform bool texture_normal_available = false;
|
||||||
|
|
||||||
|
uniform vec3 baseColor;
|
||||||
|
uniform vec2 metallicRoughness;
|
||||||
|
|
||||||
layout (location = 0) out vec4 gBaseColor;
|
layout (location = 0) out vec4 gBaseColor;
|
||||||
layout (location = 1) out vec3 gNormal;
|
layout (location = 1) out vec3 gNormal;
|
||||||
layout (location = 2) out vec3 gPosition;
|
layout (location = 2) out vec3 gPosition;
|
||||||
|
@ -15,8 +20,6 @@ in vec2 TexCoords;
|
||||||
in vec3 WorldPos;
|
in vec3 WorldPos;
|
||||||
in vec3 Normal;
|
in vec3 Normal;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
vec3 getNormalFromMap()
|
vec3 getNormalFromMap()
|
||||||
{
|
{
|
||||||
vec3 tangentNormal = texture(texture_normal, TexCoords).xyz * 2.0 - 1.0;
|
vec3 tangentNormal = texture(texture_normal, TexCoords).xyz * 2.0 - 1.0;
|
||||||
|
@ -36,22 +39,21 @@ vec3 getNormalFromMap()
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
if(textureSize(texture_basecolor,0)!=vec2(0))
|
if(texture_basecolor_available)
|
||||||
gBaseColor = texture(texture_basecolor, TexCoords);
|
gBaseColor = texture(texture_basecolor, TexCoords);
|
||||||
else
|
else
|
||||||
gBaseColor = vec4(1);
|
gBaseColor = vec4(baseColor, 1);
|
||||||
if(gBaseColor.a<0.4)
|
if(gBaseColor.a<0.4)
|
||||||
discard;
|
discard;
|
||||||
gPosition = WorldPos;
|
gPosition = WorldPos;
|
||||||
if(textureSize(texture_normal,0)!=vec2(0))
|
if(texture_normal_available)
|
||||||
gNormal = getNormalFromMap();
|
gNormal = getNormalFromMap();
|
||||||
else
|
else
|
||||||
gNormal = Normal;
|
gNormal = Normal;
|
||||||
if(textureSize(texture_metallic_roughness,0)!=vec2(0))
|
if(texture_metallic_roughness_available)
|
||||||
gMetallicRoughness = texture(texture_metallic_roughness, TexCoords).bg;
|
gMetallicRoughness = texture(texture_metallic_roughness, TexCoords).bg;
|
||||||
else
|
else
|
||||||
gMetallicRoughness = vec2(0,1);
|
gMetallicRoughness = metallicRoughness;
|
||||||
|
|
||||||
gPaintingIndex = uvec2(0);
|
|
||||||
|
|
||||||
|
gPaintingIndex = uvec2(0);
|
||||||
}
|
}
|
|
@ -204,6 +204,9 @@ void main()
|
||||||
|
|
||||||
vec3 V = normalize(camPos - worldPos);
|
vec3 V = normalize(camPos - worldPos);
|
||||||
|
|
||||||
|
if(dot(V, normal)<0)
|
||||||
|
normal = -normal;
|
||||||
|
|
||||||
vec3 F0 = vec3(0.04);
|
vec3 F0 = vec3(0.04);
|
||||||
F0 = mix(F0, albedo, metallic);
|
F0 = mix(F0, albedo, metallic);
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transfo
|
||||||
//qDebug() << leafLayer<<"------" << painterPath;
|
//qDebug() << leafLayer<<"------" << painterPath;
|
||||||
// transform to -1£¬ 1
|
// transform to -1£¬ 1
|
||||||
QTransform trans;
|
QTransform trans;
|
||||||
double maxLen = std::max(bound.width(), bound.height()) * 1.00001;
|
double maxLen = std::max(bound.width(), bound.height()) * 1.00001 * 2;
|
||||||
//qDebug() << maxLen << bound;
|
//qDebug() << maxLen << bound;
|
||||||
trans.scale(1 / maxLen, 1 / maxLen);
|
trans.scale(1 / maxLen, 1 / maxLen);
|
||||||
trans.translate(-bound.center().x(), -bound.center().y());
|
trans.translate(-bound.center().x(), -bound.center().y());
|
||||||
|
|
|
@ -28,6 +28,12 @@ void Mesh::draw()
|
||||||
shaderProgram->setUniformValue("texture_basecolor", 0);
|
shaderProgram->setUniformValue("texture_basecolor", 0);
|
||||||
shaderProgram->setUniformValue("texture_metallic_roughness", 1);
|
shaderProgram->setUniformValue("texture_metallic_roughness", 1);
|
||||||
shaderProgram->setUniformValue("texture_normal", 2);
|
shaderProgram->setUniformValue("texture_normal", 2);
|
||||||
|
shaderProgram->setUniformValue("texture_basecolor_available", textureBasecolor != 0);
|
||||||
|
shaderProgram->setUniformValue("texture_metallic_roughness_available", textureMetallicRoughness != 0);
|
||||||
|
shaderProgram->setUniformValue("texture_normal_available", textureNormal != 0);
|
||||||
|
shaderProgram->setUniformValue("model", model);
|
||||||
|
shaderProgram->setUniformValue("baseColor", baseColor);
|
||||||
|
shaderProgram->setUniformValue("metallicRoughness", metallicRoughness);
|
||||||
|
|
||||||
QOpenGLVertexArrayObject::Binder bind(&VAO);
|
QOpenGLVertexArrayObject::Binder bind(&VAO);
|
||||||
shaderProgram->setUniformValue("model", model);
|
shaderProgram->setUniformValue("model", model);
|
||||||
|
|
|
@ -43,6 +43,8 @@ namespace Renderer
|
||||||
GLuint textureBasecolor = 0;
|
GLuint textureBasecolor = 0;
|
||||||
GLuint textureMetallicRoughness = 0;
|
GLuint textureMetallicRoughness = 0;
|
||||||
GLuint textureNormal = 0;
|
GLuint textureNormal = 0;
|
||||||
|
QVector3D baseColor;
|
||||||
|
QVector2D metallicRoughness;
|
||||||
|
|
||||||
QMatrix4x4 model;
|
QMatrix4x4 model;
|
||||||
QOpenGLFunctions_4_5_Core* glFunc;
|
QOpenGLFunctions_4_5_Core* glFunc;
|
||||||
|
|
|
@ -88,14 +88,14 @@ void Renderer::Model::loadModel(QString path)
|
||||||
aiMatrix4x4::Scaling(aiVector3D(1 / 0.008), transform);
|
aiMatrix4x4::Scaling(aiVector3D(1 / 0.008), transform);
|
||||||
processNode(scene->mRootNode, scene, transform * scene->mRootNode->mTransformation);
|
processNode(scene->mRootNode, scene, transform * scene->mRootNode->mTransformation);
|
||||||
AABB.clear();
|
AABB.clear();
|
||||||
AABB.emplace_back(minX, minY, minZ);
|
AABB.emplace_back(minPos.x, minPos.y, minPos.z);
|
||||||
AABB.emplace_back(minX, minY, maxZ);
|
AABB.emplace_back(minPos.x, minPos.y, maxPos.z);
|
||||||
AABB.emplace_back(minX, maxY, minZ);
|
AABB.emplace_back(minPos.x, maxPos.y, minPos.z);
|
||||||
AABB.emplace_back(minX, maxY, maxZ);
|
AABB.emplace_back(minPos.x, maxPos.y, maxPos.z);
|
||||||
AABB.emplace_back(maxX, minY, minZ);
|
AABB.emplace_back(maxPos.x, minPos.y, minPos.z);
|
||||||
AABB.emplace_back(maxX, minY, maxZ);
|
AABB.emplace_back(maxPos.x, minPos.y, maxPos.z);
|
||||||
AABB.emplace_back(maxX, maxY, minZ);
|
AABB.emplace_back(maxPos.x, maxPos.y, minPos.z);
|
||||||
AABB.emplace_back(maxX, maxY, maxZ);
|
AABB.emplace_back(maxPos.x, maxPos.y, maxPos.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::Model::unloadModel()
|
void Renderer::Model::unloadModel()
|
||||||
|
@ -107,12 +107,8 @@ void Renderer::Model::unloadModel()
|
||||||
texturesLoaded.clear();
|
texturesLoaded.clear();
|
||||||
meshes.clear();
|
meshes.clear();
|
||||||
|
|
||||||
minX = std::numeric_limits<float>::max();
|
minPos = glm::vec3(std::numeric_limits<float>::max());
|
||||||
maxX = std::numeric_limits<float>::min();
|
maxPos = glm::vec3(std::numeric_limits<float>::min());
|
||||||
minY = std::numeric_limits<float>::max();
|
|
||||||
maxY = std::numeric_limits<float>::min();
|
|
||||||
minZ = std::numeric_limits<float>::max();
|
|
||||||
maxZ = std::numeric_limits<float>::min();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::processNode(aiNode* node, const aiScene* scene, aiMatrix4x4 mat4)
|
void Model::processNode(aiNode* node, const aiScene* scene, aiMatrix4x4 mat4)
|
||||||
|
@ -143,12 +139,8 @@ std::unique_ptr<Drawable> Model::processMesh(aiMesh* mesh, const aiScene* scene,
|
||||||
auto pos = mesh->mVertices[i];
|
auto pos = mesh->mVertices[i];
|
||||||
vertices.push_back(Vertex(pos, mesh->mNormals[i], mesh->mTextureCoords[0][i]));
|
vertices.push_back(Vertex(pos, mesh->mNormals[i], mesh->mTextureCoords[0][i]));
|
||||||
auto worldPos = model * pos;
|
auto worldPos = model * pos;
|
||||||
minX = std::min(minX, worldPos.x);
|
minPos = glm::min(minPos, glm::vec3(worldPos.x, worldPos.y, worldPos.z));
|
||||||
maxX = std::max(maxX, worldPos.x);
|
maxPos = glm::max(maxPos, glm::vec3(worldPos.x, worldPos.y, worldPos.z));
|
||||||
minY = std::min(minY, worldPos.y);
|
|
||||||
maxY = std::max(maxY, worldPos.y);
|
|
||||||
minZ = std::min(minZ, worldPos.z);
|
|
||||||
maxZ = std::max(maxZ, worldPos.z);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +154,7 @@ std::unique_ptr<Drawable> Model::processMesh(aiMesh* mesh, const aiScene* scene,
|
||||||
aiString str;
|
aiString str;
|
||||||
material->GetTexture(aiTextureType_BASE_COLOR, 0, &str);
|
material->GetTexture(aiTextureType_BASE_COLOR, 0, &str);
|
||||||
return std::string(str.C_Str());
|
return std::string(str.C_Str());
|
||||||
}()); paintingProgram != nullptr && iter != paintingMap.end())
|
}()); paintingProgram != nullptr && iter != paintingMap.end())
|
||||||
{
|
{
|
||||||
qDebug() << iter->first.c_str() << "Replaced";
|
qDebug() << iter->first.c_str() << "Replaced";
|
||||||
|
|
||||||
|
@ -193,19 +185,24 @@ std::unique_ptr<Drawable> Model::processMesh(aiMesh* mesh, const aiScene* scene,
|
||||||
mesh->indices = indices;
|
mesh->indices = indices;
|
||||||
|
|
||||||
if (!(mesh->textureBasecolor = loadMaterialTextures(material, aiTextureType_BASE_COLOR)))
|
if (!(mesh->textureBasecolor = loadMaterialTextures(material, aiTextureType_BASE_COLOR)))
|
||||||
qWarning() << "Basecolor Texture Loading Failed!";
|
|
||||||
if (!(mesh->textureMetallicRoughness = loadMaterialTextures(material, aiTextureType_METALNESS)))
|
|
||||||
qWarning() << "MetallicRoughness Texture Loading Failed!";
|
|
||||||
if (!(mesh->textureNormal = loadMaterialTextures(material, aiTextureType_NORMALS)))
|
|
||||||
qWarning() << "Normal Texture Loading Failed!";
|
|
||||||
|
|
||||||
if (mesh->textureBasecolor && mesh->textureMetallicRoughness && mesh->textureNormal)
|
|
||||||
{
|
{
|
||||||
mesh->setupMesh();
|
aiColor3D color;
|
||||||
return mesh;
|
material->Get(AI_MATKEY_BASE_COLOR, color);
|
||||||
|
mesh->baseColor = QVector3D(color.r, color.g, color.b);
|
||||||
}
|
}
|
||||||
else
|
if (!(mesh->textureMetallicRoughness = loadMaterialTextures(material, aiTextureType_METALNESS)))
|
||||||
return nullptr;
|
{
|
||||||
|
float metallic, roughness;
|
||||||
|
material->Get(AI_MATKEY_METALLIC_FACTOR, metallic);
|
||||||
|
material->Get(AI_MATKEY_ROUGHNESS_FACTOR, roughness);
|
||||||
|
mesh->metallicRoughness = QVector2D(metallic, roughness);
|
||||||
|
}
|
||||||
|
if (!(mesh->textureNormal = loadMaterialTextures(material, aiTextureType_NORMALS)))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
mesh->setupMesh();
|
||||||
|
return mesh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,8 @@ namespace Renderer
|
||||||
QDir directory; /// 模型所在路径
|
QDir directory; /// 模型所在路径
|
||||||
QString name; /// 模型文件名
|
QString name; /// 模型文件名
|
||||||
|
|
||||||
float minX, maxX, minY, maxY, minZ, maxZ;
|
glm::vec3 minPos = glm::vec3(std::numeric_limits<float>::max());
|
||||||
|
glm::vec3 maxPos = glm::vec3(std::numeric_limits<float>::min());
|
||||||
|
|
||||||
/// 递归遍历结点
|
/// 递归遍历结点
|
||||||
void processNode(aiNode* node, const aiScene* scene, aiMatrix4x4 mat4 = aiMatrix4x4());
|
void processNode(aiNode* node, const aiScene* scene, aiMatrix4x4 mat4 = aiMatrix4x4());
|
||||||
|
|
|
@ -293,7 +293,7 @@ void RendererGLWidget::paintGL()
|
||||||
|
|
||||||
gl->BeginQuery(GL_TIME_ELAPSED, timeQuery);
|
gl->BeginQuery(GL_TIME_ELAPSED, timeQuery);
|
||||||
|
|
||||||
gl->Enable(GL_CULL_FACE);
|
//gl->Enable(GL_CULL_FACE);
|
||||||
|
|
||||||
light.lightDirection.setX(cos(qDegreesToRadians(sunPitch)) * cos(qDegreesToRadians(sunYaw)));
|
light.lightDirection.setX(cos(qDegreesToRadians(sunPitch)) * cos(qDegreesToRadians(sunYaw)));
|
||||||
light.lightDirection.setY(sin(qDegreesToRadians(sunPitch)));
|
light.lightDirection.setY(sin(qDegreesToRadians(sunPitch)));
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100.45 1"><defs><style>.cls-1{fill:none;stroke:#231815;stroke-miterlimit:10;}</style></defs><g id="图层_2" data-name="图层 2"><g id="图层_1-2" data-name="图层 1"><line class="cls-1" y1="0.5" x2="100.45" y2="0.5"/></g></g></svg>
|
After Width: | Height: | Size: 288 B |
Loading…
Reference in New Issue