Allow specifying material opacity.

This commit is contained in:
Andrzej Kapolka 2014-09-16 17:52:39 -07:00
parent 7b3f61ddc2
commit fbd1efad81
18 changed files with 48 additions and 36 deletions

View file

@ -48,6 +48,6 @@ void main(void) {
normalizedNormal)); normalizedNormal));
// modulate texture by base color and add specular contribution // modulate texture by base color and add specular contribution
gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + gl_FragColor = vec4(base.rgb, gl_FrontMaterial.diffuse.a) * texture2D(diffuseMap, gl_TexCoord[0].st) +
vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb, 0.0); vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb, 0.0);
} }

View file

@ -66,6 +66,6 @@ void main(void) {
normalizedNormal)); normalizedNormal));
// modulate texture by base color and add specular contribution // modulate texture by base color and add specular contribution
gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + gl_FragColor = vec4(base.rgb, gl_FrontMaterial.diffuse.a) * texture2D(diffuseMap, gl_TexCoord[0].st) +
vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb, 0.0); vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb, 0.0);
} }

View file

@ -79,6 +79,6 @@ void main(void) {
normalize(vec4(vec3(interpolatedPosition), 0.0))), viewNormal)); normalize(vec4(vec3(interpolatedPosition), 0.0))), viewNormal));
// modulate texture by base color and add specular contribution // modulate texture by base color and add specular contribution
gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + gl_FragColor = vec4(base.rgb, gl_FrontMaterial.diffuse.a) * texture2D(diffuseMap, gl_TexCoord[0].st) +
vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb, 0.0); vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb, 0.0);
} }

View file

@ -82,6 +82,7 @@ void main(void) {
normalize(vec4(interpolatedPosition.xyz, 0.0))), viewNormal)); normalize(vec4(interpolatedPosition.xyz, 0.0))), viewNormal));
// modulate texture by base color and add specular contribution // modulate texture by base color and add specular contribution
gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FragColor = vec4(base.rgb, gl_FrontMaterial.diffuse.a) * texture2D(diffuseMap, gl_TexCoord[0].st) +
gl_FrontLightProduct[0].specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, 0.0); vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb *
texture2D(specularMap, gl_TexCoord[0].st).rgb, 0.0);
} }

View file

@ -69,6 +69,7 @@ void main(void) {
normalizedNormal)); normalizedNormal));
// modulate texture by base color and add specular contribution // modulate texture by base color and add specular contribution
gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FragColor = vec4(base.rgb, gl_FrontMaterial.diffuse.a) * texture2D(diffuseMap, gl_TexCoord[0].st) +
gl_FrontLightProduct[0].specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, 0.0); vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb *
texture2D(specularMap, gl_TexCoord[0].st).rgb, 0.0);
} }

View file

@ -60,6 +60,6 @@ void main(void) {
normalize(vec4(vec3(interpolatedPosition), 0.0))), viewNormal)); normalize(vec4(vec3(interpolatedPosition), 0.0))), viewNormal));
// modulate texture by base color and add specular contribution // modulate texture by base color and add specular contribution
gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + gl_FragColor = vec4(base.rgb, gl_FrontMaterial.diffuse.a) * texture2D(diffuseMap, gl_TexCoord[0].st) +
vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb, 0.0); vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb, 0.0);
} }

View file

@ -63,6 +63,7 @@ void main(void) {
normalize(vec4(interpolatedPosition.xyz, 0.0))), viewNormal)); normalize(vec4(interpolatedPosition.xyz, 0.0))), viewNormal));
// modulate texture by base color and add specular contribution // modulate texture by base color and add specular contribution
gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FragColor = vec4(base.rgb, gl_FrontMaterial.diffuse.a) * texture2D(diffuseMap, gl_TexCoord[0].st) +
gl_FrontLightProduct[0].specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, 0.0); vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb *
texture2D(specularMap, gl_TexCoord[0].st).rgb, 0.0);
} }

