Read the emissive color property and use it to effect glow.

This commit is contained in:
Andrzej Kapolka 2014-09-19 16:49:51 -07:00
parent 9515145b9b
commit 6c907a9d83
3 changed files with 24 additions and 9 deletions

View file

@ -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);

View file

@ -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<double>();
@ -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()) {

View file

@ -108,6 +108,7 @@ public:
glm::vec3 diffuseColor;
glm::vec3 specularColor;
glm::vec3 emissiveColor;
float shininess;
float opacity;