From 6c907a9d835a9fb0fd558549a67082c374a084c0 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 19 Sep 2014 16:49:51 -0700 Subject: [PATCH] Read the emissive color property and use it to effect glow. --- interface/src/renderer/Model.cpp | 25 +++++++++++++++++-------- libraries/fbx/src/FBXReader.cpp | 7 ++++++- libraries/fbx/src/FBXReader.h | 1 + 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 1e77662ecd..2031035726 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -421,7 +421,10 @@ bool Model::render(float alpha, RenderMode mode) { glDisable(GL_BLEND); glEnable(GL_ALPHA_TEST); - glAlphaFunc(GL_EQUAL, Application::getInstance()->getGlowEffect()->getIntensity()); + + if (mode == SHADOW_RENDER_MODE) { + glAlphaFunc(GL_EQUAL, 0.0f); + } Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers( mode == DEFAULT_RENDER_MODE || mode == DIFFUSE_RENDER_MODE, @@ -431,10 +434,8 @@ bool Model::render(float alpha, RenderMode mode) { renderMeshes(mode, false); // render translucent meshes afterwards - if (mode == DEFAULT_RENDER_MODE) { - Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(false, true, true); - renderMeshes(mode, true, 0.75f); - } + Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(false, true, true); + renderMeshes(mode, true, 0.75f); glDisable(GL_ALPHA_TEST); glEnable(GL_BLEND); @@ -443,7 +444,9 @@ bool Model::render(float alpha, RenderMode mode) { Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true); - renderMeshes(mode, true, 0.0f); + if (mode == DEFAULT_RENDER_MODE || mode == DIFFUSE_RENDER_MODE) { + renderMeshes(mode, true, 0.0f); + } glDepthMask(true); glDepthFunc(GL_LESS); @@ -1322,8 +1325,14 @@ void Model::renderMeshes(RenderMode mode, bool translucent, float alphaThreshold glBindTexture(GL_TEXTURE_2D, 0); } else { - glm::vec4 diffuse = glm::vec4(part.diffuseColor, (translucent && alphaThreshold == 0.0f) ? - part.opacity : Application::getInstance()->getGlowEffect()->getIntensity()); + glm::vec4 diffuse = glm::vec4(part.diffuseColor, part.opacity); + if (!(translucent && alphaThreshold == 0.0f)) { + float emissive = (part.emissiveColor.r + part.emissiveColor.g + part.emissiveColor.b) / 3.0f; + diffuse.a = qMax(Application::getInstance()->getGlowEffect()->getIntensity(), emissive); + glAlphaFunc(GL_EQUAL, diffuse.a); + diffuse = glm::vec4(qMax(diffuse.r, part.emissiveColor.r), qMax(diffuse.g, part.emissiveColor.g), + qMax(diffuse.b, part.emissiveColor.b), diffuse.a); + } glm::vec4 specular = glm::vec4(part.specularColor, 1.0f); glMaterialfv(GL_FRONT, GL_AMBIENT, (const float*)&diffuse); glMaterialfv(GL_FRONT, GL_DIFFUSE, (const float*)&diffuse); diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 3b9a340ed2..47120bda7a 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -656,6 +656,7 @@ class Material { public: glm::vec3 diffuse; glm::vec3 specular; + glm::vec3 emissive; float shininess; float opacity; }; @@ -1281,7 +1282,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) textureContent.insert(filename, content); } } else if (object.name == "Material") { - Material material = { glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0f, 1.0f, 1.0f), 96.0f, 1.0f }; + Material material = { glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(), 96.0f, 1.0f }; foreach (const FBXNode& subobject, object.children) { bool properties = false; QByteArray propertyName; @@ -1305,6 +1306,9 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) } else if (property.properties.at(0) == "SpecularColor") { material.specular = getVec3(property.properties, index); + } else if (property.properties.at(0) == "Emissive") { + material.emissive = getVec3(property.properties, index); + } else if (property.properties.at(0) == "Shininess") { material.shininess = property.properties.at(index).value(); @@ -1605,6 +1609,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) FBXMeshPart& part = extracted.mesh.parts[j]; part.diffuseColor = material.diffuse; part.specularColor = material.specular; + part.emissiveColor = material.emissive; part.shininess = material.shininess; part.opacity = material.opacity; if (!diffuseTexture.filename.isNull()) { diff --git a/libraries/fbx/src/FBXReader.h b/libraries/fbx/src/FBXReader.h index 363cf491d8..423c810418 100644 --- a/libraries/fbx/src/FBXReader.h +++ b/libraries/fbx/src/FBXReader.h @@ -108,6 +108,7 @@ public: glm::vec3 diffuseColor; glm::vec3 specularColor; + glm::vec3 emissiveColor; float shininess; float opacity;