support transparency now

This commit is contained in:
Anakin 2017-01-15 15:51:12 +01:00
parent b8f8a5c2ad
commit 454ed45fa1
5 changed files with 103 additions and 23 deletions

View File

@ -6,6 +6,8 @@ precision mediump float;
uniform sampler2D texture;
uniform bool b_transparent;
varying vec2 v_texcoord;
void main()
@ -13,5 +15,10 @@ void main()
// Set fragment color from texture
vec4 finalColor = vec4(texture2D(texture, v_texcoord));
if(!b_transparent)
{
finalColor.a = 1.0f;
}
gl_FragColor = finalColor;
}

View File

@ -71,7 +71,6 @@ void GeometryEngine::loadFile(QString filePath)
m_boundings = file.getBoundingBox();
// collect data
//TODO: sort transparent faces
unsigned int indexOffset(0);
unsigned int vertexOffset(0);
for (auto& modelIterator : *models)
@ -94,7 +93,11 @@ void GeometryEngine::loadFile(QString filePath)
// save data
vertexData += segmentIterator->vertices;
indexData += segmentIterator->indices;
if (segmentIterator->textureIndex < m_materials->size() && m_materials->at(segmentIterator->textureIndex).transparent)
m_drawList.push_back(new_info);
else
m_drawList.push_front(new_info);
// update offset
indexOffset += new_info.size;
@ -172,15 +175,25 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
for (auto& it : m_drawList)
{
bool tmp_transparent(false);
// bind the correct texture
if (it.textureIndex < m_materials->size())
{
m_materials->at(it.textureIndex).texture->bind();
tmp_transparent = m_materials->at(it.textureIndex).transparent;
}
else
{
m_materials->last().texture->bind();
tmp_transparent = m_materials->last().transparent;
}
// Set model matrix
program->setUniformValue("m_matrix", it.modelMatrix);
// decide if this is transparent
program->setUniformValue("b_transparent", tmp_transparent);
// Draw cube geometry using indices from VBO 1
glDrawElements(GL_TRIANGLES, it.size, GL_UNSIGNED_INT, (void*)(it.offset * sizeof(GLuint)));
}

View File

@ -160,6 +160,7 @@ void MshFile::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
std::list<ChunkHeader*> tmp_matdChunks;
loadChunks(tmp_matdChunks, it->position, it->size);
//TODO: materialy without texture have null pointer need to fix that
m_materials->push_back(Material());
// analyse MATD subchunks
@ -216,7 +217,67 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
{
for (auto& it : chunkList)
{
if (!strcmp("TX0D", it->name))
//TODO: get information from flags
// attributes
if (!strcmp("ATRB", it->name))
{
// read the attributes
m_file.seekg(it->position);
std::uint8_t flag, render, data[2];
m_file.read(F2V(flag), sizeof(flag));
m_file.read(F2V(render), sizeof(render));
m_file.read(F2V(data[0]), sizeof(data[0]));
m_file.read(F2V(data[1]), sizeof(data[1]));
// specular
if (flag >> 7)
{
std::cout << "specular" << std::endl;
}
// additive transparency
if ((flag << 1) >> 7)
{
std::cout << "additive transparency" << std::endl;
m_materials->back().transparent = true;
}
// per-pixel lighting
if ((flag << 2) >> 7)
{
std::cout << "per-pixel lighting" << std::endl;
}
// hard-edged transparency
if ((flag << 3) >> 7)
{
std::cout << "hard-edged transparency" << std::endl;
m_materials->back().transparent = true;
}
// double-sided transparency
if ((flag << 4) >> 7)
{
std::cout << "double-sided transparency" << std::endl;
m_materials->back().transparent = true;
}
// single-sided transparency
if ((flag << 5) >> 7)
{
std::cout << "single-sided transparency" << std::endl;
m_materials->back().transparent = true;
}
// glow
if ((flag << 6) >> 7)
{
std::cout << "glow" << std::endl;
}
// emissive
if ((flag << 7) >> 7)
{
std::cout << "emissive" << std::endl;
}
}
// texture name
else if (!strcmp("TX0D", it->name))
{
// get the texture name
m_file.seekg(it->position);
@ -536,7 +597,6 @@ void MshFile::analyseClthChunks(Model * dataDestination, std::list<ChunkHeader*>
m_materials->push_back(Material());
m_materials->back().name = QString(buffer);
//TODO: load texture;
loadTexture(m_materials->back().texture, m_filepath + "/" + m_materials->back().name);
new_segment->textureIndex = m_materials->size() - 1;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.