Commit 80265842 authored by Sylvain Thery's avatar Sylvain Thery

Merge branch 'develop' into 'develop'

Develop

See merge request !55
parents 3ae34e1a 4f4e657d
......@@ -19,7 +19,11 @@ IF (WIN32)
ENDIF()
ELSE()
link_directories( ${CGoGN_ROOT_DIR}/lib/${CMAKE_BUILD_TYPE} )
SET(EXECUTABLE_OUTPUT_PATH ${CGoGN_ROOT_DIR}/bin/${CMAKE_BUILD_TYPE} )
IF(APPLE)
SET(EXECUTABLE_OUTPUT_PATH ${CGoGN_ROOT_DIR}/bin/${CMAKE_BUILD_TYPE}/Contents/MacOS/ )
ELSE()
SET(EXECUTABLE_OUTPUT_PATH ${CGoGN_ROOT_DIR}/bin/${CMAKE_BUILD_TYPE} )
ENDIF()
ENDIF()
#include_directories(
......
......@@ -45,7 +45,7 @@ Viewer::Viewer() :
faceShrinkage = 1.0f ;
colClear = Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f) ;
colDif = Geom::Vec4f(0.8f, 0.9f, 0.7f, 1.0f) ;
colDif = Geom::Vec4f(0.3f, 0.5f, 0.2f, 1.0f) ;
colSpec = Geom::Vec4f(0.9f, 0.9f, 0.9f, 1.0f) ;
colNormal = Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f) ;
shininess = 80.0f ;
......@@ -92,31 +92,33 @@ void Viewer::cb_initGL()
m_positionVBO = new Utils::VBO() ;
m_normalVBO = new Utils::VBO() ;
m_phongShader = new Utils::ShaderPhong() ;
m_phongShader = new Utils::ShaderPhong(true,false,false) ;
m_phongShader->setAttributePosition(m_positionVBO) ;
m_phongShader->setAttributeNormal(m_normalVBO) ;
m_phongShader->setAmbiant(colClear) ;
m_phongShader->setDiffuse(colDif) ;
m_phongShader->setSpecular(colSpec) ;
m_phongShader->setShininess(shininess) ;
m_phongShader->setBackColor(Geom::Vec4f(0,0,0.2,0)) ;
m_flatShader = new Utils::ShaderSimpleFlat() ;
m_flatShader = new Utils::ShaderSimpleFlat(true,false) ;
m_flatShader->setAttributePosition(m_positionVBO) ;
m_flatShader->setAmbiant(colClear) ;
m_flatShader->setDiffuse(colDif) ;
// m_flatShader->setDiffuseBack(Geom::Vec4f(0,0,0,0)) ;
// m_flatShader->setExplode(faceShrinkage) ;
m_flatShader->setBackColor(Geom::Vec4f(0,0,0.2,0)) ;
m_vectorShader = new Utils::ShaderVectorPerVertex() ;
m_vectorShader->setAttributePosition(m_positionVBO) ;
m_vectorShader->setAttributeVector(m_normalVBO) ;
m_vectorShader->setColor(colNormal) ;
m_simpleColorShader = new Utils::ShaderSimpleColor() ;
m_simpleColorShader = new Utils::ShaderSimpleColor(true) ;
m_simpleColorShader->setAttributePosition(m_positionVBO) ;
Geom::Vec4f c(0.0f, 0.0f, 0.0f, 1.0f) ;
m_simpleColorShader->setColor(c) ;
m_pointSprite = new Utils::PointSprite() ;
m_pointSprite->setAttributePosition(m_positionVBO) ;
m_pointSprite->setColor(Geom::Vec4f(0.0f, 0.0f, 1.0f, 1.0f)) ;
......@@ -132,25 +134,31 @@ void Viewer::cb_redraw()
{
if(m_drawVertices)
{
glDepthFunc(GL_LEQUAL);
m_pointSprite->setSize(vertexScaleFactor) ;
m_render->draw(m_pointSprite, Algo::Render::GL2::POINTS) ;
}
if(m_drawEdges)
{
glDepthFunc(GL_LEQUAL);
m_simpleColorShader->setColor(Geom::Vec4f(1.,1.,0.,0.));
glLineWidth(1.0f) ;
m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES) ;
}
if(m_drawTopo)
{
glDepthFunc(GL_LEQUAL);
m_topoRender->drawTopo() ;
}
if(m_drawFaces)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
glEnable(GL_LIGHTING) ;
glEnable(GL_POLYGON_OFFSET_FILL) ;
glPolygonOffset(1.0f, 1.0f) ;
glDepthFunc(GL_LESS);
if (m_drawEdges||m_drawTopo)
{
glEnable(GL_POLYGON_OFFSET_FILL) ;
glPolygonOffset(1.0f, 1.0f) ;
}
switch(m_renderStyle)
{
case FLAT :
......@@ -163,11 +171,7 @@ void Viewer::cb_redraw()
glDisable(GL_POLYGON_OFFSET_FILL) ;
}
if(m_drawTopo)
{
glDepthFunc(GL_LEQUAL);
m_topoRender->drawTopo() ;
}
if(m_drawNormals)
{
......@@ -210,6 +214,32 @@ void Viewer::cb_keyPress(int keycode)
{
switch(keycode)
{
case 'n':
m_flatShader->setNoClippingPlane();
m_phongShader->setNoClippingPlane();
m_topoRender->setNoClippingPlane();
m_simpleColorShader->setNoClippingPlane();
m_pointSprite->setNoClippingPlane();
m_vectorShader->setNoClippingPlane();
break;
case 'N':
{
const Geom::Vec3f& Pc = bb.center();
const Geom::Vec3f& Nc = bb.diag();
Geom::Vec4f planeClip(Nc[0],Nc[1],Nc[2],-(Pc*Nc));
m_flatShader->setClippingPlane(planeClip);
m_phongShader->setClippingPlane(planeClip);
m_topoRender->setClippingPlane(planeClip);
m_simpleColorShader->setClippingPlane(planeClip);
m_pointSprite->setClippingPlane(planeClip);
m_vectorShader->setClippingPlane(planeClip);
}
break;
case 'c' :
myMap.check();
break;
......@@ -578,6 +608,18 @@ void Viewer::importMesh(std::string& filename)
m_normalVBO->updateData(normal) ;
setParamObject(bb.maxSize(), bb.center().data()) ;
const Geom::Vec3f& Pc = bb.center();
const Geom::Vec3f& Nc = bb.diag();
Geom::Vec4f planeClip(Nc[0],Nc[1],Nc[2],-(Pc*Nc));
// m_flatShader->setClippingPlane(planeClip);
// m_phongShader->setClippingPlane(planeClip);
// m_topoRender->setClippingPlane(planeClip);
// m_simpleColorShader->setClippingPlane(planeClip);
// m_pointSprite->setClippingPlane(planeClip);
// m_vectorShader->setClippingPlane(planeClip);
updateGLMatrices() ;
std::cout << "#vertices -> " << Algo::Topo::getNbOrbits<VERTEX>(myMap) << std::endl;
......
......@@ -107,11 +107,9 @@ link_directories( ${CGoGN_ROOT_DIR}/lib/${CMAKE_BUILD_TYPE} )
IF (CGoGN_ONELIB)
IF(CGoGN_WITH_QT)
add_definitions(-DCGoGN_QT_DLL_EXPORT)
add_library( cgogn ${files_topology} ${files_container} ${files_algo} ${files_utils_withQt})
qt_use_modules(cgogn Gui OpenGL Xml Svg)
IF(${CGoGN_DESIRED_QT_VERSION} STREQUAL "5")
qt_use_modules(cgogn Widgets)
ENDIF()
ELSE()
add_library( cgogn ${files_topology} ${files_container} ${files_algo} ${files_utils} )
ENDIF()
......
......@@ -9,6 +9,8 @@ uniform vec4 materialDiffuse;
uniform vec4 materialSpecular;
uniform vec4 materialAmbient;
uniform float shininess;
uniform vec4 backColor;
FRAG_OUT_DEF;
void main()
{
......@@ -51,6 +53,10 @@ void main()
float specular = pow( max(dot(R, E), 0.0), shininess );
finalColor += materialSpecular * specular;
}
else
{
finalColor = backColor;
}
#endif
FRAG_OUT=finalColor;
}
......@@ -48,8 +48,10 @@ protected:
bool m_with_eyepos;
// shader sources OGL3
static std::string vertexShaderText;
static std::string fragmentShaderText;
static std::string vertexShaderText;
static std::string fragmentShaderText;
static std::string vertexShaderClipText;
static std::string fragmentShaderClipText;
// uniform locations
CGoGNGLuint m_unif_ambiant;
......@@ -58,6 +60,7 @@ protected:
CGoGNGLuint m_unif_shininess;
CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_eyePos;
CGoGNGLuint m_unif_backColor;
//values
Geom::Vec4f m_ambiant;
......@@ -66,11 +69,16 @@ protected:
float m_shininess;
Geom::Vec3f m_lightPos;
Geom::Vec3f m_eyePos;
Geom::Vec4f m_backColor;
VBO* m_vboPos;
VBO* m_vboNormal;
VBO* m_vboColor;
/// clipping
CGoGNGLuint m_unif_planeClip;
Geom::Vec4f m_planeClip;
void getLocations();
void sendParams();
......@@ -78,7 +86,7 @@ protected:
void restoreUniformsAttribs();
public:
ShaderPhong(bool doubleSided = false, bool withEyePosition=false);
ShaderPhong(bool withClipping = false ,bool doubleSided = false, bool withEyePosition=false);
// inviduals parameter setting functions
void setAmbiant(const Geom::Vec4f& ambiant);
......@@ -90,6 +98,8 @@ public:
void setShininess(float shininess);
void setLightPosition(const Geom::Vec3f& lp);
void setBackColor(const Geom::Vec4f& back);
/// set eye position for VR environement
void setEyePosition(const Geom::Vec3f& ep);
......@@ -117,6 +127,10 @@ public:
// optional attributes
unsigned int setAttributeColor(VBO* vbo);
void unsetAttributeColor();
void setClippingPlane(const Geom::Vec4f& plane);
inline void setNoClippingPlane() { setClippingPlane(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f)); }
};
} // namespace Utils
......
//ShaderPhong::fragmentShaderClipText
PRECISION;
VARYING_FRAG vec3 EyeVector, Normal, LightDir;
#ifdef WITH_COLOR
VARYING_FRAG vec3 Color;
#endif
uniform vec4 materialDiffuse;
uniform vec4 materialSpecular;
uniform vec4 materialAmbient;
uniform float shininess;
uniform vec4 backColor;
uniform vec4 planeClip;
VARYING_FRAG vec3 posClip;
FRAG_OUT_DEF;
void main()
{
if (dot(planeClip,vec4(posClip,1.0))>0.0)
discard;
vec3 N = normalize (Normal);
vec3 L = normalize (LightDir);
//float lambertTerm = clamp(dot(N,L),0.0,1.0);
vec4 finalColor = materialAmbient;
#ifdef DOUBLE_SIDED
float lambertTerm;
vec4 diffuseColor = materialDiffuse;
if (!gl_FrontFacing)
{
N *= -1.0;
lambertTerm = clamp(dot(N,L),0.0,1.0);
}
else
lambertTerm = clamp(dot(N,L),0.0,1.0);
#ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm;
#else
finalColor += vec4((Color*lambertTerm),0.0) ;
#endif
vec3 E = normalize(EyeVector);
vec3 R = reflect(-L, N);
float specular = pow( max(dot(R, E), 0.0), shininess );
finalColor += materialSpecular * specular;
#else
float lambertTerm = clamp(dot(N,L),0.0,1.0);
if (gl_FrontFacing)
{
#ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm;
#else
finalColor += vec4((Color*lambertTerm),0.0) ;
#endif
vec3 E = normalize(EyeVector);
vec3 R = reflect(-L, N);
float specular = pow( max(dot(R, E), 0.0), shininess );
finalColor += materialSpecular * specular;
}
else
{
finalColor = backColor;
}
#endif
FRAG_OUT=finalColor;
}
//ShaderPhong::vertexShaderClipText
ATTRIBUTE vec3 VertexPosition, VertexNormal;
#ifdef WITH_COLOR
ATTRIBUTE vec3 VertexColor;
#endif
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 ModelViewMatrix;
uniform mat4 NormalMatrix;
uniform vec3 lightPosition;
VARYING_VERT vec3 EyeVector, Normal, LightDir;
#ifdef WITH_COLOR
VARYING_VERT vec3 Color;
#endif
#ifdef WITH_EYEPOSITION
uniform vec3 eyePosition;
#endif
VARYING_VERT vec3 posClip;
INVARIANT_POS;
void main ()
{
Normal = vec3 (NormalMatrix * vec4 (VertexNormal, 0.0));
vec3 Position = vec3 (ModelViewMatrix * vec4 (VertexPosition, 1.0));
LightDir = lightPosition - Position;
#ifdef WITH_EYEPOSITION
EyeVector = eyePosition-Position;
#else
EyeVector = -Position;
#endif
#ifdef WITH_COLOR
Color = VertexColor;
#endif
posClip = VertexPosition;
gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);
}
......@@ -67,6 +67,9 @@ public:
unsigned int setAttributePosition(VBO* vbo);
void setClippingPlane(const Geom::Vec4f& plane);
inline void setNoClippingPlane() { setClippingPlane(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f)); }
};
} // namespace Utils
......
......@@ -10,6 +10,8 @@ uniform vec4 materialDiffuse;
uniform vec4 materialSpecular;
uniform vec4 materialAmbient;
uniform float shininess;
uniform vec4 backColor;
FRAG_OUT_DEF;
void main()
......@@ -47,6 +49,10 @@ void main()
finalColor += vec4((Color*lambertTerm),0.0) ;
#endif
}
else
{
finalColor = backColor;
}
#endif
FRAG_OUT=finalColor;
}
......@@ -48,22 +48,31 @@ protected:
bool m_with_eyepos;
// shader sources OGL3
static std::string vertexShaderText;
static std::string fragmentShaderText;
static std::string vertexShaderText;
static std::string fragmentShaderText;
static std::string vertexShaderClipText;
static std::string fragmentShaderClipText;
// uniform locations
CGoGNGLuint m_unif_ambiant;
CGoGNGLuint m_unif_diffuse;
CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_backColor;
//values
Geom::Vec4f m_ambiant;
Geom::Vec4f m_diffuse;
Geom::Vec3f m_lightPos;
Geom::Vec4f m_backColor;
VBO* m_vboPos;
VBO* m_vboColor;
/// clipping
CGoGNGLuint m_unif_planeClip;
Geom::Vec4f m_planeClip;
void getLocations();
void sendParams();
......@@ -71,16 +80,17 @@ protected:
void restoreUniformsAttribs();
public:
ShaderSimpleFlat(bool doubleSided = false);
ShaderSimpleFlat(bool withClipping = false, bool doubleSided = false);
// inviduals parameter setting functions
void setAmbiant(const Geom::Vec4f& ambiant);
void setDiffuse(const Geom::Vec4f& diffuse);
void setLightPosition(const Geom::Vec3f& lp);
void setBackColor(const Geom::Vec4f& back);
const Geom::Vec4f& getAmbiant() const { return m_ambiant; }
const Geom::Vec4f& getDiffuse() const { return m_diffuse; }
......@@ -98,6 +108,11 @@ public:
// optional attributes
unsigned int setAttributeColor(VBO* vbo);
void unsetAttributeColor();
void setClippingPlane(const Geom::Vec4f& plane);
inline void setNoClippingPlane() { setClippingPlane(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f)); }
};
} // namespace Utils
......
//ShaderSimpleFlat::fragmentShaderClipText
PRECISION;
VARYING_FRAG vec3 LightDir;
VARYING_FRAG vec3 Position;
#ifdef WITH_COLOR
VARYING_FRAG vec3 Color;
#endif
uniform vec4 materialDiffuse;
uniform vec4 materialSpecular;
uniform vec4 materialAmbient;
uniform float shininess;
uniform vec4 backColor;
FRAG_OUT_DEF;
uniform vec4 planeClip;
VARYING_FRAG vec3 posClip;
void main()
{
if (dot(planeClip,vec4(posClip,1.0))>0.0)
discard;
vec3 DX = dFdx(Position);
vec3 DY = dFdy(Position);
vec3 N=normalize(cross(DX,DY));
vec3 L = normalize (LightDir);
vec4 finalColor = materialAmbient;
#ifdef DOUBLE_SIDED
float lambertTerm;
vec4 diffuseColor = materialDiffuse;
if (!gl_FrontFacing)
{
N *= -1.0;
lambertTerm = clamp(dot(N,L),0.0,1.0);
}
else
lambertTerm = clamp(dot(N,L),0.0,1.0);
#ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm;
#else
finalColor += vec4((Color*lambertTerm),0.0) ;
#endif
#else
float lambertTerm = clamp(dot(N,L),0.0,1.0);
if (gl_FrontFacing)
{
#ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm;
#else
finalColor += vec4((Color*lambertTerm),0.0) ;
#endif
}
else
{
finalColor = backColor;
}
#endif
FRAG_OUT=finalColor;
}
//ShaderSimpleFlat::vertexShaderClipText
ATTRIBUTE vec3 VertexPosition, VertexNormal;
#ifdef WITH_COLOR
ATTRIBUTE vec3 VertexColor;
#endif
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 ModelViewMatrix;
uniform vec3 lightPosition;
VARYING_VERT vec3 LightDir;
VARYING_VERT vec3 Position;
VARYING_VERT vec3 posClip;
#ifdef WITH_COLOR
VARYING_VERT vec3 Color;
#endif
INVARIANT_POS;
void main ()
{
Position = vec3 (ModelViewMatrix * vec4 (VertexPosition, 1.0));
LightDir = lightPosition - Position;
#ifdef WITH_COLOR
Color = VertexColor;
#endif
posClip = VertexPosition;
gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);
}
......@@ -3,11 +3,18 @@
uniform float vectorScale;
uniform mat4 ModelViewProjectionMatrix;
VARYING_IN vec3 VectorAttrib[];
uniform vec4 planeClip;
VARYING_IN vec3 posClip[];
void main()
{
gl_Position = ModelViewProjectionMatrix * POSITION_IN(0);
EmitVertex();
gl_Position = ModelViewProjectionMatrix * (POSITION_IN(0) + vec4(VectorAttrib[0] * vectorScale, 0.0));
EmitVertex();
EndPrimitive();
if (dot(planeClip,vec4(posClip[0],1.0))<=0.0)
{
gl_Position = ModelViewProjectionMatrix * POSITION_IN(0);
EmitVertex();
gl_Position = ModelViewProjectionMatrix * (POSITION_IN(0) + vec4(VectorAttrib[0] * vectorScale, 0.0));
EmitVertex();
EndPrimitive();
}
}
......@@ -54,6 +54,10 @@ protected:
VBO* m_vboPos;
VBO* m_vboVec;
/// clipping
CGoGNGLuint m_unif_planeClip;
Geom::Vec4f m_planeClip;
void getLocations();
void sendParams();
......@@ -61,7 +65,7 @@ protected:
void restoreUniformsAttribs();
public:
ShaderVectorPerVertex();
ShaderVectorPerVertex();
void setScale(float scale);
......@@ -70,6 +74,11 @@ public:
unsigned int setAttributePosition(VBO* vbo);
unsigned int setAttributeVector(VBO* vbo);
void setClippingPlane(const Geom::Vec4f& plane);
inline void setNoClippingPlane() { setClippingPlane(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f)); }
};
} // namespace Utils
......
......@@ -3,9 +3,12 @@
ATTRIBUTE vec3 VertexPosition;
ATTRIBUTE vec3 VertexVector;
VARYING_VERT vec3 VectorAttrib;
VARYING_VERT vec3 posClip;
INVARIANT_POS;
void main ()
{
posClip = VertexPosition;
VectorAttrib = VertexVector;
gl_Position = vec4(VertexPosition, 1.0);
}
......@@ -3,6 +3,9 @@
uniform float size;
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix;
uniform vec4 planeClip;
VARYING_IN vec3 posClip[1];
#ifdef WITH_PLANE
uniform vec3 eyePos;
......@@ -37,10 +40,11 @@ void corner( vec4 center, float x, float y)
void main()
{
if (dot(planeClip,vec4(posClip[0],1.0))<=0.0)
{
#ifdef WITH_COLOR_PER_VERTEX
colorsprite = color[0];
#endif
vec4 posCenter = ModelViewMatrix * POSITION_IN(0);
sphereCenter = posCenter.xyz;
......@@ -65,5 +69,6 @@ void main()
#endif
EndPrimitive();
}
}
......@@ -63,6 +63,11 @@ protected:
Geom::Vec3f m_ambiant;
Geom::Vec3f m_eyePos;
/// clipping