Fix transparancy check for nodes

The previous method tried to read from meshes which had been freed from memory
This commit is contained in:
Peder Bergebakken Sundt 2019-03-22 18:01:42 +01:00
parent b4e66809cb
commit 84cbd5e5c7
3 changed files with 13 additions and 10 deletions

View File

@ -14,7 +14,7 @@ void SceneNode::setMesh(const Mesh* mesh) {
vertexArrayObjectID = cache[mesh]; vertexArrayObjectID = cache[mesh];
VAOIndexCount = mesh->indices.size(); VAOIndexCount = mesh->indices.size();
isVertexColored = ! mesh->colors.empty(); isVertexColored = ! mesh->colors.empty();
m_gemoetry = mesh; mesh_has_transparancy = mesh->has_transparancy;
} }
void SceneNode::setTexture( void SceneNode::setTexture(
const PNGImage* diffuse, const PNGImage* diffuse,
@ -28,7 +28,7 @@ void SceneNode::setTexture(
isNormalMapped = false; isNormalMapped = false;
isDisplacementMapped = false; isDisplacementMapped = false;
isReflectionMapped = false; isReflectionMapped = false;
t_diffuse = nullptr; tex_has_transparancy = false;
} }
if (diffuse) { if (diffuse) {
@ -36,7 +36,7 @@ void SceneNode::setTexture(
cache[diffuse] = generateTexture(*diffuse); cache[diffuse] = generateTexture(*diffuse);
diffuseTextureID = cache[diffuse]; diffuseTextureID = cache[diffuse];
isTextured = true; isTextured = true;
t_diffuse = diffuse; tex_has_transparancy = diffuse->has_transparancy;
} }
if (normal) { if (normal) {
@ -84,9 +84,9 @@ bool SceneNode::has_no_transforms() const {
} }
bool SceneNode::has_transparancy() const { bool SceneNode::has_transparancy() const {
return opacity < 1.0 return mesh_has_transparancy
|| t_diffuse && t_diffuse->has_transparancy || tex_has_transparancy
|| m_gemoetry && m_gemoetry->has_transparancy; || opacity < 0.98;
} }
SceneNode* SceneNode::clone() const { SceneNode* SceneNode::clone() const {

View File

@ -82,9 +82,9 @@ struct SceneNode {
float displacementCoefficient = 0.1; // in units float displacementCoefficient = 0.1; // in units
uint reflectionTextureID; uint reflectionTextureID;
// has_transparancy // has_transparancy check
const Mesh* m_gemoetry = nullptr; bool mesh_has_transparancy = false;
const PNGImage* t_diffuse = nullptr; bool tex_has_transparancy = false;
// shader flags // shader flags
bool isTextured = false; bool isTextured = false;

View File

@ -176,6 +176,7 @@ SceneNode* loadModelScene(const std::string& dirname, const std::string& filenam
}); });
} }
mesh.has_transparancy = false;
if (aimesh->GetNumColorChannels() >= 1) if (aimesh->GetNumColorChannels() >= 1)
for (uint i=0; i < aimesh->mNumVertices; i++){ for (uint i=0; i < aimesh->mNumVertices; i++){
mesh.colors.push_back({ mesh.colors.push_back({
@ -184,6 +185,8 @@ SceneNode* loadModelScene(const std::string& dirname, const std::string& filenam
aimesh->mColors[0][i].b, aimesh->mColors[0][i].b,
aimesh->mColors[0][i].a, aimesh->mColors[0][i].a,
}); });
if (aimesh->mColors[0][i].a < 255)
mesh.has_transparancy = true;
} }
for (uint i=0; i < aimesh->mNumFaces; i++){ for (uint i=0; i < aimesh->mNumFaces; i++){