View file

@ -58,6 +58,6 @@ void main(void) {
normalizedNormal)); normalizedNormal));
// modulate texture by base color and add specular contribution // modulate texture by base color and add specular contribution
gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + gl_FragColor = vec4(base.rgb, gl_FrontMaterial.diffuse.a) * texture2D(diffuseMap, gl_TexCoord[0].st) +
vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb, 0.0); vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb, 0.0);
} }

View file

@ -70,6 +70,6 @@ void main(void) {
normalize(vec4(vec3(interpolatedPosition), 0.0))), viewNormal)); normalize(vec4(vec3(interpolatedPosition), 0.0))), viewNormal));
// modulate texture by base color and add specular contribution // modulate texture by base color and add specular contribution
gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + gl_FragColor = vec4(base.rgb, gl_FrontMaterial.diffuse.a) * texture2D(diffuseMap, gl_TexCoord[0].st) +
vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb, 0.0); vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb, 0.0);
} }

View file

@ -73,6 +73,7 @@ void main(void) {
normalize(vec4(interpolatedPosition.xyz, 0.0))), viewNormal)); normalize(vec4(interpolatedPosition.xyz, 0.0))), viewNormal));
// modulate texture by base color and add specular contribution // modulate texture by base color and add specular contribution
gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FragColor = vec4(base.rgb, gl_FrontMaterial.diffuse.a) * texture2D(diffuseMap, gl_TexCoord[0].st) +
gl_FrontLightProduct[0].specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, 0.0); vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb *
texture2D(specularMap, gl_TexCoord[0].st).rgb, 0.0);
} }

View file

@ -61,6 +61,7 @@ void main(void) {
normalizedNormal)); normalizedNormal));
// modulate texture by base color and add specular contribution // modulate texture by base color and add specular contribution
gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FragColor = vec4(base.rgb, gl_FrontMaterial.diffuse.a) * texture2D(diffuseMap, gl_TexCoord[0].st) +
gl_FrontLightProduct[0].specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, 0.0); vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb *
texture2D(specularMap, gl_TexCoord[0].st).rgb, 0.0);
} }

View file

@ -51,7 +51,7 @@ void main(void) {
normalizedNormal)); normalizedNormal));
// modulate texture by base color and add specular contribution // modulate texture by base color and add specular contribution
gl_FragColor = base * texture2D(diffuseMap, gl_TexCoord[0].st) + vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FragColor = vec4(base.rgb, gl_FrontMaterial.diffuse.a) * texture2D(diffuseMap, gl_TexCoord[0].st) +
gl_FrontLightProduct[0].specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, 0.0); vec4(pow(specular, gl_FrontMaterial.shininess) * gl_FrontLightProduct[0].specular.rgb *
texture2D(specularMap, gl_TexCoord[0].st).rgb, 0.0);
} }

View file

@ -684,10 +684,10 @@ bool NetworkMeshPart::isTranslucent() const {
return diffuseTexture && diffuseTexture->isTranslucent(); return diffuseTexture && diffuseTexture->isTranslucent();
} }
int NetworkMesh::getTranslucentPartCount() const { int NetworkMesh::getTranslucentPartCount(const FBXMesh& fbxMesh) const {
int count = 0; int count = 0;
foreach (const NetworkMeshPart& part, parts) { for (int i = 0; i < parts.size(); i++) {
if (part.isTranslucent()) { if (parts.at(i).isTranslucent() || fbxMesh.parts.at(i).opacity != 1.0f) {
count++; count++;
} }
} }

View file

@ -145,7 +145,7 @@ public:
QVector<NetworkMeshPart> parts; QVector<NetworkMeshPart> parts;
int getTranslucentPartCount() const; int getTranslucentPartCount(const FBXMesh& fbxMesh) const;
}; };
#endif // hifi_GeometryCache_h #endif // hifi_GeometryCache_h

View file

