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:
Utils::ShaderExplodeVolumes* m_shader;
bool m_cpf;
Utils::ShaderExplodeVolumesLines* m_shaderL;
Utils::VBO* m_vboPos;
......@@ -78,7 +80,7 @@ public:
* @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 ..)
*/
ExplodeVolumeRender() ;
ExplodeVolumeRender(bool withColorPerFace=false) ;
/**
* Destructor
......@@ -106,6 +108,16 @@ public:
template<typename PFP>
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
*/
......
......@@ -40,7 +40,8 @@ namespace Render
namespace GL2
{
inline ExplodeVolumeRender::ExplodeVolumeRender()
inline ExplodeVolumeRender::ExplodeVolumeRender(bool withColorPerFace):
m_cpf(withColorPerFace)
{
m_vboPos = new Utils::VBO();
m_vboPos->setDataSize(3);
......@@ -48,7 +49,7 @@ inline ExplodeVolumeRender::ExplodeVolumeRender()
m_vboPosLine = new Utils::VBO();
m_vboPosLine->setDataSize(3);
m_shader = new Utils::ShaderExplodeVolumes();
m_shader = new Utils::ShaderExplodeVolumes(withColorPerFace);
m_shaderL = new Utils::ShaderExplodeVolumesLines();
// m_shader->setAmbiant(Geom::Vec4f(0.1f,0.1f,0.1f,0.0f));
......@@ -69,6 +70,12 @@ inline ExplodeVolumeRender::~ExplodeVolumeRender()
template<typename PFP>
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::REAL REAL;
......@@ -115,6 +122,85 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3
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();
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
}
inline void ExplodeVolumeRender::drawFaces()
{
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();
}
......
......@@ -8,6 +8,7 @@ uniform vec4 diffuse;
uniform vec4 ambient;
uniform vec4 plane;
VARYING_OUT vec4 ColorFS;
void main(void)
{
float d = dot(plane,POSITION_IN(0));
......@@ -24,12 +25,16 @@ void main(void)
vec3 L = normalize (lightPosition - newPos.xyz);
float lambertTerm = dot(N,L);
ColorFS = ambient;
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
for (int i=1; i<NBVERTS_IN; i++)
for (int i=1; i<=3; i++)
{
vec4 P = explodeV * POSITION_IN(i) + (1.0-explodeV)* POSITION_IN(0);
gl_Position = ModelViewProjectionMatrix * P;
......@@ -37,4 +42,6 @@ void main(void)
}
EndPrimitive();
}
}
......@@ -62,7 +62,7 @@ protected:
void restoreUniformsAttribs();
public:
ShaderExplodeVolumes();
ShaderExplodeVolumes(bool withColorPerFace=false);
void setExplodeVolumes(float explode);
......
// ShaderFlatColorPerFace::geometryShaderText
uniform float explode;
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 NormalMatrix;
......@@ -24,7 +23,7 @@ void main(void)
float lambertTerm = dot(N,L);
int i;
vec averageColor(0.,0.,0.);
vec3 averageColor=vec3(0.,0.,0.);
for(i=0; i< NBVERTS_IN; i++)
{
averageColor +=colorVertex[i];
......
......@@ -36,7 +36,7 @@ namespace Utils
#include "shaderExplodeVolumes.geom"
ShaderExplodeVolumes::ShaderExplodeVolumes()
ShaderExplodeVolumes::ShaderExplodeVolumes(bool withColorPerFace)
{
m_nameVS = "ShaderExplodeVolumes_vs";
m_nameFS = "ShaderExplodeVolumes_fs";
......@@ -46,12 +46,21 @@ ShaderExplodeVolumes::ShaderExplodeVolumes()
glxvert.append(vertexShaderText);
std::string glxgeom(GLSLShader::defines_Geom("quads", "triangle_strip", 4));
if (withColorPerFace)
glxgeom.append("#define WITH_COLORPF 1\n");
glxgeom.append(geometryShaderText);
std::string glxfrag(*GLSLShader::DEFINES_GL);
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();
......
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