Commit 7fe64ae9 authored by Sylvain Thery's avatar Sylvain Thery

SCHNApps backface render + view scaling

parent 517a6df8
......@@ -6,8 +6,15 @@ VARYING_FRAG float lambertTerm;
FRAG_OUT_DEF;
void main()
{
#ifdef DOUBLE_SIDED
if (gl_FrontFacing)
FRAG_OUT = ambient + lambertTerm*diffuse;
else
FRAG_OUT = ambient + lambertTerm*diffuseBack;
FRAG_OUT = ambient - lambertTerm*diffuse;
#else
if (gl_FrontFacing)
FRAG_OUT = ambient + lambertTerm*diffuse;
else
FRAG_OUT = ambient - lambertTerm*diffuseBack;
#endif
}
......@@ -18,7 +18,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++)
......
......@@ -51,6 +51,7 @@ protected:
CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_explode;
bool m_doubleSided;
float m_explode;
Geom::Vec4f m_ambiant;
Geom::Vec4f m_diffuse;
......@@ -66,6 +67,8 @@ protected:
public:
ShaderFlat();
void setDoubleSided(bool doubleSided);
void setExplode(float explode);
void setAmbiant(const Geom::Vec4f& ambiant);
......
......@@ -40,9 +40,9 @@ void main()
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)
{
float lambertTerm = clamp(dot(N,L),0.0,1.0);
#ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm;
#else
......@@ -55,7 +55,16 @@ void main()
}
else
{
finalColor = backColor;
float lambertTerm = clamp(-dot(N,L),0.0,1.0);
#ifndef WITH_COLOR
finalColor += backColor * 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;
}
#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;
......@@ -88,6 +89,8 @@ protected:
public:
ShaderPhong(bool withClipping = false ,bool doubleSided = false, bool withEyePosition=false);
void setDoubleSided(bool doubleSided);
// inviduals parameter setting functions
void setAmbiant(const Geom::Vec4f& ambiant);
......
......@@ -28,10 +28,7 @@ void main()
float lambertTerm;
vec4 diffuseColor = materialDiffuse;
if (!gl_FrontFacing)
{
N *= -1.0;
lambertTerm = clamp(dot(N,L),0.0,1.0);
}
lambertTerm = clamp(-dot(N,L),0.0,1.0);
else
lambertTerm = clamp(dot(N,L),0.0,1.0);
#ifndef WITH_COLOR
......@@ -40,9 +37,10 @@ void main()
finalColor += vec4((Color*lambertTerm),0.0) ;
#endif
#else
float lambertTerm = clamp(dot(N,L),0.0,1.0);
if (gl_FrontFacing)
{
float lambertTerm = clamp(dot(N,L),0.0,1.0);
#ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm;
#else
......@@ -51,7 +49,12 @@ void main()
}
else
{
finalColor = backColor;
float lambertTerm = clamp(-dot(N,L),0.0,1.0);
#ifndef WITH_COLOR
finalColor += backColor * lambertTerm;
#else
finalColor += vec4((Color*lambertTerm),0.0) ;
#endif
}
#endif
FRAG_OUT=finalColor;
......
......@@ -46,7 +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;
static std::string fragmentShaderText;
......@@ -82,6 +82,8 @@ protected:
public:
ShaderSimpleFlat(bool withClipping = false, bool doubleSided = false);
void setDoubleSided(bool doubleSided);
// inviduals parameter setting functions
void setAmbiant(const Geom::Vec4f& ambiant);
......
......@@ -36,7 +36,8 @@ namespace Utils
#include "shaderFlat.geom"
ShaderFlat::ShaderFlat()
ShaderFlat::ShaderFlat():
m_doubleSided(false)
{
m_nameVS = "ShaderFlat_vs";
m_nameFS = "ShaderFlat_fs";
......@@ -67,6 +68,31 @@ ShaderFlat::ShaderFlat()
setParams(m_explode, m_ambiant, m_diffuse, m_diffuseBack ,m_light_pos);
}
void ShaderFlat::setDoubleSided(bool doubleSided)
{
if (doubleSided == m_doubleSided)
return;
std::string glxvert(GLSLShader::defines_gl());
glxvert.append(vertexShaderText);
std::string glxgeom = GLSLShader::defines_Geom("triangles", "triangle_strip", 3);
glxgeom.append(geometryShaderText);
std::string glxfrag(GLSLShader::defines_gl());
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderText);
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_TRIANGLES, GL_TRIANGLE_STRIP, 3);
bind();
getLocations();
unbind();
setParams(m_explode, m_ambiant, m_diffuse, m_diffuseBack, m_light_pos);
}
void ShaderFlat::getLocations()
{
*m_unif_explode = glGetUniformLocation(program_handler(), "explode");
......
......@@ -37,9 +37,10 @@ namespace Utils
#include "shaderPhongClip.frag"
ShaderPhong::ShaderPhong(bool withClipping, bool doubleSided, bool withEyePosition):
ShaderPhong::ShaderPhong(bool withClipping, bool doubleSided, bool withEyePosition) :
m_with_color(false),
m_with_eyepos(withEyePosition),
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_specular(Geom::Vec4f(1.0f,1.0f,1.0f,0.0f)),
......@@ -86,6 +87,47 @@ ShaderPhong::ShaderPhong(bool withClipping, bool doubleSided, bool withEyePositi
sendParams();
}
void ShaderPhong::setDoubleSided(bool doubleSided)
{
if (doubleSided == m_doubleSided)
return;
m_doubleSided = doubleSided;
std::string glxvert(GLSLShader::defines_gl());
std::string glxfrag(GLSLShader::defines_gl());
if (m_nameVS == "ShaderPhongClip_vs")
{
if (m_with_eyepos)
glxvert.append("#define WITH_EYEPOSITION");
glxvert.append(vertexShaderClipText);
// Use double sided lighting if set
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderClipText);
}
else
{
if (m_with_eyepos)
glxvert.append("#define WITH_EYEPOSITION");
glxvert.append(vertexShaderText);
// Use double sided lighting if set
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderText);
}
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str());
// and get and fill uniforms
getLocations();
sendParams();
}
void ShaderPhong::getLocations()
{
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)),
......@@ -78,6 +79,36 @@ ShaderSimpleFlat::ShaderSimpleFlat(bool withClipping, bool doubleSided):
sendParams();
}
void ShaderSimpleFlat::setDoubleSided(bool doubleSided)
{
if (doubleSided == m_doubleSided)
return;
std::string glxvert(GLSLShader::defines_gl());
std::string glxfrag(GLSLShader::defines_gl());
if (m_nameVS == "ShaderSimpleFlatClip_vs")
{
glxvert.append(vertexShaderClipText);
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderClipText);
}
else
{
glxvert.append(vertexShaderText);
if (doubleSided)
glxfrag.append("#define DOUBLE_SIDED\n");
glxfrag.append(fragmentShaderText);
}
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str());
// and get and fill uniforms
getLocations();
sendParams();
}
void ShaderSimpleFlat::getLocations()
{
bind();
......
......@@ -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()
......
......@@ -14,13 +14,6 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Position :</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="combo_positionVBO">
<property name="sizePolicy">
......@@ -36,6 +29,20 @@
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Color :</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Position :</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
......@@ -58,13 +65,6 @@
</item>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Color :</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="combo_colorVBO">
<property name="sizePolicy">
......@@ -83,17 +83,17 @@
<item row="3" column="0" colspan="2">
<widget class="Line" name="line"/>
</item>
<item row="4" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item row="6" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QCheckBox" name="check_renderVertices">
<widget class="QCheckBox" name="check_renderEdges">
<property name="text">
<string>render vertices</string>
<string>render edges</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
......@@ -106,7 +106,7 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="vcolorButton">
<widget class="QPushButton" name="scolorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
......@@ -126,27 +126,17 @@
</item>
</layout>
</item>
<item row="5" column="0" colspan="2">
<widget class="QSlider" name="slider_verticesScaleFactor">
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item row="4" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QCheckBox" name="check_renderEdges">
<widget class="QCheckBox" name="check_renderVertices">
<property name="text">
<string>render edges</string>
<string>render vertices</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
......@@ -159,7 +149,7 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="scolorButton">
<widget class="QPushButton" name="vcolorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
......@@ -179,6 +169,39 @@
</item>
</layout>
</item>
<item row="5" column="0" colspan="2">
<widget class="QSlider" name="slider_verticesScaleFactor">
<property name="value">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="13" column="0">
<widget class="QRadioButton" name="radio_flatShading">
<property name="text">
<string>Flat</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">group_faceShading</string>
</attribute>
</widget>
</item>
<item row="13" column="1">
<widget class="QRadioButton" name="radio_phongShading">
<property name="text">
<string>Phong</string>
</property>
<attribute name="buttonGroup">
<string notr="true">group_faceShading</string>
</attribute>
</widget>
</item>
<item row="7" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
......@@ -343,37 +366,7 @@
</item>
</layout>
</item>
<item row="8" column="0">
<widget class="QRadioButton" name="radio_flatShading">
<property name="text">
<string>Flat</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">group_faceShading</string>
</attribute>
</widget>
</item>
<item row="8" column="1">
<widget class="QRadioButton" name="radio_phongShading">
<property name="text">
<string>Phong</string>
</property>
<attribute name="buttonGroup">
<string notr="true">group_faceShading</string>
</attribute>
</widget>
</item>
<item row="9" column="0" colspan="2">
<widget class="QCheckBox" name="check_renderBoundary">
<property name="text">
<string>render boundary</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<item row="16" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -386,6 +379,54 @@
</property>
</spacer>
</item>
<item row="14" column="0" colspan="2">
<widget class="QCheckBox" name="check_renderBoundary">
<property name="text">
<string>render boundary</string>
</property>
</widget>
</item>
<item row="15" column="0" colspan="2">
<widget class="QCheckBox" name="check_doubleSided">
<property name="text">
<string>double sided</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string> BackFace </string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="bfcolorButton">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
......
......@@ -37,7 +37,8 @@ struct MapParameters
faceStyle(FLAT),
diffuseColor(0.85f,0.25f,0.19f,0.0f),
simpleColor(0.0f,0.0f,0.0f,0.0f),
vertexColor(0.0f,0.0f,1.0f,0.0f)
vertexColor(0.0f,0.0f,1.0f,0.0f),
backColor(0.85f, 0.25f, 0.19f, 0.0f)
{}
Utils::VBO* positionVBO;
......@@ -54,6 +55,7 @@ struct MapParameters
Geom::Vec4f diffuseColor;
Geom::Vec4f simpleColor;
Geom::Vec4f vertexColor;
Geom::Vec4f backColor;
};
class Surface_Render_Plugin : public PluginInteraction
......@@ -118,6 +120,8 @@ public slots:
void changeFaceColor(const QString& view, const QString& map, float r, float g, float b);
void changeEdgeColor(const QString& view, const QString& map, float r, float g, float b);
void changeVertexColor(const QString& view, const QString& map, float r, float g, float b);
void changeBackColor(const QString& view, const QString& map, float r, float g, float b);
protected:
Surface_Render_DockTab* m_dockTab;
......
......@@ -32,6 +32,7 @@ private:
QColor m_diffuseColor;
QColor m_simpleColor;
QColor m_vertexColor;
QColor m_backColor;
int m_currentColorDial;
bool b_updatingUI;
......@@ -50,6 +51,7 @@ private slots:
void diffuseColorClicked();
void simpleColorClicked();
void vertexColorClicked();
void backColorClicked();
void colorSelected(const QColor& col);
private:
......
......@@ -18,13 +18,13 @@ bool Surface_Render_Plugin::enable()
m_schnapps->addPluginDockTab(this, m_dockTab, "Surface_Render");
m_flatShader = new CGoGN::Utils::ShaderFlat();
m_flatShader->setAmbiant(CGoGN::Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f));
//m_flatShader->setAmbiant(CGoGN::Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f));
m_flatShader->setExplode(1.0f);
m_phongShader = new CGoGN::Utils::ShaderPhong();
m_phongShader->setAmbiant(CGoGN::Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f));
m_phongShader->setSpecular(CGoGN::Geom::Vec4f(0.9f, 0.9f, 0.9f, 1.0f));
m_phongShader->setShininess(80.0f);
//m_phongShader->setAmbiant(CGoGN::Geom::Vec4f(0.2f, 0.2f, 0.2f, 0.1f));
//m_phongShader->setSpecular(CGoGN::Geom::Vec4f(0.9f, 0.9f, 0.9f, 1.0f));
//m_phongShader->setShininess(80.0f);
m_colorPerVertexShader = new CGoGN::Utils::ShaderColorPerVertex();
......@@ -91,6 +91,7 @@ void Surface_Render_Plugin::drawMap(View* view, MapHandlerGen* map)
}
else
{
m_flatShader->setDiffuseBack(p.backColor);
m_flatShader->setAttributePosition(p.positionVBO);
m_flatShader->setDiffuse(p.diffuseColor);
map->draw(m_flatShader, CGoGN::Algo::Render::GL2::TRIANGLES);
......@@ -99,6 +100,7 @@ void Surface_Render_Plugin::drawMap(View* view, MapHandlerGen* map)
case MapParameters::PHONG :
if(p.normalVBO != NULL)
{
m_phongShader->setBackColor(p.backColor);
m_phongShader->setAttributePosition(p.positionVBO);
m_phongShader->setAttributeNormal(p.normalVBO);
m_phongShader->setDiffuse(p.diffuseColor);
......@@ -431,6 +433,24 @@ void Surface_Render_Plugin::changeVertexColor(const QString& view, const QString
}
void Surface_Render_Plugin::changeBackColor(const QString& view, const QString& map, float r, float g, float b)
{
DEBUG_SLOT();
View* v = m_schnapps->getView(view);
MapHandlerGen* m = m_schnapps->getMap(map);
if (v && m)
{
h_viewParameterSet[v][m].backColor = Geom::Vec4f(r, g, b, 0);
if (v->isSelectedView())
{
if (v->isLinkedToMap(m)) v->updateGL();
if (m->isSelectedMap()) m_dockTab->updateMapParameters();
}
}
}
void Surface_Render_Plugin::schnappsClosing()
{
......
......@@ -33,6 +33,7 @@ Surface_Render_DockTab::Surface_Render_DockTab(SCHNApps* s, Surface_Render_Plugi
connect(dcolorButton,SIGNAL(clicked()),this,SLOT(diffuseColorClicked()));
connect(scolorButton,SIGNAL(clicked()),this,SLOT(simpleColorClicked()));
connect(vcolorButton,SIGNAL(clicked()),this,SLOT(vertexColorClicked()));
connect(bfcolorButton, SIGNAL(clicked()), this, SLOT(backColorClicked()));
connect(m_colorDial,SIGNAL(colorSelected(const QColor&)),this,SLOT(colorSelected(const QColor&)));
}
......@@ -180,8 +181,6 @@ void Surface_Render_DockTab::renderBoundaryChanged(bool b)
void Surface_Render_DockTab::diffuseColorClicked()
{
m_colorDial->show();
......@@ -203,6 +202,13 @@ void Surface_Render_DockTab::vertexColorClicked()
m_currentColorDial = 3;
}
void Surface_Render_DockTab::backColorClicked()
{
m_colorDial->show();
m_colorDial->setCurrentColor(m_vertexColor);
m_currentColorDial = 4;
}
void Surface_Render_DockTab::colorSelected(const QColor& col)
{
......@@ -256,6 +262,23 @@ void Surface_Render_DockTab::colorSelected(const QColor& col)
m_plugin->pythonRecording("changeVertexColor", "", view->getName(), map->getName(), rgbCol[0], rgbCol[1], rgbCol[2]);
}
}
if (m_currentColorDial == 4)
{
m_backColor = col;
bfcolorButton->setStyleSheet("QPushButton { background-color:" + col.name() + "}");
Geom::Vec4f rgbCol(1.0 / 255.0*m_backColor.red(), 1.0 / 255.0*m_backColor.green(), 1.0 / 255.0*m_backColor.blue(), 0.0f);
View* view = m_schnapps->getSelectedView();
MapHandlerGen* map = m_schnapps->getSelectedMap();
if (view && map)
{
m_plugin->h_viewParameterSet[view][map].backColor = rgbCol;
view->updateGL();
m_plugin->pythonRecording("changeBackColor", "", view->getName(), map->getName(), rgbCol[0], rgbCol[1], rgbCol[2]);
}
}
}