mirror of
https://github.com/overte-org/overte.git
synced 2025-04-26 10:16:19 +02:00
Merge pull request #5926 from samcake/calvin
HIghlight issue not solved, but a few fixes along the way
This commit is contained in:
commit
c201ed1b04
9 changed files with 79 additions and 24 deletions
|
@ -934,7 +934,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
||||||
_textureContent.insert(filename, content);
|
_textureContent.insert(filename, content);
|
||||||
}
|
}
|
||||||
} else if (object.name == "Material") {
|
} else if (object.name == "Material") {
|
||||||
FBXMaterial material(glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0f), glm::vec3(), glm::vec2(0.f, 1.0f), 96.0f, 1.0f);
|
FBXMaterial material;
|
||||||
foreach (const FBXNode& subobject, object.children) {
|
foreach (const FBXNode& subobject, object.children) {
|
||||||
bool properties = false;
|
bool properties = false;
|
||||||
QByteArray propertyName;
|
QByteArray propertyName;
|
||||||
|
@ -954,9 +954,17 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
||||||
if (property.name == propertyName) {
|
if (property.name == propertyName) {
|
||||||
if (property.properties.at(0) == "DiffuseColor") {
|
if (property.properties.at(0) == "DiffuseColor") {
|
||||||
material.diffuseColor = getVec3(property.properties, index);
|
material.diffuseColor = getVec3(property.properties, index);
|
||||||
|
} else if (property.properties.at(0) == "Diffuse") {
|
||||||
|
material.diffuseColor = getVec3(property.properties, index);
|
||||||
|
} else if (property.properties.at(0) == "DiffuseFactor") {
|
||||||
|
material.diffuseFactor = property.properties.at(index).value<double>();
|
||||||
|
|
||||||
} else if (property.properties.at(0) == "SpecularColor") {
|
} else if (property.properties.at(0) == "SpecularColor") {
|
||||||
material.specularColor = getVec3(property.properties, index);
|
material.specularColor = getVec3(property.properties, index);
|
||||||
|
} else if (property.properties.at(0) == "Specular") {
|
||||||
|
material.specularColor = getVec3(property.properties, index);
|
||||||
|
} else if (property.properties.at(0) == "SpecularFactor") {
|
||||||
|
material.specularFactor = property.properties.at(index).value<double>();
|
||||||
|
|
||||||
} else if (property.properties.at(0) == "Emissive") {
|
} else if (property.properties.at(0) == "Emissive") {
|
||||||
material.emissiveColor = getVec3(property.properties, index);
|
material.emissiveColor = getVec3(property.properties, index);
|
||||||
|
|
|
@ -146,12 +146,15 @@ public:
|
||||||
shininess(shininess),
|
shininess(shininess),
|
||||||
opacity(opacity) {}
|
opacity(opacity) {}
|
||||||
|
|
||||||
glm::vec3 diffuseColor;
|
glm::vec3 diffuseColor{ 1.0f };
|
||||||
glm::vec3 specularColor;
|
float diffuseFactor = 1.0f;
|
||||||
glm::vec3 emissiveColor;
|
glm::vec3 specularColor{ 0.02f };
|
||||||
glm::vec2 emissiveParams;
|
float specularFactor = 1.0f;
|
||||||
float shininess;
|
|
||||||
float opacity;
|
glm::vec3 emissiveColor{ 0.0f };
|
||||||
|
glm::vec2 emissiveParams{ 0.0f, 1.0f };
|
||||||
|
float shininess = 23.0f;
|
||||||
|
float opacity = 1.0f;
|
||||||
|
|
||||||
QString materialID;
|
QString materialID;
|
||||||
model::MaterialPointer _material;
|
model::MaterialPointer _material;
|
||||||
|
|
|
@ -134,12 +134,16 @@ void FBXReader::consolidateFBXMaterials() {
|
||||||
// Finally create the true material representation
|
// Finally create the true material representation
|
||||||
material._material = std::make_shared<model::Material>();
|
material._material = std::make_shared<model::Material>();
|
||||||
material._material->setEmissive(material.emissiveColor);
|
material._material->setEmissive(material.emissiveColor);
|
||||||
if (glm::all(glm::equal(material.diffuseColor, glm::vec3(0.0f)))) {
|
|
||||||
material._material->setDiffuse(material.diffuseColor);
|
auto diffuse = material.diffuseColor;
|
||||||
} else {
|
// FIXME: Do not use the Diffuse Factor yet as some FBX models have it set to 0
|
||||||
material._material->setDiffuse(material.diffuseColor);
|
// diffuse *= material.diffuseFactor;
|
||||||
}
|
material._material->setDiffuse(diffuse);
|
||||||
material._material->setMetallic(glm::length(material.specularColor));
|
|
||||||
|
float metallic = std::max(material.specularColor.x, std::max(material.specularColor.y, material.specularColor.z));
|
||||||
|
// FIXME: Do not use the Specular Factor yet as some FBX models have it set to 0
|
||||||
|
// metallic *= material.specularFactor;
|
||||||
|
material._material->setMetallic(metallic);
|
||||||
material._material->setGloss(material.shininess);
|
material._material->setGloss(material.shininess);
|
||||||
|
|
||||||
if (material.opacity <= 0.0f) {
|
if (material.opacity <= 0.0f) {
|
||||||
|
|
|
@ -418,10 +418,10 @@ void GLBackend::resetStages() {
|
||||||
#define DO_IT_NOW(call, offset)
|
#define DO_IT_NOW(call, offset)
|
||||||
|
|
||||||
void Batch::_glActiveBindTexture(GLenum unit, GLenum target, GLuint texture) {
|
void Batch::_glActiveBindTexture(GLenum unit, GLenum target, GLuint texture) {
|
||||||
|
// clean the cache on the texture unit we are going to use so the next call to setResourceTexture() at the same slot works fine
|
||||||
setResourceTexture(unit - GL_TEXTURE0, nullptr);
|
setResourceTexture(unit - GL_TEXTURE0, nullptr);
|
||||||
|
|
||||||
ADD_COMMAND_GL(glActiveBindTexture);
|
ADD_COMMAND_GL(glActiveBindTexture);
|
||||||
|
|
||||||
_params.push_back(texture);
|
_params.push_back(texture);
|
||||||
_params.push_back(target);
|
_params.push_back(target);
|
||||||
_params.push_back(unit);
|
_params.push_back(unit);
|
||||||
|
@ -434,6 +434,7 @@ void GLBackend::do_glActiveBindTexture(Batch& batch, uint32 paramOffset) {
|
||||||
glBindTexture(
|
glBindTexture(
|
||||||
batch._params[paramOffset + 1]._uint,
|
batch._params[paramOffset + 1]._uint,
|
||||||
batch._params[paramOffset + 0]._uint);
|
batch._params[paramOffset + 0]._uint);
|
||||||
|
|
||||||
(void) CHECK_GL_ERROR();
|
(void) CHECK_GL_ERROR();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -230,12 +230,15 @@ NetworkTexture::TextureLoaderFunc NetworkTexture::getTextureLoader() const {
|
||||||
return TextureLoaderFunc(model::TextureUsage::createNormalTextureFromBumpImage);
|
return TextureLoaderFunc(model::TextureUsage::createNormalTextureFromBumpImage);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case NORMAL_TEXTURE: {
|
||||||
|
return TextureLoaderFunc(model::TextureUsage::createNormalTextureFromNormalImage);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case CUSTOM_TEXTURE: {
|
case CUSTOM_TEXTURE: {
|
||||||
return _textureLoader;
|
return _textureLoader;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DEFAULT_TEXTURE:
|
case DEFAULT_TEXTURE:
|
||||||
case NORMAL_TEXTURE:
|
|
||||||
case SPECULAR_TEXTURE:
|
case SPECULAR_TEXTURE:
|
||||||
case EMISSIVE_TEXTURE:
|
case EMISSIVE_TEXTURE:
|
||||||
default: {
|
default: {
|
||||||
|
|
|
@ -137,6 +137,40 @@ gpu::Texture* TextureUsage::create2DTextureFromImage(const QImage& srcImage, con
|
||||||
return theTexture;
|
return theTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gpu::Texture* TextureUsage::createNormalTextureFromNormalImage(const QImage& srcImage, const std::string& srcImageName) {
|
||||||
|
QImage image = srcImage;
|
||||||
|
|
||||||
|
if (!image.hasAlphaChannel()) {
|
||||||
|
if (image.format() != QImage::Format_RGB888) {
|
||||||
|
image = image.convertToFormat(QImage::Format_RGB888);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (image.format() != QImage::Format_ARGB32) {
|
||||||
|
image = image.convertToFormat(QImage::Format_ARGB32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gpu::Texture* theTexture = nullptr;
|
||||||
|
if ((image.width() > 0) && (image.height() > 0)) {
|
||||||
|
|
||||||
|
bool isLinearRGB = true;
|
||||||
|
|
||||||
|
gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB));
|
||||||
|
gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB));
|
||||||
|
if (image.hasAlphaChannel()) {
|
||||||
|
formatGPU = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::RGBA : gpu::SRGBA));
|
||||||
|
formatMip = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::BGRA : gpu::SBGRA));
|
||||||
|
}
|
||||||
|
|
||||||
|
theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
||||||
|
theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
||||||
|
theTexture->autoGenerateMips(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return theTexture;
|
||||||
|
}
|
||||||
|
|
||||||
int clampPixelCoordinate(int coordinate, int maxCoordinate) {
|
int clampPixelCoordinate(int coordinate, int maxCoordinate) {
|
||||||
return coordinate - ((int)(coordinate < 0) * coordinate) + ((int)(coordinate > maxCoordinate) * (maxCoordinate - coordinate));
|
return coordinate - ((int)(coordinate < 0) * coordinate) + ((int)(coordinate > maxCoordinate) * (maxCoordinate - coordinate));
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ public:
|
||||||
int _environmentUsage = 0;
|
int _environmentUsage = 0;
|
||||||
|
|
||||||
static gpu::Texture* create2DTextureFromImage(const QImage& image, const std::string& srcImageName);
|
static gpu::Texture* create2DTextureFromImage(const QImage& image, const std::string& srcImageName);
|
||||||
|
static gpu::Texture* createNormalTextureFromNormalImage(const QImage& image, const std::string& srcImageName);
|
||||||
static gpu::Texture* createNormalTextureFromBumpImage(const QImage& image, const std::string& srcImageName);
|
static gpu::Texture* createNormalTextureFromBumpImage(const QImage& image, const std::string& srcImageName);
|
||||||
static gpu::Texture* createCubeTextureFromImage(const QImage& image, const std::string& srcImageName);
|
static gpu::Texture* createCubeTextureFromImage(const QImage& image, const std::string& srcImageName);
|
||||||
};
|
};
|
||||||
|
|
|
@ -189,6 +189,7 @@ void Model::RenderPipelineLib::initLocations(gpu::ShaderPointer& program, Model:
|
||||||
locations.emissiveParams = program->getUniforms().findLocation("emissiveParams");
|
locations.emissiveParams = program->getUniforms().findLocation("emissiveParams");
|
||||||
locations.glowIntensity = program->getUniforms().findLocation("glowIntensity");
|
locations.glowIntensity = program->getUniforms().findLocation("glowIntensity");
|
||||||
locations.normalFittingMapUnit = program->getTextures().findLocation("normalFittingMap");
|
locations.normalFittingMapUnit = program->getTextures().findLocation("normalFittingMap");
|
||||||
|
locations.diffuseTextureUnit = program->getTextures().findLocation("diffuseMap");
|
||||||
locations.normalTextureUnit = program->getTextures().findLocation("normalMap");
|
locations.normalTextureUnit = program->getTextures().findLocation("normalMap");
|
||||||
locations.specularTextureUnit = program->getTextures().findLocation("specularMap");
|
locations.specularTextureUnit = program->getTextures().findLocation("specularMap");
|
||||||
locations.emissiveTextureUnit = program->getTextures().findLocation("emissiveMap");
|
locations.emissiveTextureUnit = program->getTextures().findLocation("emissiveMap");
|
||||||
|
@ -1629,7 +1630,6 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, int shape
|
||||||
// Diffuse
|
// Diffuse
|
||||||
if (materialKey.isDiffuseMap()) {
|
if (materialKey.isDiffuseMap()) {
|
||||||
auto diffuseMap = textureMaps[model::MaterialKey::DIFFUSE_MAP];
|
auto diffuseMap = textureMaps[model::MaterialKey::DIFFUSE_MAP];
|
||||||
|
|
||||||
if (diffuseMap && diffuseMap->isDefined()) {
|
if (diffuseMap && diffuseMap->isDefined()) {
|
||||||
batch.setResourceTexture(DIFFUSE_MAP_SLOT, diffuseMap->getTextureView());
|
batch.setResourceTexture(DIFFUSE_MAP_SLOT, diffuseMap->getTextureView());
|
||||||
|
|
||||||
|
|
|
@ -345,6 +345,7 @@ private:
|
||||||
int tangent;
|
int tangent;
|
||||||
int alphaThreshold;
|
int alphaThreshold;
|
||||||
int texcoordMatrices;
|
int texcoordMatrices;
|
||||||
|
int diffuseTextureUnit;
|
||||||
int normalTextureUnit;
|
int normalTextureUnit;
|
||||||
int specularTextureUnit;
|
int specularTextureUnit;
|
||||||
int emissiveTextureUnit;
|
int emissiveTextureUnit;
|
||||||
|
|
Loading…
Reference in a new issue