added wireframe mesh type

This commit is contained in:
Anselme 2016-12-12 23:04:32 +01:00
parent 8f23c181fe
commit 1a547ed824
6 changed files with 75 additions and 27 deletions

View File

@ -38,50 +38,63 @@ uniform sampler2D normalMap;
in vec3 varTangent;
in vec3 varBinormal;
#endif
#ifdef WIREFRAME
in vec3 varColor;
#else
in vec3 varNormal;
in vec2 varTexCoord;
#endif
void main()
{
#ifdef WIREFRAME
outColor.rgb = varColor;
outNormal = vec3(0., 0., 1.);
outSpecular = vec4(0., 0., 0., 1.);
#else
#ifdef ALPHA_MASK
if(texture(alphaMask, varTexCoord).r < 0.5)
discard;
if(texture(alphaMask, varTexCoord).r < 0.5)
discard;
#endif
#ifdef NORMAL_MAP
vec3 normalTexel = normalize(texture(normalMap, varTexCoord).xyz -0.5);
vec3 tangent = normalize(varTangent);
vec3 binormal = normalize(varBinormal);
vec3 normal = normalize(varNormal);
mat3 tangentSpace = mat3(vec3(tangent.x, binormal.x, normal.x),
vec3(tangent.y, binormal.y, normal.y),
vec3(tangent.z, binormal.z, normal.z));
outNormal = normalize(normalTexel * tangentSpace);
vec3 normalTexel = normalize(texture(normalMap, varTexCoord).xyz -0.5);
vec3 tangent = normalize(varTangent);
vec3 binormal = normalize(varBinormal);
vec3 normal = normalize(varNormal);
mat3 tangentSpace = mat3(vec3(tangent.x, binormal.x, normal.x),
vec3(tangent.y, binormal.y, normal.y),
vec3(tangent.z, binormal.z, normal.z));
outNormal = normalize(normalTexel * tangentSpace);
#else
outNormal = normalize(varNormal);
outNormal = normalize(varNormal);
#endif
#ifdef DIFFUSE_TEXTURE
outColor.rgb = texture(diffuseTexture, varTexCoord).rgb;
outColor.rgb = texture(diffuseTexture, varTexCoord).rgb;
#else
outColor.rgb = materialKd;
outColor.rgb = materialKd;
#endif
#ifdef SPECULAR_TEXTURE
outSpecular.rgb = texture(specularTexture, varTexCoord).rgb;
#else
outSpecular.rgb = materialKs;
#endif
outSpecular.w = float(materialNs)/255;
#endif // WIREFRAME
#ifdef INSTANCED
outColor.a = float(object_identifier+instanceId)/255;
#else
outColor.a = float(object_identifier)/255;
#endif
#ifdef SPECULAR_TEXTURE
outSpecular.rgb = texture(specularTexture, varTexCoord).rgb;
#else
outSpecular.rgb = materialKs;
#endif
outSpecular.w = float(materialNs)/255;
outPosition = posInView;
outPosition = posInView;
}

View File

@ -7,9 +7,14 @@ out vec4 posInView;
out vec3 varTangent;
out vec3 varBinormal;
#endif
#ifdef WIREFRAME
out vec3 varColor;
#else
out vec3 varNormal;
out vec2 varTexCoord;
#endif
layout(location = 0)in vec3 inPosition;
layout(location = 2)in vec2 inTexCoord;
@ -31,10 +36,15 @@ void main(void) {
varTangent = normalize(normalMatrix*inTangent);
varBinormal = normalize(normalMatrix*inBinormal);
#endif
#ifdef WIREFRAME
varColor = inNormal;
#else
varNormal = normalize(normalMatrix*inNormal);
//computing UVs
varTexCoord = inTexCoord.xy;
#endif
// computing positions
#ifdef INSTANCED
@ -44,6 +54,6 @@ void main(void) {
vec4 pos = vec4(inPosition, 1.0);
#endif
posInView = modelViewMatrix*pos;
posInView = modelViewMatrix * pos;
gl_Position = projectionMatrix * posInView;
}

View File

@ -249,10 +249,13 @@ void DeferredPipeline::setSources(ShaderSource *gBufferSource, ShaderSource *lig
void DeferredPipeline::refreshScene(Scene *scene)
{
// delete previous shaders
for(auto it : m_mesh3DShaders)
delete it.second;
m_mesh3DShaders.clear();
m_meshTypes.clear();
// gather all unique mesh flags
scene->getMeshTypes(m_meshTypes);
for(unsigned int type : m_meshTypes)
{

View File

@ -18,6 +18,7 @@ const char* const Mesh::flagStr[Mesh::NB_FLAGS] =
"TANGENT_SPACE",
"DOUBLE_SIDED",
"BILLBOARD",
"WIREFRAME",
"SHADOWED",
"COLOR_TEXTURE",
@ -37,6 +38,7 @@ Mesh::Mesh(const std::string &name) :
material(NULL),
isDoubleSided(false),
isBillboard(false),
isWireframe(false),
isShadowCaster(true),
depth(0),
m_flags(0),
@ -87,6 +89,8 @@ unsigned int Mesh::updateFlags()
m_flags |= 1 << MESH_DOUBLE_SIDED;
if(isBillboard)
m_flags |= 1 << MESH_BILLBOARD;
if(isWireframe)
m_flags |= 1 << MESH_WIREFRAME;
if(isShadowCaster)
m_flags |= 1 << MESH_SHADOWED;
}
@ -274,6 +278,15 @@ void Mesh::setIsBillboard(bool val)
m_flags &= ~(1 << MESH_BILLBOARD);
}
void Mesh::setWireframe(bool val)
{
isWireframe = val;
if(val)
m_flags |= 1 << MESH_WIREFRAME;
else
m_flags &= ~(1 << MESH_WIREFRAME);
}
void Mesh::setIsShadowCaster(bool val)
{
isShadowCaster = val;

View File

@ -34,6 +34,7 @@ public:
MESH_TANGENT_SPACE,
MESH_DOUBLE_SIDED,
MESH_BILLBOARD,
MESH_WIREFRAME,
MESH_SHADOWED,
// simple material (no lighting)
@ -169,6 +170,13 @@ public:
* a billboard mesh will always follow the camera orientation
*/
void setIsBillboard(bool val);
/**
* @brief setIsWireframe must be called for a mesh of GL_LINE primitives,
* lighting will probably not be computed on lines,
* normals value can be interpreted as a color, depending on the shader.
*/
void setWireframe(bool val);
/**
* @brief setIsShadowCaster allows to enable or disable,
@ -249,6 +257,7 @@ protected:
Material* material;
bool isDoubleSided;
bool isBillboard;
bool isWireframe;
bool isShadowCaster;
float depth;
unsigned int m_flags;

View File

@ -8,12 +8,12 @@ class MeshGenerator
{
public:
virtual glm::vec3 evalUV(float u, float v) = 0;
/**
* @brief generateParametricMesh creates a mesh from a rectangular grid of size width:height
*/
Mesh* generateParametricMesh(Material* mat, int width = 10, int height = 10, float size = 1, bool alternate = true);
/**
* @brief generateGeodesicMesh creates a closed mesh from an icosahedron subdivided n times
*/
@ -41,7 +41,7 @@ private:
int getEdge(int a, int b);
void createVertex(float u, float v);
void subdivide();
// parametric methods
int getVertexId(int i, int j, int height);
};