Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
C-Fu
OpenGL
Commits
454ed45f
Commit
454ed45f
authored
Jan 15, 2017
by
Anakin
Browse files
support transparency now
parent
b8f8a5c2
Changes
5
Hide whitespace changes
Inline
Side-by-side
QtMeshViewer/Resources/fshader.glsl
View file @
454ed45f
...
...
@@ -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
.
0
f
;
}
gl_FragColor
=
finalColor
;
}
QtMeshViewer/Source/GeometryEngine.cpp
View file @
454ed45f
...
...
@@ -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
;
m_drawList
.
push_back
(
new_info
);
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
)));
}
...
...
QtMeshViewer/Source/MshFile.cpp
View file @
454ed45f
...
...
@@ -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
);
...
...
@@ -397,27 +458,27 @@ void MshFile::analyseSegmChunks(Model * dataDestination, std::list<ChunkHeader*>
// normals
else
if
(
!
strcmp
(
"NRML"
,
it
->
name
))
{
std
::
uint32_t
tmp_size
;
m_file
.
seekg
(
it
->
position
);
m_file
.
read
(
F2V
(
tmp_size
),
sizeof
(
tmp_size
));
std
::
uint32_t
tmp_size
;
m_file
.
seekg
(
it
->
position
);
m_file
.
read
(
F2V
(
tmp_size
),
sizeof
(
tmp_size
));
if
(
tmp_size
<
new_segment
->
vertices
.
size
())
{
emit
sendMessage
(
"WARNING: too less normals "
+
QString
::
number
(
tmp_size
)
+
" < "
+
QString
::
number
(
new_segment
->
vertices
.
size
()),
1
);
if
(
tmp_size
<
new_segment
->
vertices
.
size
())
{
emit
sendMessage
(
"WARNING: too less normals "
+
QString
::
number
(
tmp_size
)
+
" < "
+
QString
::
number
(
new_segment
->
vertices
.
size
()),
1
);
for
(
unsigned
int
i
=
new_segment
->
vertices
.
size
();
i
!=
tmp_size
;
i
--
)
for
(
unsigned
int
j
=
0
;
j
<
3
;
j
++
)
new_segment
->
vertices
[
i
-
1
].
normal
[
j
]
=
0
;
}
else
if
(
tmp_size
>
new_segment
->
vertices
.
size
())
{
emit
sendMessage
(
"WARNING: too many normals "
+
QString
::
number
(
tmp_size
)
+
" > "
+
QString
::
number
(
new_segment
->
vertices
.
size
()),
1
);
tmp_size
=
new_segment
->
vertices
.
size
();
}
for
(
unsigned
int
i
=
new_segment
->
vertices
.
size
();
i
!=
tmp_size
;
i
--
)
for
(
unsigned
int
j
=
0
;
j
<
3
;
j
++
)
new_segment
->
vertices
[
i
-
1
].
normal
[
j
]
=
0
;
}
else
if
(
tmp_size
>
new_segment
->
vertices
.
size
())
{
emit
sendMessage
(
"WARNING: too many normals "
+
QString
::
number
(
tmp_size
)
+
" > "
+
QString
::
number
(
new_segment
->
vertices
.
size
()),
1
);
tmp_size
=
new_segment
->
vertices
.
size
();
}
for
(
unsigned
int
i
=
0
;
i
<
tmp_size
;
i
++
)
for
(
unsigned
int
j
=
0
;
j
<
3
;
j
++
)
m_file
.
read
(
F2V
(
new_segment
->
vertices
[
i
].
normal
[
j
]),
sizeof
(
float
));
for
(
unsigned
int
i
=
0
;
i
<
tmp_size
;
i
++
)
for
(
unsigned
int
j
=
0
;
j
<
3
;
j
++
)
m_file
.
read
(
F2V
(
new_segment
->
vertices
[
i
].
normal
[
j
]),
sizeof
(
float
));
}
...
...
@@ -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
;
}
...
...
Release/Msh/1.tga
View file @
454ed45f
No preview for this file type
Release/Msh/quadPoly.msh
View file @
454ed45f
No preview for this file type
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment