Commit 0f8e560c authored by Sylvain Thery's avatar Sylvain Thery

Merge remote-tracking branch 'origin/update_geosiris' into develop

parents f54353e0 1200f45a
......@@ -92,20 +92,20 @@ void Viewer::cb_initGL()
m_positionVBO = new Utils::VBO() ;
m_normalVBO = new Utils::VBO() ;
m_phongShader = new Utils::ShaderPhong(true,false,false) ;
m_phongShader = new Utils::ShaderPhong(true,false) ;
m_phongShader->setAttributePosition(m_positionVBO) ;
m_phongShader->setAttributeNormal(m_normalVBO) ;
m_phongShader->setAmbiant(colClear) ;
m_phongShader->setDiffuse(colDif) ;
m_phongShader->setSpecular(colSpec) ;
m_phongShader->setShininess(shininess) ;
m_phongShader->setBackColor(Geom::Vec4f(0,0,0.2,0)) ;
m_phongShader->setBackColor(Geom::Vec4f(0.9f, 0.0f, 0.0f, 0.0f));
m_flatShader = new Utils::ShaderSimpleFlat(true,false) ;
m_flatShader = new Utils::ShaderSimpleFlat() ;
m_flatShader->setAttributePosition(m_positionVBO) ;
m_flatShader->setAmbiant(colClear) ;
m_flatShader->setDiffuse(colDif) ;
m_flatShader->setBackColor(Geom::Vec4f(0,0,0.2,0)) ;
m_flatShader->setBackColor(Geom::Vec4f(0.9f, 0.0f, 0.0f, 0.0f));
m_vectorShader = new Utils::ShaderVectorPerVertex() ;
......@@ -182,7 +182,7 @@ void Viewer::cb_redraw()
}
m_nbFrames++;
if (m_nbFrames >=100)
if (m_nbFrames >=500)
{
std::cout << 100000.0/m_frame_ch.elapsed()<< " fps"<<std::endl;
m_nbFrames = 0;
......@@ -214,6 +214,34 @@ void Viewer::cb_keyPress(int keycode)
{
switch(keycode)
{
case 'd':
{
m_phongShader->setDoubleSided(true);
m_flatShader->setDoubleSided(true);
updateGL();
}
break;
case 'D':
{
m_phongShader->setDoubleSided(false);
m_flatShader->setDoubleSided(false);
updateGL();
}
break;
case 'q':
{
Utils::Chrono ch;
ch.start();
for (int i = 0; i < 1000; ++i)
{
m_render->draw(m_flatShader, Algo::Render::GL2::TRIANGLES);
glFlush();
}
std::cout << "speed render " << 1000.0*1000.0/ch.elapsed() << " fps " << std::endl;
}
case 'n':
m_flatShader->setNoClippingPlane();
m_phongShader->setNoClippingPlane();
......
......@@ -43,6 +43,7 @@
#include "Utils/Shaders/shaderPhong.h"
#include "Utils/Shaders/shaderSimpleFlat.h"
//#include "Utils/Shaders/shaderFlat.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderVectorPerVertex.h"
#include "Utils/pointSprite.h"
......
......@@ -2,12 +2,20 @@
uniform vec4 diffuse;
uniform vec4 diffuseBack;
uniform vec4 ambient;
uniform bool doubleSided;
VARYING_FRAG float lambertTerm;
FRAG_OUT_DEF;
void main()
{
if (gl_FrontFacing)
FRAG_OUT = ambient + lambertTerm*diffuse;
else
FRAG_OUT = ambient + lambertTerm*diffuseBack;
{
if (!doubleSided)
discard;
FRAG_OUT = ambient - lambertTerm*diffuseBack;
}
}
......@@ -5,6 +5,7 @@ uniform mat4 ModelViewProjectionMatrix;
uniform mat4 NormalMatrix;
uniform mat4 ModelViewMatrix;
uniform vec3 lightPosition;
VARYING_OUT float lambertTerm;
void main(void)
......@@ -18,7 +19,7 @@ void main(void)
center /= 3.0;
vec4 newPos = ModelViewMatrix * vec4(center,1.0);
vec3 L = normalize (lightPosition - newPos.xyz);
lambertTerm = clamp(dot(N,L),0.0,1.0);
lambertTerm = dot(N,L);
int i;
for(i=0; i< NBVERTS_IN; i++)
......
......@@ -50,7 +50,9 @@ protected:
CGoGNGLuint m_unif_diffuseback;
CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_explode;
CGoGNGLuint m_unif_doubleSided;
int m_doubleSided;
float m_explode;
Geom::Vec4f m_ambiant;
Geom::Vec4f m_diffuse;
......@@ -66,13 +68,15 @@ protected:
public:
ShaderFlat();
void setDoubleSided(bool doubleSided);
void setExplode(float explode);
void setAmbiant(const Geom::Vec4f& ambiant);
void setDiffuse(const Geom::Vec4f& diffuse);
void setDiffuseBack(const Geom::Vec4f& diffuseb);
void setBackColor(const Geom::Vec4f& diffuseb);
void setLightPosition(const Geom::Vec3f& lp);
......
......@@ -8,30 +8,30 @@ VARYING_FRAG vec3 Color;
uniform vec4 materialDiffuse;
uniform vec4 materialSpecular;
uniform vec4 materialAmbient;
uniform float shininess;
uniform vec4 backColor;
uniform float shininess;
uniform bool doubleSided;
FRAG_OUT_DEF;
void main()
{
vec3 N = normalize (Normal);
vec3 L = normalize (LightDir);
//float lambertTerm = clamp(dot(N,L),0.0,1.0);
vec4 finalColor = materialAmbient;
#ifdef DOUBLE_SIDED
float lambertTerm;
vec4 diffuseColor = materialDiffuse;
vec4 currentColor = materialDiffuse;
if (!gl_FrontFacing)
{
if (!doubleSided)
discard;
N *= -1.0;
lambertTerm = clamp(dot(N,L),0.0,1.0);
currentColor = backColor;
}
else
lambertTerm = clamp(dot(N,L),0.0,1.0);
float lambertTerm = clamp(dot(N,L),0.0,1.0);
#ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm;
finalColor += currentColor * lambertTerm;
#else
finalColor += vec4((Color*lambertTerm),0.0) ;
#endif
......@@ -39,24 +39,5 @@ void main()
vec3 R = reflect(-L, N);
float specular = pow( max(dot(R, E), 0.0), shininess );
finalColor += materialSpecular * specular;
#else
float lambertTerm = clamp(dot(N,L),0.0,1.0);
if (gl_FrontFacing)
{
#ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm;
#else
finalColor += vec4((Color*lambertTerm),0.0) ;
#endif
vec3 E = normalize(EyeVector);
vec3 R = reflect(-L, N);
float specular = pow( max(dot(R, E), 0.0), shininess );
finalColor += materialSpecular * specular;
}
else
{
finalColor = backColor;
}
#endif
FRAG_OUT=finalColor;
}
......@@ -46,6 +46,7 @@ protected:
bool m_with_color;
// flag color per vertex or not
bool m_with_eyepos;
//bool m_doubleSided;
// shader sources OGL3
static std::string vertexShaderText;
......@@ -61,6 +62,7 @@ protected:
CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_eyePos;
CGoGNGLuint m_unif_backColor;
CGoGNGLuint m_unif_doubleSided;
//values
Geom::Vec4f m_ambiant;
......@@ -70,6 +72,7 @@ protected:
Geom::Vec3f m_lightPos;
Geom::Vec3f m_eyePos;
Geom::Vec4f m_backColor;
int m_doubleSided;
VBO* m_vboPos;
VBO* m_vboNormal;
......@@ -86,7 +89,9 @@ protected:
void restoreUniformsAttribs();
public:
ShaderPhong(bool withClipping = false ,bool doubleSided = false, bool withEyePosition=false);
ShaderPhong(bool withClipping = false, bool withEyePosition=false);
void setDoubleSided(bool doubleSided);
// inviduals parameter setting functions
void setAmbiant(const Geom::Vec4f& ambiant);
......
......@@ -10,7 +10,7 @@ uniform vec4 materialSpecular;
uniform vec4 materialAmbient;
uniform float shininess;
uniform vec4 backColor;
uniform bool doubleSided;
uniform vec4 planeClip;
VARYING_FRAG vec3 posClip;
......@@ -26,19 +26,19 @@ void main()
//float lambertTerm = clamp(dot(N,L),0.0,1.0);
vec4 finalColor = materialAmbient;
vec4 currentColor = materialDiffuse;
#ifdef DOUBLE_SIDED
float lambertTerm;
vec4 diffuseColor = materialDiffuse;
if (!gl_FrontFacing)
{
if (!doubleSided)
discard;
N *= -1.0;
lambertTerm = clamp(dot(N,L),0.0,1.0);
currentColor = backColor;
}
else
lambertTerm = clamp(dot(N,L),0.0,1.0);
float lambertTerm = clamp(dot(N,L),0.0,1.0);
#ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm;
finalColor += currentColor * lambertTerm;
#else
finalColor += vec4((Color*lambertTerm),0.0) ;
#endif
......@@ -46,24 +46,6 @@ void main()
vec3 R = reflect(-L, N);
float specular = pow( max(dot(R, E), 0.0), shininess );
finalColor += materialSpecular * specular;
#else
float lambertTerm = clamp(dot(N,L),0.0,1.0);
if (gl_FrontFacing)
{
#ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm;
#else
finalColor += vec4((Color*lambertTerm),0.0) ;
#endif
vec3 E = normalize(EyeVector);
vec3 R = reflect(-L, N);
float specular = pow( max(dot(R, E), 0.0), shininess );
finalColor += materialSpecular * specular;
}
else
{
finalColor = backColor;
}
#endif
FRAG_OUT=finalColor;
}
......@@ -11,6 +11,7 @@ uniform vec4 materialSpecular;
uniform vec4 materialAmbient;
uniform float shininess;
uniform vec4 backColor;
uniform bool doubleSided;
FRAG_OUT_DEF;
......@@ -23,36 +24,21 @@ void main()
vec3 L = normalize (LightDir);
vec4 finalColor = materialAmbient;
float lambertTerm = clamp(dot(N,L),0.0,1.0);
vec4 currentColor = materialDiffuse;
#ifdef DOUBLE_SIDED
float lambertTerm;
vec4 diffuseColor = materialDiffuse;
if (!gl_FrontFacing)
{
N *= -1.0;
lambertTerm = clamp(dot(N,L),0.0,1.0);
if (!doubleSided)
discard;
currentColor = backColor;
}
else
lambertTerm = clamp(dot(N,L),0.0,1.0);
#ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm;
finalColor += currentColor * lambertTerm;
#else
finalColor += vec4((Color*lambertTerm),0.0) ;
#endif
#else
float lambertTerm = clamp(dot(N,L),0.0,1.0);
if (gl_FrontFacing)
{
#ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm;
#else
finalColor += vec4((Color*lambertTerm),0.0) ;
#endif
}
else
{
finalColor = backColor;
}
#endif
FRAG_OUT=finalColor;
}
......@@ -46,7 +46,6 @@ protected:
bool m_with_color;
// flag color per vertex or not
bool m_with_eyepos;
// shader sources OGL3
static std::string vertexShaderText;
static std::string fragmentShaderText;
......@@ -58,12 +57,14 @@ protected:
CGoGNGLuint m_unif_diffuse;
CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_backColor;
CGoGNGLuint m_unif_doubleSided;
//values
Geom::Vec4f m_ambiant;
Geom::Vec4f m_diffuse;
Geom::Vec3f m_lightPos;
Geom::Vec4f m_backColor;
int m_doubleSided;
VBO* m_vboPos;
VBO* m_vboColor;
......@@ -82,6 +83,8 @@ protected:
public:
ShaderSimpleFlat(bool withClipping = false, bool doubleSided = false);
void setDoubleSided(bool doubleSided);
// inviduals parameter setting functions
void setAmbiant(const Geom::Vec4f& ambiant);
......
......@@ -11,6 +11,7 @@ uniform vec4 materialSpecular;
uniform vec4 materialAmbient;
uniform float shininess;
uniform vec4 backColor;
uniform bool doubleSided;
FRAG_OUT_DEF;
......@@ -28,37 +29,21 @@ void main()
vec3 L = normalize (LightDir);
vec4 finalColor = materialAmbient;
vec4 finalColor = materialAmbient;
#ifdef DOUBLE_SIDED
float lambertTerm;
vec4 diffuseColor = materialDiffuse;
if (!gl_FrontFacing)
{
if (!doubleSided)
discard;
N *= -1.0;
lambertTerm = clamp(dot(N,L),0.0,1.0);
}
else
lambertTerm = clamp(dot(N,L),0.0,1.0);
float lambertTerm = clamp(dot(N,L),0.0,1.0);
#ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm;
#else
finalColor += vec4((Color*lambertTerm),0.0) ;
#endif
#else
float lambertTerm = clamp(dot(N,L),0.0,1.0);
if (gl_FrontFacing)
{
#ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm;
#else
finalColor += vec4((Color*lambertTerm),0.0) ;
#endif
}
else
{
finalColor = backColor;
}
#endif
FRAG_OUT=finalColor;
}
......@@ -36,6 +36,10 @@ void VBO::updateData(std::vector<T>& data)
CGoGNerr << "Error locked VBO" << CGoGNendl;
return;
}
if (data.empty())
return;
m_data_size = sizeof(T) / sizeof(float);
m_nbElts = uint32(data.size());
......
......@@ -36,7 +36,8 @@ namespace Utils
#include "shaderFlat.geom"
ShaderFlat::ShaderFlat()
ShaderFlat::ShaderFlat():
m_doubleSided(1)
{
m_nameVS = "ShaderFlat_vs";
m_nameFS = "ShaderFlat_fs";
......@@ -67,6 +68,16 @@ ShaderFlat::ShaderFlat()
setParams(m_explode, m_ambiant, m_diffuse, m_diffuseBack ,m_light_pos);
}
void ShaderFlat::setDoubleSided(bool doubleSided)
{
m_doubleSided = doubleSided;
bind();
glUniform1i(*m_unif_doubleSided, m_doubleSided);
unbind();
}
void ShaderFlat::getLocations()
{
*m_unif_explode = glGetUniformLocation(program_handler(), "explode");
......@@ -74,6 +85,7 @@ void ShaderFlat::getLocations()
*m_unif_diffuse = glGetUniformLocation(program_handler(), "diffuse");
*m_unif_diffuseback = glGetUniformLocation(program_handler(), "diffuseBack");
*m_unif_lightPos = glGetUniformLocation(program_handler(), "lightPosition");
*m_unif_doubleSided = glGetUniformLocation(this->program_handler(), "doubleSided");
}
unsigned int ShaderFlat::setAttributePosition(VBO* vbo)
......@@ -127,7 +139,7 @@ void ShaderFlat::setDiffuse(const Geom::Vec4f& diffuse)
unbind();
}
void ShaderFlat::setDiffuseBack(const Geom::Vec4f& diffuseb)
void ShaderFlat::setBackColor(const Geom::Vec4f& diffuseb)
{
m_diffuseBack = diffuseb;
bind();
......@@ -150,6 +162,7 @@ void ShaderFlat::restoreUniformsAttribs()
*m_unif_diffuse = glGetUniformLocation(program_handler(),"diffuse");
*m_unif_diffuseback = glGetUniformLocation(program_handler(),"diffuseBack");
*m_unif_lightPos = glGetUniformLocation(program_handler(),"lightPosition");
*m_unif_doubleSided = glGetUniformLocation(this->program_handler(), "doubleSided");
bind();
......@@ -158,6 +171,7 @@ void ShaderFlat::restoreUniformsAttribs()
glUniform4fv(*m_unif_diffuse, 1, m_diffuse.data());
glUniform4fv(*m_unif_diffuseback, 1, m_diffuseBack.data());
glUniform3fv(*m_unif_lightPos, 1, m_light_pos.data());
glUniform1i(*m_unif_doubleSided, m_doubleSided);
bindVA_VBO("VertexPosition", m_vboPos);
......
......@@ -37,9 +37,10 @@ namespace Utils
#include "shaderPhongClip.frag"
ShaderPhong::ShaderPhong(bool withClipping, bool doubleSided, bool withEyePosition):
ShaderPhong::ShaderPhong(bool withClipping, bool withEyePosition) :
m_with_color(false),
m_with_eyepos(withEyePosition),
m_doubleSided(1),
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_specular(Geom::Vec4f(1.0f,1.0f,1.0f,0.0f)),
......@@ -62,8 +63,8 @@ ShaderPhong::ShaderPhong(bool withClipping, bool doubleSided, bool withEyePositi
glxvert.append("#define WITH_EYEPOSITION");
glxvert.append(vertexShaderClipText);
// Use double sided lighting if set
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
//if (doubleSided)
// glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderClipText);
}
else
......@@ -74,8 +75,8 @@ ShaderPhong::ShaderPhong(bool withClipping, bool doubleSided, bool withEyePositi
glxvert.append("#define WITH_EYEPOSITION");
glxvert.append(vertexShaderText);
// Use double sided lighting if set
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
//if (doubleSided)
// glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderText);
}
......@@ -86,6 +87,7 @@ ShaderPhong::ShaderPhong(bool withClipping, bool doubleSided, bool withEyePositi
sendParams();
}
void ShaderPhong::getLocations()
{
bind();
......@@ -98,6 +100,7 @@ void ShaderPhong::getLocations()
*m_unif_eyePos = glGetUniformLocation(this->program_handler(), "eyePosition");
*m_unif_backColor = glGetUniformLocation(this->program_handler(), "backColor");
*m_unif_planeClip = glGetUniformLocation(this->program_handler(), "planeClip");
*m_unif_doubleSided = glGetUniformLocation(this->program_handler(), "doubleSided");
unbind();
}
......@@ -110,6 +113,7 @@ void ShaderPhong::sendParams()
glUniform4fv(*m_unif_specular, 1, m_specular.data());
glUniform1f(*m_unif_shininess, m_shininess);
glUniform3fv(*m_unif_lightPos, 1, m_lightPos.data());
glUniform1i(*m_unif_doubleSided, m_doubleSided);
if (m_with_eyepos)
glUniform3fv(*m_unif_eyePos, 1, m_eyePos.data());
glUniform4fv(*m_unif_backColor, 1, m_backColor.data());
......@@ -118,6 +122,16 @@ void ShaderPhong::sendParams()
unbind();
}
void ShaderPhong::setDoubleSided(bool doubleSided)
{
m_doubleSided = doubleSided;
bind();
glUniform1i(*m_unif_doubleSided, m_doubleSided);
unbind();
}
void ShaderPhong::setAmbiant(const Geom::Vec4f& ambiant)
{
bind();
......
......@@ -40,6 +40,7 @@ namespace Utils
ShaderSimpleFlat::ShaderSimpleFlat(bool withClipping, bool doubleSided):
m_with_color(false),
m_doubleSided(doubleSided),
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_lightPos(Geom::Vec3f(10.0f,10.0f,1000.0f)),
......@@ -56,8 +57,6 @@ ShaderSimpleFlat::ShaderSimpleFlat(bool withClipping, bool doubleSided):
m_nameVS = "ShaderSimpleFlatClip_vs";
m_nameFS = "ShaderSimpleFlatClip_fs";
glxvert.append(vertexShaderClipText);
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderClipText);
}
else
......@@ -67,8 +66,6 @@ ShaderSimpleFlat::ShaderSimpleFlat(bool withClipping, bool doubleSided):
// get choose GL defines (2 or 3)
// ans compile shaders
glxvert.append(vertexShaderText);
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderText);
}
......@@ -78,6 +75,16 @@ ShaderSimpleFlat::ShaderSimpleFlat(bool withClipping, bool doubleSided):
sendParams();
}
void ShaderSimpleFlat::setDoubleSided(bool doubleSided)
{
m_doubleSided = doubleSided;
bind();
glUniform1i(*m_unif_doubleSided, m_doubleSided);
unbind();
}
void ShaderSimpleFlat::getLocations()
{
bind();
......@@ -86,6 +93,7 @@ void ShaderSimpleFlat::getLocations()
*m_unif_lightPos = glGetUniformLocation(this->program_handler(), "lightPosition");
*m_unif_backColor = glGetUniformLocation(this->program_handler(), "backColor");
*m_unif_planeClip = glGetUniformLocation(this->program_handler(), "planeClip");
*m_unif_doubleSided = glGetUniformLocation(this->program_handler(), "doubleSided");
unbind();
}
......@@ -96,6 +104,7 @@ void ShaderSimpleFlat::sendParams()
glUniform4fv(*m_unif_diffuse, 1, m_diffuse.data());
glUniform3fv(*m_unif_lightPos, 1, m_lightPos.data());
glUniform4fv(*m_unif_backColor, 1, m_backColor.data());
glUniform1i(*m_unif_doubleSided, m_doubleSided);
if (*m_unif_planeClip > 0)
glUniform4fv(*m_unif_planeClip, 1, m_planeClip.data());
unbind();
......
......@@ -239,6 +239,11 @@ LIST(APPEND CGoGN_EXT_LIBS
${SUITESPARSE_LIBRARIES}
)
IF (APPLE)
FIND_LIBRARY(ACCELERATE_LIBRARY Accelerate)
LIST(APPEND CGoGN_EXT_LIBS ${ACCELERATE_LIBRARY})
ENDIF()
IF(NOT WIN32)
LIST(APPEND CGoGN_EXT_LIBS pthread) #for c++11 thread
ENDIF()
......
......@@ -11,7 +11,11 @@ namespace CGoGN
namespace SCHNApps
{
/**
* @brief Plugin that manage the computation of differential properties
* - Normals
* - Curvatures
*/
class Surface_DifferentialProperties_Plugin : public PluginProcessing
{
Q_OBJECT
......@@ -43,11 +47,32 @@ private slots:
void schnappsClosing();
public slots:
/**
* @brief [PYTHON] compute the normals of a mesh
* @param mapName name of the 2d map (mesh)
* @param positionAttributeName name of position attribute used for computation
* @param normalAttributeName name of result attribute
* @param autoUpdate automatically update the normal attribute when position attribute change.
*/
void computeNormal(const QString& mapName,
const QString& positionAttributeName = "position",
const QString& normalAttributeName = "normal",
bool autoUpdate = true);
/**
* @brief [PYTHON] compute curvatures of a mesh
* @param mapName name of 2d map
* @param positionAttributeName name of input position attribute
* @param normalAttributeName name of input normal attributes
* @param KmaxAttributeName ?? result attribute name
* @param kmaxAttributeName ?? result attribute name
* @param KminAttributeName ?? result attribute name
* @param kminAttributeName ?? result attribute name
* @param KnormalAttributeName ?? result attribute aname
* @param compute_kmean compute the mean curvature
* @param compute_kgaussian compute the gaussian curvature
* @param autoUpdate automatically update the output attributes when input attribute change.
*/
void computeCurvature(
const QString& mapName,
const QString& positionAttributeName = "position",
......
......@@ -36,6 +36,15 @@ private slots:
void schnappsClosing();
public slots:
/**
* @brief compute distance between 2 maps