Commit 0097e8ea authored by Sylvain Thery's avatar Sylvain Thery

add clipping plane in volume explode rendering for 3map

parent 6de0fa92
......@@ -107,15 +107,21 @@ public:
void updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, const FunctorSelect& good = allDarts);
/**
* draw
* draw edges
*/
void drawEdges();
/**
* draw edges
*/
void drawFaces();
void setExplodeVolumes(float explode) { m_shader->setExplodeVolumes(explode);m_shaderL->setExplodeVolumes(explode);}
void setClippingPlane(const Geom::Vec4f& p) {m_shader->setClippingPlane(p); m_shaderL->setClippingPlane(p);}
void setNoClippingPlane() { Geom::Vec4f p(0.0f,0.0f,10000.0f,100000000000000000000000000.0f); m_shader->setClippingPlane(p); m_shaderL->setClippingPlane(p);}
void setAmbiant(const Geom::Vec4f& ambiant) { m_shader->setAmbiant(ambiant);}
void setDiffuse(const Geom::Vec4f& diffuse) { m_shader->setDiffuse(diffuse);}
......
......@@ -6,16 +6,20 @@ uniform mat4 ModelViewMatrix;
uniform vec3 lightPosition;
uniform vec4 diffuse;
uniform vec4 ambient;
uniform vec4 plane;
VARYING_OUT vec4 ColorFS;
void main(void)
{
float d = dot(plane,POSITION_IN(0));
if (d>=0.0)
{
vec3 v1 = POSITION_IN(2).xyz - POSITION_IN(1).xyz;
vec3 v2 = POSITION_IN(3).xyz - POSITION_IN(1).xyz;
vec3 N = cross(v1,v2);
N = normalize (vec3(NormalMatrix*vec4(N,0.0)));
// compute face center & lighting informations
// compute face center & lighting informations
vec4 newPos = ModelViewMatrix * POSITION_IN(1);
vec3 L = normalize (lightPosition - newPos.xyz);
float lambertTerm = dot(N,L);
......@@ -23,7 +27,7 @@ void main(void)
if (lambertTerm > 0.0)
ColorFS += diffuse * lambertTerm;
// Explode in face
// Explode in face
for (int i=1; i<NBVERTS_IN; i++)
{
......@@ -32,4 +36,5 @@ void main(void)
EmitVertex();
}
EndPrimitive();
}
}
......@@ -47,11 +47,13 @@ protected:
GLuint m_unif_diffuse;
GLuint m_unif_lightPos;
GLuint m_unif_explodeV;
GLuint m_unif_plane;
float m_explodeV;
Geom::Vec4f m_ambiant;
Geom::Vec4f m_diffuse;
Geom::Vec3f m_light_pos;
Geom::Vec4f m_plane;
VBO* m_vboPos;
......@@ -70,7 +72,9 @@ public:
void setLightPosition(const Geom::Vec3f& lp);
void setParams(float explodeV, const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec3f& lightPos);
void setClippingPlane(const Geom::Vec4f& plane);
void setParams(float explodeV, const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec3f& lightPos, const Geom::Vec4f& plane);
void setAttributePosition(VBO* vbo);
};
......
......@@ -3,11 +3,16 @@ uniform float explodeV;
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 NormalMatrix;
uniform mat4 ModelViewMatrix;
uniform vec4 plane;
uniform vec4 color;
VARYING_OUT vec4 ColorFS;
void main(void)
{
float d = dot(plane,POSITION_IN(0));
if (d>=0.0)
{
ColorFS = color;
for (int i=1; i<NBVERTS_IN; i++)
......@@ -17,4 +22,5 @@ void main(void)
EmitVertex();
}
EndPrimitive();
}
}
......@@ -45,9 +45,11 @@ protected:
// uniform locations
GLuint m_unif_color;
GLuint m_unif_explodeV;
GLuint m_unif_plane;
float m_explodeV;
Geom::Vec4f m_color;
Geom::Vec4f m_plane;
VBO* m_vboPos;
......@@ -62,7 +64,9 @@ public:
void setColor(const Geom::Vec4f& color);
void setParams(float explodeV, const Geom::Vec4f& color);
void setClippingPlane(const Geom::Vec4f& plane);
void setParams(float explodeV, const Geom::Vec4f& color, const Geom::Vec4f& plane);
void setAttributePosition(VBO* vbo);
};
......
......@@ -51,14 +51,6 @@ ShaderExplodeVolumes::ShaderExplodeVolumes()
std::string glxfrag(*GLSLShader::DEFINES_GL);
glxfrag.append(fragmentShaderText);
// std::cout << "----------------------------------------------------------" << std::endl;
// std::cout << glxvert << std::endl;
// std::cout << "----------------------------------------------------------" << std::endl;
// std::cout << glxfrag << std::endl;
// std::cout << "----------------------------------------------------------" << std::endl;
// std::cout << glxgeom << std::endl;
// std::cout << "----------------------------------------------------------" << std::endl;
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_LINES_ADJACENCY_EXT , GL_TRIANGLE_STRIP,4);
getLocations();
......@@ -68,8 +60,9 @@ ShaderExplodeVolumes::ShaderExplodeVolumes()
m_ambiant = Geom::Vec4f(0.05f, 0.05f, 0.1f, 0.0f);
m_diffuse = Geom::Vec4f(0.1f, 1.0f, 0.1f, 0.0f);
m_light_pos = Geom::Vec3f(10.0f, 10.0f, 1000.0f);
m_plane = Geom::Vec4f(0.0f, 0.0f, 1000.f, 1000000000000000000000000000.0f);
setParams(m_explodeV, m_ambiant, m_diffuse, m_light_pos);
setParams(m_explodeV, m_ambiant, m_diffuse, m_light_pos, m_plane);
}
void ShaderExplodeVolumes::getLocations()
......@@ -78,6 +71,7 @@ void ShaderExplodeVolumes::getLocations()
m_unif_ambiant = glGetUniformLocation(program_handler(),"ambient");
m_unif_diffuse = glGetUniformLocation(program_handler(),"diffuse");
m_unif_lightPos = glGetUniformLocation(program_handler(),"lightPosition");
m_unif_plane = glGetUniformLocation(program_handler(),"plane");
}
void ShaderExplodeVolumes::setAttributePosition(VBO* vbo)
......@@ -86,12 +80,13 @@ void ShaderExplodeVolumes::setAttributePosition(VBO* vbo)
bindVA_VBO("VertexPosition", vbo);
}
void ShaderExplodeVolumes::setParams(float explV, const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec3f& lightPos)
void ShaderExplodeVolumes::setParams(float explV, const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec3f& lightPos, const Geom::Vec4f& plane)
{
m_explodeV = explV;
m_ambiant = ambiant;
m_diffuse = diffuse;
m_light_pos = lightPos;
m_plane = plane;
bind();
......@@ -99,6 +94,7 @@ void ShaderExplodeVolumes::setParams(float explV, const Geom::Vec4f& ambiant, co
glUniform4fv(m_unif_ambiant, 1, ambiant.data());
glUniform4fv(m_unif_diffuse, 1, diffuse.data());
glUniform3fv(m_unif_lightPos, 1, lightPos.data());
glUniform4fv(m_unif_plane, 1, m_plane.data());
unbind(); // ??
}
......@@ -132,18 +128,29 @@ void ShaderExplodeVolumes::setLightPosition(const Geom::Vec3f& lp)
glUniform3fv(m_unif_lightPos,1,lp.data());
}
void ShaderExplodeVolumes::setClippingPlane(const Geom::Vec4f& plane)
{
m_plane = plane;
bind();
glUniform4fv(m_unif_plane,1, plane.data());
}
void ShaderExplodeVolumes::restoreUniformsAttribs()
{
m_unif_explodeV = glGetUniformLocation(program_handler(),"explodeV");
m_unif_ambiant = glGetUniformLocation(program_handler(),"ambient");
m_unif_diffuse = glGetUniformLocation(program_handler(),"diffuse");
m_unif_lightPos = glGetUniformLocation(program_handler(),"lightPosition");
m_unif_plane = glGetUniformLocation(program_handler(),"plane");
bind();
glUniform1f (m_unif_explodeV, m_explodeV);
glUniform4fv(m_unif_ambiant, 1, m_ambiant.data());
glUniform4fv(m_unif_diffuse, 1, m_diffuse.data());
glUniform3fv(m_unif_lightPos, 1, m_light_pos.data());
glUniform4fv(m_unif_plane, 1, m_plane.data());
bindVA_VBO("VertexPosition", m_vboPos);
unbind();
......
......@@ -58,13 +58,15 @@ ShaderExplodeVolumesLines::ShaderExplodeVolumesLines()
//Default values
m_explodeV = 0.9f;
m_color = Geom::Vec4f(0.05f, 0.05f, 0.05f, 0.0f);
setParams(m_explodeV, m_color);
m_plane = Geom::Vec4f(0.0f, 0.0f, 1000.f, 1000000000000000000000000000.0f);
setParams(m_explodeV, m_color, m_plane);
}
void ShaderExplodeVolumesLines::getLocations()
{
m_unif_explodeV = glGetUniformLocation(program_handler(),"explodeV");
m_unif_color = glGetUniformLocation(program_handler(),"color");
m_unif_plane = glGetUniformLocation(program_handler(),"plane");
}
void ShaderExplodeVolumesLines::setAttributePosition(VBO* vbo)
......@@ -73,15 +75,17 @@ void ShaderExplodeVolumesLines::setAttributePosition(VBO* vbo)
bindVA_VBO("VertexPosition", vbo);
}
void ShaderExplodeVolumesLines::setParams(float explV, const Geom::Vec4f& color)
void ShaderExplodeVolumesLines::setParams(float explV, const Geom::Vec4f& color, const Geom::Vec4f& plane)
{
m_explodeV = explV;
m_color = color;
m_plane = plane;
bind();
glUniform1f(m_unif_explodeV, explV);
glUniform4fv(m_unif_color, 1, color.data());
glUniform4fv(m_unif_plane, 1, m_plane.data());
unbind(); // ??
}
......@@ -100,15 +104,23 @@ void ShaderExplodeVolumesLines::setColor(const Geom::Vec4f& color)
glUniform4fv(m_unif_color,1, color.data());
}
void ShaderExplodeVolumesLines::setClippingPlane(const Geom::Vec4f& plane)
{
m_plane = plane;
bind();
glUniform4fv(m_unif_plane,1, plane.data());
}
void ShaderExplodeVolumesLines::restoreUniformsAttribs()
{
m_unif_explodeV = glGetUniformLocation(program_handler(),"explodeV");
m_unif_color = glGetUniformLocation(program_handler(),"color");
m_unif_plane = glGetUniformLocation(program_handler(),"plane");
bind();
glUniform1f (m_unif_explodeV, m_explodeV);
glUniform4fv(m_unif_color, 1, m_color.data());
glUniform4fv(m_unif_plane, 1, m_plane.data());
bindVA_VBO("VertexPosition", m_vboPos);
unbind();
......
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