@ -608,13 +608,13 @@ bool Model::render(float alpha, RenderMode mode, bool receiveShadows) {
glAlphaFunc(GL_GREATER, 0.5f * alpha); glAlphaFunc(GL_GREATER, 0.5f * alpha);
receiveShadows &= Menu::getInstance()->getShadowsEnabled(); receiveShadows &= Menu::getInstance()->getShadowsEnabled();
renderMeshes(alpha, mode, false, receiveShadows); renderMeshes(mode, false, receiveShadows);
glDisable(GL_ALPHA_TEST); glDisable(GL_ALPHA_TEST);
// render translucent meshes afterwards // render translucent meshes afterwards
renderMeshes(alpha, mode, true, receiveShadows); renderMeshes(mode, true, receiveShadows);
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
@ -1356,7 +1356,7 @@ void Model::deleteGeometry() {
} }
} }
void Model::renderMeshes(float alpha, RenderMode mode, bool translucent, bool receiveShadows) { void Model::renderMeshes(RenderMode mode, bool translucent, bool receiveShadows) {
updateVisibleJointStates(); updateVisibleJointStates();
const FBXGeometry& geometry = _geometry->getFBXGeometry(); const FBXGeometry& geometry = _geometry->getFBXGeometry();
const QVector<NetworkMesh>& networkMeshes = _geometry->getMeshes(); const QVector<NetworkMesh>& networkMeshes = _geometry->getMeshes();
@ -1365,13 +1365,13 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent, bool re
for (int i = 0; i < networkMeshes.size(); i++) { for (int i = 0; i < networkMeshes.size(); i++) {
// exit early if the translucency doesn't match what we're drawing // exit early if the translucency doesn't match what we're drawing
const NetworkMesh& networkMesh = networkMeshes.at(i); const NetworkMesh& networkMesh = networkMeshes.at(i);
if (translucent ? (networkMesh.getTranslucentPartCount() == 0) : const FBXMesh& mesh = geometry.meshes.at(i);
(networkMesh.getTranslucentPartCount() == networkMesh.parts.size())) { if (translucent ? (networkMesh.getTranslucentPartCount(mesh) == 0) :
(networkMesh.getTranslucentPartCount(mesh) == networkMesh.parts.size())) {
continue; continue;
} }
const_cast<QOpenGLBuffer&>(networkMesh.indexBuffer).bind(); const_cast<QOpenGLBuffer&>(networkMesh.indexBuffer).bind();
const FBXMesh& mesh = geometry.meshes.at(i);
int vertexCount = mesh.vertices.size(); int vertexCount = mesh.vertices.size();
if (vertexCount == 0) { if (vertexCount == 0) {
// sanity check // sanity check
@ -1528,7 +1528,7 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent, bool re
if (!mesh.colors.isEmpty()) { if (!mesh.colors.isEmpty()) {
glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_COLOR_ARRAY);
} else { } else {
glColor4f(1.0f, 1.0f, 1.0f, alpha); glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
} }
if (!mesh.texCoords.isEmpty()) { if (!mesh.texCoords.isEmpty()) {
glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY);
@ -1538,7 +1538,7 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent, bool re
for (int j = 0; j < networkMesh.parts.size(); j++) { for (int j = 0; j < networkMesh.parts.size(); j++) {
const NetworkMeshPart& networkPart = networkMesh.parts.at(j); const NetworkMeshPart& networkPart = networkMesh.parts.at(j);
const FBXMeshPart& part = mesh.parts.at(j); const FBXMeshPart& part = mesh.parts.at(j);
if (networkPart.isTranslucent() != translucent) { if ((networkPart.isTranslucent() || part.opacity != 1.0f) != translucent) {
offset += (part.quadIndices.size() + part.triangleIndices.size()) * sizeof(int); offset += (part.quadIndices.size() + part.triangleIndices.size()) * sizeof(int);
continue; continue;
} }
@ -1547,8 +1547,8 @@ void Model::renderMeshes(float alpha, RenderMode mode, bool translucent, bool re
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
} else { } else {
glm::vec4 diffuse = glm::vec4(part.diffuseColor, alpha); glm::vec4 diffuse = glm::vec4(part.diffuseColor, part.opacity);
glm::vec4 specular = glm::vec4(part.specularColor, alpha); glm::vec4 specular = glm::vec4(part.specularColor, part.opacity);
glMaterialfv(GL_FRONT, GL_AMBIENT, (const float*)&diffuse); glMaterialfv(GL_FRONT, GL_AMBIENT, (const float*)&diffuse);
glMaterialfv(GL_FRONT, GL_DIFFUSE, (const float*)&diffuse); glMaterialfv(GL_FRONT, GL_DIFFUSE, (const float*)&diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, (const float*)&specular); glMaterialfv(GL_FRONT, GL_SPECULAR, (const float*)&specular);

View file

@ -256,7 +256,7 @@ private:
void applyNextGeometry(); void applyNextGeometry();
void deleteGeometry(); void deleteGeometry();
void renderMeshes(float alpha, RenderMode mode, bool translucent, bool receiveShadows); void renderMeshes(RenderMode mode, bool translucent, bool receiveShadows);
QVector<JointState> createJointStates(const FBXGeometry& geometry); QVector<JointState> createJointStates(const FBXGeometry& geometry);
void initJointTransforms(); void initJointTransforms();

View file

@ -657,6 +657,7 @@ public:
glm::vec3 diffuse; glm::vec3 diffuse;
glm::vec3 specular; glm::vec3 specular;
float shininess; float shininess;
float opacity;
}; };
class Cluster { class Cluster {
@ -1280,7 +1281,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
textureContent.insert(filename, content); textureContent.insert(filename, content);
} }
} else if (object.name == "Material") { } 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 }; Material material = { glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0f, 1.0f, 1.0f), 96.0f, 1.0f };
foreach (const FBXNode& subobject, object.children) { foreach (const FBXNode& subobject, object.children) {
bool properties = false; bool properties = false;
QByteArray propertyName; QByteArray propertyName;
@ -1306,6 +1307,9 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
} else if (property.properties.at(0) == "Shininess") { } else if (property.properties.at(0) == "Shininess") {
material.shininess = property.properties.at(index).value<double>(); material.shininess = property.properties.at(index).value<double>();
} else if (property.properties.at(0) == "Opacity") {
material.opacity = 0.5f; // property.properties.at(index).value<double>();
} }
} }
} }
@ -1602,6 +1606,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
part.diffuseColor = material.diffuse; part.diffuseColor = material.diffuse;
part.specularColor = material.specular; part.specularColor = material.specular;
part.shininess = material.shininess; part.shininess = material.shininess;
part.opacity = material.opacity;
if (!diffuseTexture.filename.isNull()) { if (!diffuseTexture.filename.isNull()) {
part.diffuseTexture = diffuseTexture; part.diffuseTexture = diffuseTexture;
} }
@ -2042,6 +2047,7 @@ FBXGeometry readSVO(const QByteArray& model) {
FBXMeshPart part; FBXMeshPart part;
part.diffuseColor = glm::vec3(1.0f, 1.0f, 1.0f); part.diffuseColor = glm::vec3(1.0f, 1.0f, 1.0f);
part.shininess = 96.0f; part.shininess = 96.0f;
part.opacity = 1.0f;
mesh.parts.append(part); mesh.parts.append(part);
VoxelTree tree; VoxelTree tree;

View file

@ -109,6 +109,7 @@ public:
glm::vec3 diffuseColor; glm::vec3 diffuseColor;
glm::vec3 specularColor; glm::vec3 specularColor;
float shininess; float shininess;
float opacity;
FBXTexture diffuseTexture; FBXTexture diffuseTexture;
FBXTexture normalTexture; FBXTexture normalTexture;