Commit bbe3c27b authored by untereiner's avatar untereiner

Merge cgogn:~thery/CGoGN

parents 64a8ae55 9276de25
......@@ -422,6 +422,12 @@ int main(int argc, char **argv)
prim.hexaGrid_topo(nb,nb,nb);
prim.embedHexaGrid(1.0f,1.0f,1.0f);
for (unsigned int i=position.begin(); i != position.end(); position.next(i))
{
PFP::VEC3 pert(float(double(rand())/RAND_MAX/20.0),float(double(rand())/RAND_MAX/20.0),float(double(rand())/RAND_MAX/20.0));
position[i]+= pert;
}
color = myMap.addAttribute<PFP::VEC3, VOLUME>("color");
TraversorW<PFP::MAP> tra(myMap);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
......
......@@ -56,16 +56,16 @@
</property>
</widget>
</item>
<item row="2" column="2" alignment="Qt::AlignRight">
<item row="2" column="2">
<widget class="QPushButton" name="button_refreshVBOs">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Refresh</string>
......@@ -75,11 +75,7 @@
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="Line" name="line"/>
</item>
<item>
<widget class="QCheckBox" name="check_renderVertices">
......
......@@ -32,6 +32,7 @@
#include "Topology/generic/attributeHandler.h"
#include "Topology/generic/functor.h"
#include "Utils/vbo_base.h"
#include "Utils/Shaders/shaderExplodeSmoothVolumes.h"
#include "Utils/Shaders/shaderExplodeVolumes.h"
#include "Utils/Shaders/shaderExplodeVolumesLines.h"
......@@ -54,16 +55,22 @@ protected:
Utils::ShaderExplodeVolumes* m_shader;
Utils::ShaderExplodeSmoothVolumes* m_shaderS;
bool m_cpf;
bool m_ef;
bool m_smooth;
Utils::ShaderExplodeVolumesLines* m_shaderL;
Utils::VBO* m_vboPos;
Utils::VBO* m_vboColors;
Utils::VBO* m_vboNormals;
Utils::VBO* m_vboPosLine;
/**
......@@ -75,13 +82,20 @@ protected:
Geom::Vec3f m_globalColor;
template<typename PFP>
void updateSmooth(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const VolumeAttribute<typename PFP::VEC3>& colorPerFace, const FunctorSelect& good = allDarts) ;
template<typename PFP>
void updateSmooth(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const FunctorSelect& good = allDarts) ;
public:
/**
* Constructor
* @param withColorPerFace affect a color per face
* @param withExplodeFace shrinj each face
*/
ExplodeVolumeRender(bool withColorPerFace = false, bool withExplodeFace = false) ;
ExplodeVolumeRender(bool withColorPerFace = false, bool withExplodeFace = false, bool withSmoothFaces = false) ;
/**
* Destructor
......@@ -117,6 +131,7 @@ public:
template<typename PFP>
void updateData(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const VolumeAttribute<typename PFP::VEC3>& colorPerFace, const FunctorSelect& good = allDarts) ;
/**
* draw edges
*/
......
......@@ -159,7 +159,7 @@ Dart Traversor3XY<MAP, ORBX, ORBY>::begin()
}
}
if(ORBY == VOLUME)
if ((ORBY == VOLUME) && (m_current != NIL))
{
if(m_map.isBoundaryMarked3(m_current))
m_current = next();
......
// ShaderExplodeSmoothVolumes::fragmentShaderText
uniform vec4 ambient;
uniform vec4 backColor;
VARYING_FRAG vec4 normalFS;
VARYING_FRAG vec4 lightFS;
VARYING_FRAG vec3 colorVert;
void main()
{
float lambertTerm = dot(normalize(normalFS),normalize(lightFS));
if (lambertTerm > 0.0)
gl_FragColor = ambient + vec4(colorVert*lambertTerm, 1.0);
else
gl_FragColor = ambient - backColor*lambertTerm;
}
// ShaderExplodeSmoothVolumes::geometryShaderText
uniform float explodeV;
uniform float explodeF;
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 NormalMatrix;
uniform mat4 ModelViewMatrix;
uniform vec3 lightPosition;
uniform vec4 plane;
VARYING_IN vec3 colorVertex[4];
VARYING_IN vec3 normalVertex[4];
VARYING_OUT vec3 normalFS;
VARYING_OUT vec3 lightFS;
VARYING_OUT vec3 colorVert;
void main(void)
{
float d = dot(plane,POSITION_IN(0));
if (d<=0.0)
{
for (int i=1; i<=3; i++)
{
// explode in face
vec4 P = explodeF * POSITION_IN(i) + (1.0-explodeF)* vec4(colorVertex[0],1.0);
// compute vextex illum from pos & normal
vec3 L = normalize (lightPosition - P.xyz);
vec3 N = normalize (vec3(NormalMatrix*vec4(normalVertex[i],0.0)));
// explode in volume
vec4 Q = explodeV * P + (1.0-explodeV)* POSITION_IN(0);
gl_Position = ModelViewProjectionMatrix * Q;
colorVert = colorVertex[i];
normalFS = N;
lightFS = L;
EmitVertex();
}
EndPrimitive();
}
}
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __CGOGN_SHADER_EXPLODE_SMOOTH_VOLUMES__
#define __CGOGN_SHADER_EXPLODE_SMOOTH_VOLUMES__
#include "Utils/GLSLShader.h"
#include "Geometry/vector_gen.h"
namespace CGoGN
{
namespace Utils
{
class ShaderExplodeSmoothVolumes : public GLSLShader
{
protected:
// shader sources
static std::string vertexShaderText;
static std::string fragmentShaderText;
static std::string geometryShaderText;
// uniform locations
CGoGNGLuint m_unif_ambiant;
CGoGNGLuint m_unif_backColor;
CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_explodeV;
CGoGNGLuint m_unif_explodeF;
CGoGNGLuint m_unif_plane;
// local storage for uniforms
float m_explodeV;
float m_explodeF;
Geom::Vec4f m_ambiant;
Geom::Vec4f m_backColor;
Geom::Vec3f m_light_pos;
Geom::Vec4f m_plane;
// VBO
VBO* m_vboPos;
VBO* m_vboColors;
VBO* m_vboNormals;
bool m_wcpf;
bool m_wef;
void getLocations();
void restoreUniformsAttribs();
public:
ShaderExplodeSmoothVolumes(bool withColorPerFace=false, bool withExplodeFace=false);
void setExplodeVolumes(float explode);
void setExplodeFaces(float explode);
void setAmbiant(const Geom::Vec4f& ambiant);
void setBackColor(const Geom::Vec4f& backColor);
void setLightPosition(const Geom::Vec3f& lp);
void setClippingPlane(const Geom::Vec4f& plane);
void setParams(float explodeV, float explodeF, const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec3f& lightPos, const Geom::Vec4f& plane);
unsigned int setAttributePosition(VBO* vbo);
unsigned int setAttributeColor(VBO* vbo);
unsigned int setAttributeNormal(VBO* vbo);
};
} // namespace Utils
} // namespace CGoGN
#endif
// ShaderExplodeSmoothVolumes::vertexShaderText
ATTRIBUTE vec3 VertexPosition;
ATTRIBUTE vec3 VertexNormal;
ATTRIBUTE vec3 VertexColor;
VARYING_VERT vec3 normalVertex;
VARYING_VERT vec3 colorVertex;
void main()
{
colorVertex = VertexColor;
normalVertex = VertexNormal;
gl_Position = vec4(VertexPosition, 1.0);
}
......@@ -23,7 +23,7 @@ void main(void)
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)));
N = normalize (vec3(NormalMatrix*vec4(N,0.0)));
// compute face center & lighting informations
vec4 newPos = ModelViewMatrix * vec4(colorVertex[0],1.0);
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include <string.h>
#include "Utils/Shaders/shaderExplodeSmoothVolumes.h"
namespace CGoGN
{
namespace Utils
{
#include "shaderExplodeSmoothVolumes.vert"
#include "shaderExplodeSmoothVolumes.frag"
#include "shaderExplodeSmoothVolumes.geom"
ShaderExplodeSmoothVolumes::ShaderExplodeSmoothVolumes(bool withColorPerFace, bool withExplodeFace):
m_wcpf(withColorPerFace),
m_wef(withExplodeFace)
{
m_nameVS = "ShaderExplodeSmoothVolumes_vs";
m_nameFS = "ShaderExplodeSmoothVolumes_fs";
m_nameGS = "ShaderExplodeSmoothVolumes_gs";
std::string glxvert(*GLSLShader::DEFINES_GL);
glxvert.append(vertexShaderText);
std::string glxgeom;
glxgeom.append(GLSLShader::defines_Geom("lines_with_adjacency", "triangle_strip", 3));
if (withColorPerFace)
glxgeom.append("#define WITH_COLORPF 1\n");
if (withExplodeFace)
glxgeom.append("#define WITH_EXPLODE_FACE 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);
getLocations();
//Default values
m_explodeV = 0.9f;
m_explodeF = 0.9f;
m_ambiant = Geom::Vec4f(0.05f, 0.05f, 0.1f, 0.0f);
m_backColor = Geom::Vec4f(1.0f, 0.1f, 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_explodeF, m_ambiant, m_backColor, m_light_pos, m_plane);
}
void ShaderExplodeSmoothVolumes::getLocations()
{
bind();
*m_unif_explodeV = glGetUniformLocation(program_handler(),"explodeV");
*m_unif_explodeF = glGetUniformLocation(program_handler(),"explodeF");
*m_unif_ambiant = glGetUniformLocation(program_handler(),"ambient");
*m_unif_backColor = glGetUniformLocation(program_handler(),"backColor");
*m_unif_lightPos = glGetUniformLocation(program_handler(),"lightPosition");
*m_unif_plane = glGetUniformLocation(program_handler(),"plane");
unbind();
}
unsigned int ShaderExplodeSmoothVolumes::setAttributePosition(VBO* vbo)
{
m_vboPos = vbo;
bind();
unsigned int id = bindVA_VBO("VertexPosition", vbo);
unbind();
return id;
}
unsigned int ShaderExplodeSmoothVolumes::setAttributeColor(VBO* vbo)
{
m_vboColors = vbo;
bind();
unsigned int id = bindVA_VBO("VertexColor", vbo);
unbind();
return id;
}
unsigned int ShaderExplodeSmoothVolumes::setAttributeNormal(VBO* vbo)
{
m_vboNormals = vbo;
bind();
unsigned int id = bindVA_VBO("VertexNormal", vbo);
unbind();
return id;
}
void ShaderExplodeSmoothVolumes::setParams(float explV, float explF, const Geom::Vec4f& ambiant, const Geom::Vec4f& backColor, const Geom::Vec3f& lightPos, const Geom::Vec4f& plane)
{
bind();
m_explodeV = explV;
glUniform1f(*m_unif_explodeV, explV);
m_explodeF = explF;
glUniform1f(*m_unif_explodeF, explF);
m_ambiant = ambiant;
glUniform4fv(*m_unif_ambiant, 1, ambiant.data());
m_backColor = backColor;
glUniform4fv(*m_unif_backColor, 1, backColor.data());
m_light_pos = lightPos;
glUniform3fv(*m_unif_lightPos, 1, lightPos.data());
m_plane = plane;
glUniform4fv(*m_unif_plane, 1, m_plane.data());
unbind();
}
void ShaderExplodeSmoothVolumes::setExplodeVolumes(float explode)
{
m_explodeV = explode;
bind();
glUniform1f(*m_unif_explodeV, explode);
unbind();
}
void ShaderExplodeSmoothVolumes::setExplodeFaces(float explode)
{
m_explodeF = explode;
bind();
glUniform1f(*m_unif_explodeF, explode);
unbind();
}
void ShaderExplodeSmoothVolumes::setAmbiant(const Geom::Vec4f& ambiant)
{
m_ambiant = ambiant;
bind();
glUniform4fv(*m_unif_ambiant,1, ambiant.data());
unbind();
}
void ShaderExplodeSmoothVolumes::setBackColor(const Geom::Vec4f& backColor)
{
m_backColor = backColor;
bind();
glUniform4fv(*m_unif_backColor, 1, backColor.data());
unbind();
}
void ShaderExplodeSmoothVolumes::setLightPosition(const Geom::Vec3f& lp)
{
m_light_pos = lp;
bind();
glUniform3fv(*m_unif_lightPos,1,lp.data());
unbind();
}
void ShaderExplodeSmoothVolumes::setClippingPlane(const Geom::Vec4f& plane)
{
m_plane = plane;
bind();
glUniform4fv(*m_unif_plane,1, plane.data());
unbind();
}
void ShaderExplodeSmoothVolumes::restoreUniformsAttribs()
{
bind();
*m_unif_explodeV = glGetUniformLocation(program_handler(),"explodeV");
glUniform1f (*m_unif_explodeV, m_explodeV);
*m_unif_explodeF = glGetUniformLocation(program_handler(),"explodeF");
glUniform1f (*m_unif_explodeF, m_explodeF);
*m_unif_ambiant = glGetUniformLocation(program_handler(),"ambient");
glUniform4fv(*m_unif_ambiant, 1, m_ambiant.data());
*m_unif_backColor = glGetUniformLocation(program_handler(),"backColor");
glUniform4fv(*m_unif_backColor, 1, m_backColor.data());
*m_unif_lightPos = glGetUniformLocation(program_handler(),"lightPosition");
glUniform3fv(*m_unif_lightPos, 1, m_light_pos.data());
*m_unif_plane = glGetUniformLocation(program_handler(),"plane");
glUniform4fv(*m_unif_plane, 1, m_plane.data());
bindVA_VBO("VertexPosition", m_vboPos);
bindVA_VBO("VertexColor", m_vboColors);
bindVA_VBO("VertexNormal", m_vboNormals);
unbind();
}
} // namespace Utils
} // namespace CGoGN
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