Commit 35f2eb18 authored by Sylvain Thery's avatar Sylvain Thery

clipping on vectorPerVertexShader

parent 72f0a449
...@@ -45,7 +45,7 @@ Viewer::Viewer() : ...@@ -45,7 +45,7 @@ Viewer::Viewer() :
faceShrinkage = 1.0f ; faceShrinkage = 1.0f ;
colClear = Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f) ; 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) ; colSpec = Geom::Vec4f(0.9f, 0.9f, 0.9f, 1.0f) ;
colNormal = Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f) ; colNormal = Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f) ;
shininess = 80.0f ; shininess = 80.0f ;
...@@ -92,31 +92,33 @@ void Viewer::cb_initGL() ...@@ -92,31 +92,33 @@ void Viewer::cb_initGL()
m_positionVBO = new Utils::VBO() ; m_positionVBO = new Utils::VBO() ;
m_normalVBO = 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->setAttributePosition(m_positionVBO) ;
m_phongShader->setAttributeNormal(m_normalVBO) ; m_phongShader->setAttributeNormal(m_normalVBO) ;
m_phongShader->setAmbiant(colClear) ; m_phongShader->setAmbiant(colClear) ;
m_phongShader->setDiffuse(colDif) ; m_phongShader->setDiffuse(colDif) ;
m_phongShader->setSpecular(colSpec) ; m_phongShader->setSpecular(colSpec) ;
m_phongShader->setShininess(shininess) ; 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->setAttributePosition(m_positionVBO) ;
m_flatShader->setAmbiant(colClear) ; m_flatShader->setAmbiant(colClear) ;
m_flatShader->setDiffuse(colDif) ; m_flatShader->setDiffuse(colDif) ;
// m_flatShader->setDiffuseBack(Geom::Vec4f(0,0,0,0)) ; m_flatShader->setBackColor(Geom::Vec4f(0,0,0.2,0)) ;
// m_flatShader->setExplode(faceShrinkage) ;
m_vectorShader = new Utils::ShaderVectorPerVertex() ; m_vectorShader = new Utils::ShaderVectorPerVertex() ;
m_vectorShader->setAttributePosition(m_positionVBO) ; m_vectorShader->setAttributePosition(m_positionVBO) ;
m_vectorShader->setAttributeVector(m_normalVBO) ; m_vectorShader->setAttributeVector(m_normalVBO) ;
m_vectorShader->setColor(colNormal) ; m_vectorShader->setColor(colNormal) ;
m_simpleColorShader = new Utils::ShaderSimpleColor() ; m_simpleColorShader = new Utils::ShaderSimpleColor(true) ;
m_simpleColorShader->setAttributePosition(m_positionVBO) ; m_simpleColorShader->setAttributePosition(m_positionVBO) ;
Geom::Vec4f c(0.0f, 0.0f, 0.0f, 1.0f) ; Geom::Vec4f c(0.0f, 0.0f, 0.0f, 1.0f) ;
m_simpleColorShader->setColor(c) ; m_simpleColorShader->setColor(c) ;
m_pointSprite = new Utils::PointSprite() ; m_pointSprite = new Utils::PointSprite() ;
m_pointSprite->setAttributePosition(m_positionVBO) ; m_pointSprite->setAttributePosition(m_positionVBO) ;
m_pointSprite->setColor(Geom::Vec4f(0.0f, 0.0f, 1.0f, 1.0f)) ; m_pointSprite->setColor(Geom::Vec4f(0.0f, 0.0f, 1.0f, 1.0f)) ;
...@@ -132,25 +134,31 @@ void Viewer::cb_redraw() ...@@ -132,25 +134,31 @@ void Viewer::cb_redraw()
{ {
if(m_drawVertices) if(m_drawVertices)
{ {
glDepthFunc(GL_LEQUAL);
m_pointSprite->setSize(vertexScaleFactor) ; m_pointSprite->setSize(vertexScaleFactor) ;
m_render->draw(m_pointSprite, Algo::Render::GL2::POINTS) ; m_render->draw(m_pointSprite, Algo::Render::GL2::POINTS) ;
} }
if(m_drawEdges) if(m_drawEdges)
{ {
glDepthFunc(GL_LEQUAL); m_simpleColorShader->setColor(Geom::Vec4f(1.,1.,0.,0.));
glLineWidth(1.0f) ; glLineWidth(1.0f) ;
m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES) ; m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES) ;
} }
if(m_drawTopo)
{
glDepthFunc(GL_LEQUAL);
m_topoRender->drawTopo() ;
}
if(m_drawFaces) if(m_drawFaces)
{ {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ; glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
glEnable(GL_LIGHTING) ; if (m_drawEdges||m_drawTopo)
glEnable(GL_POLYGON_OFFSET_FILL) ; {
glPolygonOffset(1.0f, 1.0f) ; glEnable(GL_POLYGON_OFFSET_FILL) ;
glDepthFunc(GL_LESS); glPolygonOffset(1.0f, 1.0f) ;
}
switch(m_renderStyle) switch(m_renderStyle)
{ {
case FLAT : case FLAT :
...@@ -163,11 +171,7 @@ void Viewer::cb_redraw() ...@@ -163,11 +171,7 @@ void Viewer::cb_redraw()
glDisable(GL_POLYGON_OFFSET_FILL) ; glDisable(GL_POLYGON_OFFSET_FILL) ;
} }
if(m_drawTopo)
{
glDepthFunc(GL_LEQUAL);
m_topoRender->drawTopo() ;
}
if(m_drawNormals) if(m_drawNormals)
{ {
...@@ -210,6 +214,32 @@ void Viewer::cb_keyPress(int keycode) ...@@ -210,6 +214,32 @@ void Viewer::cb_keyPress(int keycode)
{ {
switch(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' : case 'c' :
myMap.check(); myMap.check();
break; break;
...@@ -578,6 +608,18 @@ void Viewer::importMesh(std::string& filename) ...@@ -578,6 +608,18 @@ void Viewer::importMesh(std::string& filename)
m_normalVBO->updateData(normal) ; m_normalVBO->updateData(normal) ;
setParamObject(bb.maxSize(), bb.center().data()) ; 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() ; updateGLMatrices() ;
std::cout << "#vertices -> " << Algo::Topo::getNbOrbits<VERTEX>(myMap) << std::endl; std::cout << "#vertices -> " << Algo::Topo::getNbOrbits<VERTEX>(myMap) << std::endl;
......
...@@ -3,11 +3,18 @@ ...@@ -3,11 +3,18 @@
uniform float vectorScale; uniform float vectorScale;
uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelViewProjectionMatrix;
VARYING_IN vec3 VectorAttrib[]; VARYING_IN vec3 VectorAttrib[];
uniform vec4 planeClip;
VARYING_IN vec3 posClip[];
void main() void main()
{ {
gl_Position = ModelViewProjectionMatrix * POSITION_IN(0); if (dot(planeClip,vec4(posClip[0],1.0))<=0.0)
EmitVertex(); {
gl_Position = ModelViewProjectionMatrix * (POSITION_IN(0) + vec4(VectorAttrib[0] * vectorScale, 0.0)); gl_Position = ModelViewProjectionMatrix * POSITION_IN(0);
EmitVertex(); EmitVertex();
EndPrimitive(); gl_Position = ModelViewProjectionMatrix * (POSITION_IN(0) + vec4(VectorAttrib[0] * vectorScale, 0.0));
EmitVertex();
EndPrimitive();
}
} }
...@@ -54,6 +54,10 @@ protected: ...@@ -54,6 +54,10 @@ protected:
VBO* m_vboPos; VBO* m_vboPos;
VBO* m_vboVec; VBO* m_vboVec;
/// clipping
CGoGNGLuint m_unif_planeClip;
Geom::Vec4f m_planeClip;
void getLocations(); void getLocations();
void sendParams(); void sendParams();
...@@ -61,7 +65,7 @@ protected: ...@@ -61,7 +65,7 @@ protected:
void restoreUniformsAttribs(); void restoreUniformsAttribs();
public: public:
ShaderVectorPerVertex(); ShaderVectorPerVertex();
void setScale(float scale); void setScale(float scale);
...@@ -70,6 +74,11 @@ public: ...@@ -70,6 +74,11 @@ public:
unsigned int setAttributePosition(VBO* vbo); unsigned int setAttributePosition(VBO* vbo);
unsigned int setAttributeVector(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 } // namespace Utils
......
...@@ -3,9 +3,12 @@ ...@@ -3,9 +3,12 @@
ATTRIBUTE vec3 VertexPosition; ATTRIBUTE vec3 VertexPosition;
ATTRIBUTE vec3 VertexVector; ATTRIBUTE vec3 VertexVector;
VARYING_VERT vec3 VectorAttrib; VARYING_VERT vec3 VectorAttrib;
VARYING_VERT vec3 posClip;
INVARIANT_POS; INVARIANT_POS;
void main () void main ()
{ {
posClip = VertexPosition;
VectorAttrib = VertexVector; VectorAttrib = VertexVector;
gl_Position = vec4(VertexPosition, 1.0); gl_Position = vec4(VertexPosition, 1.0);
} }
...@@ -40,7 +40,7 @@ void corner( vec4 center, float x, float y) ...@@ -40,7 +40,7 @@ void corner( vec4 center, float x, float y)
void main() void main()
{ {
if (dot(planeClip,vec4(posClip[0],1.0))<0.0) if (dot(planeClip,vec4(posClip[0],1.0))<=0.0)
{ {
#ifdef WITH_COLOR_PER_VERTEX #ifdef WITH_COLOR_PER_VERTEX
colorsprite = color[0]; colorsprite = color[0];
......
...@@ -37,7 +37,8 @@ namespace Utils ...@@ -37,7 +37,8 @@ namespace Utils
ShaderVectorPerVertex::ShaderVectorPerVertex() : ShaderVectorPerVertex::ShaderVectorPerVertex() :
m_scale(1.0f), m_scale(1.0f),
m_color(Geom::Vec4f(1.0f, 0.0f, 0.0f, 0.0f)) m_color (1.0f, 0.0f, 0.0f, 0.0f),
m_planeClip(0.0f,0.0f,0.0f,0.0f)
{ {
m_nameVS = "ShaderVectorPerVertex_vs"; m_nameVS = "ShaderVectorPerVertex_vs";
m_nameFS = "ShaderVectorPerVertex_fs"; m_nameFS = "ShaderVectorPerVertex_fs";
...@@ -64,6 +65,7 @@ void ShaderVectorPerVertex::getLocations() ...@@ -64,6 +65,7 @@ void ShaderVectorPerVertex::getLocations()
bind(); bind();
*m_uniform_scale = glGetUniformLocation(this->program_handler(), "vectorScale"); *m_uniform_scale = glGetUniformLocation(this->program_handler(), "vectorScale");
*m_uniform_color = glGetUniformLocation(this->program_handler(), "vectorColor"); *m_uniform_color = glGetUniformLocation(this->program_handler(), "vectorColor");
*m_unif_planeClip = glGetUniformLocation(this->program_handler(), "planeClip");
unbind(); unbind();
} }
...@@ -72,6 +74,9 @@ void ShaderVectorPerVertex::sendParams() ...@@ -72,6 +74,9 @@ void ShaderVectorPerVertex::sendParams()
bind(); bind();
glUniform1f(*m_uniform_scale, m_scale); glUniform1f(*m_uniform_scale, m_scale);
glUniform4fv(*m_uniform_color, 1, m_color.data()); glUniform4fv(*m_uniform_color, 1, m_color.data());
if (*m_unif_planeClip > 0)
glUniform4fv(*m_unif_planeClip, 1, m_planeClip.data());
unbind(); unbind();
} }
...@@ -120,6 +125,18 @@ void ShaderVectorPerVertex::restoreUniformsAttribs() ...@@ -120,6 +125,18 @@ void ShaderVectorPerVertex::restoreUniformsAttribs()
unbind(); unbind();
} }
void ShaderVectorPerVertex::setClippingPlane(const Geom::Vec4f& plane)
{
if (*m_unif_planeClip > 0)
{
m_planeClip = plane;
bind();
glUniform4fv(*m_unif_planeClip, 1, plane.data());
unbind();
}
}
} // namespace Utils } // namespace Utils
} // namespace CGoGN } // namespace CGoGN
...@@ -38,10 +38,11 @@ PointSprite::PointSprite(bool withColorPerVertex, bool withPlane) : ...@@ -38,10 +38,11 @@ PointSprite::PointSprite(bool withColorPerVertex, bool withPlane) :
colorPerVertex(withColorPerVertex), colorPerVertex(withColorPerVertex),
plane(withPlane), plane(withPlane),
m_size(1.0f), m_size(1.0f),
m_color(Geom::Vec4f(0.0f, 0.0f, 1.0f, 1.0f)), m_color(0.0f, 0.0f, 1.0f, 1.0f),
m_lightPos(Geom::Vec3f(100.0f, 100.0f, 100.0f)), m_lightPos(100.0f, 100.0f, 100.0f),
m_ambiant(Geom::Vec3f(0.1f, 0.1f, 0.1f)), m_ambiant(0.1f, 0.1f, 0.1f),
m_eyePos(Geom::Vec3f(0.0f, 0.0f, 0.0f)) m_eyePos(0.0f, 0.0f, 0.0f),
m_planeClip(0.0f,0.0f,0.0f,0.0f)
{ {
std::string glxvert(*GLSLShader::DEFINES_GL); std::string glxvert(*GLSLShader::DEFINES_GL);
if (withColorPerVertex) if (withColorPerVertex)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment