Commit 26e238b1 authored by Sylvain Thery's avatar Sylvain Thery

add color per face to explode volume rendering

parent 21595e5a
...@@ -56,6 +56,8 @@ protected: ...@@ -56,6 +56,8 @@ protected:
Utils::ShaderExplodeVolumes* m_shader; Utils::ShaderExplodeVolumes* m_shader;
bool m_cpf;
Utils::ShaderExplodeVolumesLines* m_shaderL; Utils::ShaderExplodeVolumesLines* m_shaderL;
Utils::VBO* m_vboPos; Utils::VBO* m_vboPos;
...@@ -78,7 +80,7 @@ public: ...@@ -78,7 +80,7 @@ public:
* @param good functor that return true for darts of part to draw * @param good functor that return true for darts of part to draw
* @param type_vbo vbo to alloc ( VBO_P, VBO_PN, VBO_PNC, VBO_PC ..) * @param type_vbo vbo to alloc ( VBO_P, VBO_PN, VBO_PNC, VBO_PC ..)
*/ */
ExplodeVolumeRender() ; ExplodeVolumeRender(bool withColorPerFace=false) ;
/** /**
* Destructor * Destructor
...@@ -106,6 +108,16 @@ public: ...@@ -106,6 +108,16 @@ public:
template<typename PFP> template<typename PFP>
void updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, const FunctorSelect& good = allDarts) ; void updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, const FunctorSelect& good = allDarts) ;
/**
* update all drawing buffers
* @param map the map
* @param positions attribute of position vertices
* @param colorPerFace attribute of color (per face)
* @param good selector
*/
template<typename PFP>
void updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, typename PFP::TVEC3& colorPerFace, const FunctorSelect& good = allDarts) ;
/** /**
* draw edges * draw edges
*/ */
......
...@@ -40,7 +40,8 @@ namespace Render ...@@ -40,7 +40,8 @@ namespace Render
namespace GL2 namespace GL2
{ {
inline ExplodeVolumeRender::ExplodeVolumeRender() inline ExplodeVolumeRender::ExplodeVolumeRender(bool withColorPerFace):
m_cpf(withColorPerFace)
{ {
m_vboPos = new Utils::VBO(); m_vboPos = new Utils::VBO();
m_vboPos->setDataSize(3); m_vboPos->setDataSize(3);
...@@ -48,7 +49,7 @@ inline ExplodeVolumeRender::ExplodeVolumeRender() ...@@ -48,7 +49,7 @@ inline ExplodeVolumeRender::ExplodeVolumeRender()
m_vboPosLine = new Utils::VBO(); m_vboPosLine = new Utils::VBO();
m_vboPosLine->setDataSize(3); m_vboPosLine->setDataSize(3);
m_shader = new Utils::ShaderExplodeVolumes(); m_shader = new Utils::ShaderExplodeVolumes(withColorPerFace);
m_shaderL = new Utils::ShaderExplodeVolumesLines(); m_shaderL = new Utils::ShaderExplodeVolumesLines();
// m_shader->setAmbiant(Geom::Vec4f(0.1f,0.1f,0.1f,0.0f)); // m_shader->setAmbiant(Geom::Vec4f(0.1f,0.1f,0.1f,0.0f));
...@@ -69,6 +70,12 @@ inline ExplodeVolumeRender::~ExplodeVolumeRender() ...@@ -69,6 +70,12 @@ inline ExplodeVolumeRender::~ExplodeVolumeRender()
template<typename PFP> template<typename PFP>
void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, const FunctorSelect& good) void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, const FunctorSelect& good)
{ {
if (m_cpf)
{
CGoGNerr<< "ExplodeVolumeRender: problem wrong update fonction use the other" << CGoGNendl;
return;
}
typedef typename PFP::VEC3 VEC3; typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL; typedef typename PFP::REAL REAL;
...@@ -115,6 +122,85 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3 ...@@ -115,6 +122,85 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3
m_shader->setAttributePosition(m_vboPos); m_shader->setAttributePosition(m_vboPos);
buffer.clear();
TraversorCell<typename PFP::MAP> traEdge(map, PFP::MAP::ORBIT_IN_PARENT(EDGE),good);
for (Dart d=traEdge.begin(); d!=traEdge.end(); d=traEdge.next())
{
buffer.push_back(centerVolumes[d]);
buffer.push_back(positions[d]);
buffer.push_back(positions[ map.phi1(d)]);
}
m_nbLines = buffer.size()/3;
m_vboPosLine->allocate(buffer.size());
ptrPos = reinterpret_cast<VEC3*>(m_vboPosLine->lockPtr());
memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3));
m_vboPosLine->releasePtr();
m_shaderL->setAttributePosition(m_vboPosLine);
}
template<typename PFP>
void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, typename PFP::TVEC3& colorPerFace, const FunctorSelect& good)
{
if (!m_cpf)
{
CGoGNerr<< "ExplodeVolumeRender: problem wrong update fonction use the other" << CGoGNendl;
return;
}
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
CellMarker cmv(map,VOLUME);
AutoAttributeHandler<VEC3> centerVolumes(map,VOLUME,"centerVolumes");
TraversorW<typename PFP::MAP> traVol(map,good);
for (Dart d=traVol.begin(); d!=traVol.end(); d=traVol.next())
{
centerVolumes[d] = Algo::Geometry::volumeCentroid<PFP>(map, d, positions);
}
std::vector<VEC3> buffer;
buffer.reserve(16384);
TraversorCell<typename PFP::MAP> traFace(map, PFP::MAP::ORBIT_IN_PARENT(FACE),good);
for (Dart d=traFace.begin(); d!=traFace.end(); d=traFace.next())
{
Dart a = d;
Dart b = map.phi1(a);
Dart c = map.phi1(b);
// loop to cut a polygon in triangle on the fly (works only with convex faces)
do
{
buffer.push_back(centerVolumes[d]);
buffer.push_back(positions[d]);
buffer.push_back(positions[b]);
buffer.push_back(positions[c]);
buffer.push_back(colorPerFace[d]);
buffer.push_back(VEC3(0.,0.,0.)); // TODO use this place for center of face
b = c;
c = map.phi1(b);
} while (c != d);
}
m_nbTris = buffer.size()/4;
m_vboPos->allocate(buffer.size());
VEC3* ptrPos = reinterpret_cast<VEC3*>(m_vboPos->lockPtr());
memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3));
m_vboPos->releasePtr();
m_shader->setAttributePosition(m_vboPos);
buffer.clear(); buffer.clear();
TraversorCell<typename PFP::MAP> traEdge(map, PFP::MAP::ORBIT_IN_PARENT(EDGE),good); TraversorCell<typename PFP::MAP> traEdge(map, PFP::MAP::ORBIT_IN_PARENT(EDGE),good);
...@@ -138,10 +224,14 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3 ...@@ -138,10 +224,14 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3
} }
inline void ExplodeVolumeRender::drawFaces() inline void ExplodeVolumeRender::drawFaces()
{ {
m_shader->enableVertexAttribs(); m_shader->enableVertexAttribs();
glDrawArrays(GL_LINES_ADJACENCY_EXT , 0 , m_nbTris*4 ); if (m_cpf)
glDrawArrays(GL_TRIANGLES_ADJACENCY_EXT , 0 , m_nbTris*6 );
else
glDrawArrays(GL_LINES_ADJACENCY_EXT , 0 , m_nbTris*4 );
m_shader->disableVertexAttribs(); m_shader->disableVertexAttribs();
} }
......
...@@ -8,6 +8,7 @@ uniform vec4 diffuse; ...@@ -8,6 +8,7 @@ uniform vec4 diffuse;
uniform vec4 ambient; uniform vec4 ambient;
uniform vec4 plane; uniform vec4 plane;
VARYING_OUT vec4 ColorFS; VARYING_OUT vec4 ColorFS;
void main(void) void main(void)
{ {
float d = dot(plane,POSITION_IN(0)); float d = dot(plane,POSITION_IN(0));
...@@ -24,12 +25,16 @@ void main(void) ...@@ -24,12 +25,16 @@ void main(void)
vec3 L = normalize (lightPosition - newPos.xyz); vec3 L = normalize (lightPosition - newPos.xyz);
float lambertTerm = dot(N,L); float lambertTerm = dot(N,L);
ColorFS = ambient; ColorFS = ambient;
if (lambertTerm > 0.0) if (lambertTerm > 0.0)
ColorFS += diffuse * lambertTerm; #ifdef WITH_COLORPF
ColorFS += vec4(POSITION_IN(4).xyz,1.0) * lambertTerm;
#else
ColorFS += diffuse * lambertTerm;
#endif
// Explode in face // Explode in face
for (int i=1; i<=3; i++)
for (int i=1; i<NBVERTS_IN; i++)
{ {
vec4 P = explodeV * POSITION_IN(i) + (1.0-explodeV)* POSITION_IN(0); vec4 P = explodeV * POSITION_IN(i) + (1.0-explodeV)* POSITION_IN(0);
gl_Position = ModelViewProjectionMatrix * P; gl_Position = ModelViewProjectionMatrix * P;
...@@ -37,4 +42,6 @@ void main(void) ...@@ -37,4 +42,6 @@ void main(void)
} }
EndPrimitive(); EndPrimitive();
} }
} }
...@@ -62,7 +62,7 @@ protected: ...@@ -62,7 +62,7 @@ protected:
void restoreUniformsAttribs(); void restoreUniformsAttribs();
public: public:
ShaderExplodeVolumes(); ShaderExplodeVolumes(bool withColorPerFace=false);
void setExplodeVolumes(float explode); void setExplodeVolumes(float explode);
......
// ShaderFlatColorPerFace::geometryShaderText // ShaderFlatColorPerFace::geometryShaderText
uniform float explode; uniform float explode;
uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelViewProjectionMatrix;
uniform mat4 NormalMatrix; uniform mat4 NormalMatrix;
...@@ -24,7 +23,7 @@ void main(void) ...@@ -24,7 +23,7 @@ void main(void)
float lambertTerm = dot(N,L); float lambertTerm = dot(N,L);
int i; int i;
vec averageColor(0.,0.,0.); vec3 averageColor=vec3(0.,0.,0.);
for(i=0; i< NBVERTS_IN; i++) for(i=0; i< NBVERTS_IN; i++)
{ {
averageColor +=colorVertex[i]; averageColor +=colorVertex[i];
......
...@@ -36,7 +36,7 @@ namespace Utils ...@@ -36,7 +36,7 @@ namespace Utils
#include "shaderExplodeVolumes.geom" #include "shaderExplodeVolumes.geom"
ShaderExplodeVolumes::ShaderExplodeVolumes() ShaderExplodeVolumes::ShaderExplodeVolumes(bool withColorPerFace)
{ {
m_nameVS = "ShaderExplodeVolumes_vs"; m_nameVS = "ShaderExplodeVolumes_vs";
m_nameFS = "ShaderExplodeVolumes_fs"; m_nameFS = "ShaderExplodeVolumes_fs";
...@@ -46,12 +46,21 @@ ShaderExplodeVolumes::ShaderExplodeVolumes() ...@@ -46,12 +46,21 @@ ShaderExplodeVolumes::ShaderExplodeVolumes()
glxvert.append(vertexShaderText); glxvert.append(vertexShaderText);
std::string glxgeom(GLSLShader::defines_Geom("quads", "triangle_strip", 4)); std::string glxgeom(GLSLShader::defines_Geom("quads", "triangle_strip", 4));
if (withColorPerFace)
glxgeom.append("#define WITH_COLORPF 1\n");
glxgeom.append(geometryShaderText); glxgeom.append(geometryShaderText);
std::string glxfrag(*GLSLShader::DEFINES_GL); std::string glxfrag(*GLSLShader::DEFINES_GL);
glxfrag.append(fragmentShaderText); glxfrag.append(fragmentShaderText);
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_LINES_ADJACENCY_EXT , GL_TRIANGLE_STRIP,4); if (withColorPerFace)
{
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_TRIANGLES_ADJACENCY_EXT , GL_TRIANGLE_STRIP,4);
}
else
{
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_LINES_ADJACENCY_EXT , GL_TRIANGLE_STRIP,4);
}
getLocations(); getLocations();
......
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