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; ...@@ -6,8 +6,15 @@ VARYING_FRAG float lambertTerm;
FRAG_OUT_DEF; FRAG_OUT_DEF;
void main() void main()
{ {
#ifdef DOUBLE_SIDED
if (gl_FrontFacing) if (gl_FrontFacing)
FRAG_OUT = ambient + lambertTerm*diffuse; FRAG_OUT = ambient + lambertTerm*diffuse;
else 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) ...@@ -18,7 +18,7 @@ void main(void)
center /= 3.0; center /= 3.0;
vec4 newPos = ModelViewMatrix * vec4(center,1.0); vec4 newPos = ModelViewMatrix * vec4(center,1.0);
vec3 L = normalize (lightPosition - newPos.xyz); vec3 L = normalize (lightPosition - newPos.xyz);
lambertTerm = clamp(dot(N,L),0.0,1.0); lambertTerm = dot(N,L);
int i; int i;
for(i=0; i< NBVERTS_IN; i++) for(i=0; i< NBVERTS_IN; i++)
......
...@@ -51,6 +51,7 @@ protected: ...@@ -51,6 +51,7 @@ protected:
CGoGNGLuint m_unif_lightPos; CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_explode; CGoGNGLuint m_unif_explode;
bool m_doubleSided;
float m_explode; float m_explode;
Geom::Vec4f m_ambiant; Geom::Vec4f m_ambiant;
Geom::Vec4f m_diffuse; Geom::Vec4f m_diffuse;
...@@ -66,6 +67,8 @@ protected: ...@@ -66,6 +67,8 @@ protected:
public: public:
ShaderFlat(); ShaderFlat();
void setDoubleSided(bool doubleSided);
void setExplode(float explode); void setExplode(float explode);
void setAmbiant(const Geom::Vec4f& ambiant); void setAmbiant(const Geom::Vec4f& ambiant);
......
...@@ -40,9 +40,9 @@ void main() ...@@ -40,9 +40,9 @@ void main()
float specular = pow( max(dot(R, E), 0.0), shininess ); float specular = pow( max(dot(R, E), 0.0), shininess );
finalColor += materialSpecular * specular; finalColor += materialSpecular * specular;
#else #else
float lambertTerm = clamp(dot(N,L),0.0,1.0);
if (gl_FrontFacing) if (gl_FrontFacing)
{ {
float lambertTerm = clamp(dot(N,L),0.0,1.0);
#ifndef WITH_COLOR #ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm; finalColor += materialDiffuse * lambertTerm;
#else #else
...@@ -55,7 +55,16 @@ void main() ...@@ -55,7 +55,16 @@ void main()
} }
else 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 #endif
FRAG_OUT=finalColor; FRAG_OUT=finalColor;
......
...@@ -46,6 +46,7 @@ protected: ...@@ -46,6 +46,7 @@ protected:
bool m_with_color; bool m_with_color;
// flag color per vertex or not // flag color per vertex or not
bool m_with_eyepos; bool m_with_eyepos;
bool m_doubleSided;
// shader sources OGL3 // shader sources OGL3
static std::string vertexShaderText; static std::string vertexShaderText;
...@@ -88,6 +89,8 @@ protected: ...@@ -88,6 +89,8 @@ protected:
public: public:
ShaderPhong(bool withClipping = false ,bool doubleSided = false, bool withEyePosition=false); ShaderPhong(bool withClipping = false ,bool doubleSided = false, bool withEyePosition=false);
void setDoubleSided(bool doubleSided);
// inviduals parameter setting functions // inviduals parameter setting functions
void setAmbiant(const Geom::Vec4f& ambiant); void setAmbiant(const Geom::Vec4f& ambiant);
......
...@@ -28,10 +28,7 @@ void main() ...@@ -28,10 +28,7 @@ void main()
float lambertTerm; float lambertTerm;
vec4 diffuseColor = materialDiffuse; vec4 diffuseColor = materialDiffuse;
if (!gl_FrontFacing) if (!gl_FrontFacing)
{ lambertTerm = clamp(-dot(N,L),0.0,1.0);
N *= -1.0;
lambertTerm = clamp(dot(N,L),0.0,1.0);
}
else else
lambertTerm = clamp(dot(N,L),0.0,1.0); lambertTerm = clamp(dot(N,L),0.0,1.0);
#ifndef WITH_COLOR #ifndef WITH_COLOR
...@@ -40,9 +37,10 @@ void main() ...@@ -40,9 +37,10 @@ void main()
finalColor += vec4((Color*lambertTerm),0.0) ; finalColor += vec4((Color*lambertTerm),0.0) ;
#endif #endif
#else #else
float lambertTerm = clamp(dot(N,L),0.0,1.0);
if (gl_FrontFacing) if (gl_FrontFacing)
{ {
float lambertTerm = clamp(dot(N,L),0.0,1.0);
#ifndef WITH_COLOR #ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm; finalColor += materialDiffuse * lambertTerm;
#else #else
...@@ -51,7 +49,12 @@ void main() ...@@ -51,7 +49,12 @@ void main()
} }
else 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 #endif
FRAG_OUT=finalColor; FRAG_OUT=finalColor;
......
...@@ -46,7 +46,7 @@ protected: ...@@ -46,7 +46,7 @@ protected:
bool m_with_color; bool m_with_color;
// flag color per vertex or not // flag color per vertex or not
bool m_with_eyepos; bool m_with_eyepos;
bool m_doubleSided;
// shader sources OGL3 // shader sources OGL3
static std::string vertexShaderText; static std::string vertexShaderText;
static std::string fragmentShaderText; static std::string fragmentShaderText;
...@@ -82,6 +82,8 @@ protected: ...@@ -82,6 +82,8 @@ protected:
public: public:
ShaderSimpleFlat(bool withClipping = false, bool doubleSided = false); ShaderSimpleFlat(bool withClipping = false, bool doubleSided = false);
void setDoubleSided(bool doubleSided);
// inviduals parameter setting functions // inviduals parameter setting functions
void setAmbiant(const Geom::Vec4f& ambiant); void setAmbiant(const Geom::Vec4f& ambiant);
......
...@@ -36,7 +36,8 @@ namespace Utils ...@@ -36,7 +36,8 @@ namespace Utils
#include "shaderFlat.geom" #include "shaderFlat.geom"
ShaderFlat::ShaderFlat() ShaderFlat::ShaderFlat():
m_doubleSided(false)
{ {
m_nameVS = "ShaderFlat_vs"; m_nameVS = "ShaderFlat_vs";
m_nameFS = "ShaderFlat_fs"; m_nameFS = "ShaderFlat_fs";
...@@ -67,6 +68,31 @@ ShaderFlat::ShaderFlat() ...@@ -67,6 +68,31 @@ ShaderFlat::ShaderFlat()
setParams(m_explode, m_ambiant, m_diffuse, m_diffuseBack ,m_light_pos); 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() void ShaderFlat::getLocations()
{ {
*m_unif_explode = glGetUniformLocation(program_handler(), "explode"); *m_unif_explode = glGetUniformLocation(program_handler(), "explode");
......
...@@ -37,9 +37,10 @@ namespace Utils ...@@ -37,9 +37,10 @@ namespace Utils
#include "shaderPhongClip.frag" #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_color(false),
m_with_eyepos(withEyePosition), m_with_eyepos(withEyePosition),
m_doubleSided(doubleSided),
m_ambiant(Geom::Vec4f(0.05f,0.05f,0.1f,0.0f)), 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_diffuse(Geom::Vec4f(0.1f,1.0f,0.1f,0.0f)),
m_specular(Geom::Vec4f(1.0f,1.0f,1.0f,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 ...@@ -86,6 +87,47 @@ ShaderPhong::ShaderPhong(bool withClipping, bool doubleSided, bool withEyePositi
sendParams(); 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() void ShaderPhong::getLocations()
{ {
bind(); bind();
......
...@@ -40,6 +40,7 @@ namespace Utils ...@@ -40,6 +40,7 @@ namespace Utils
ShaderSimpleFlat::ShaderSimpleFlat(bool withClipping, bool doubleSided): ShaderSimpleFlat::ShaderSimpleFlat(bool withClipping, bool doubleSided):
m_with_color(false), m_with_color(false),
m_doubleSided(doubleSided),
m_ambiant(Geom::Vec4f(0.05f,0.05f,0.1f,0.0f)), 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_diffuse(Geom::Vec4f(0.1f,1.0f,0.1f,0.0f)),
m_lightPos(Geom::Vec3f(10.0f,10.0f,1000.0f)), m_lightPos(Geom::Vec3f(10.0f,10.0f,1000.0f)),
...@@ -78,6 +79,36 @@ ShaderSimpleFlat::ShaderSimpleFlat(bool withClipping, bool doubleSided): ...@@ -78,6 +79,36 @@ ShaderSimpleFlat::ShaderSimpleFlat(bool withClipping, bool doubleSided):
sendParams(); 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() void ShaderSimpleFlat::getLocations()
{ {
bind(); bind();
......
...@@ -239,6 +239,11 @@ LIST(APPEND CGoGN_EXT_LIBS ...@@ -239,6 +239,11 @@ LIST(APPEND CGoGN_EXT_LIBS
${SUITESPARSE_LIBRARIES} ${SUITESPARSE_LIBRARIES}
) )
IF (APPLE)
FIND_LIBRARY(ACCELERATE_LIBRARY Accelerate)
LIST(APPEND CGoGN_EXT_LIBS ${ACCELERATE_LIBRARY})
ENDIF()
IF(NOT WIN32) IF(NOT WIN32)
LIST(APPEND CGoGN_EXT_LIBS pthread) #for c++11 thread LIST(APPEND CGoGN_EXT_LIBS pthread) #for c++11 thread
ENDIF() ENDIF()
......
...@@ -14,13 +14,6 @@ ...@@ -14,13 +14,6 @@
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <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"> <item row="0" column="1">
<widget class="QComboBox" name="combo_positionVBO"> <widget class="QComboBox" name="combo_positionVBO">
<property name="sizePolicy"> <property name="sizePolicy">
...@@ -36,6 +29,20 @@ ...@@ -36,6 +29,20 @@
</item> </item>
</widget> </widget>
</item> </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"> <item row="1" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
...@@ -58,13 +65,6 @@ ...@@ -58,13 +65,6 @@
</item> </item>
</widget> </widget>
</item> </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"> <item row="2" column="1">
<widget class="QComboBox" name="combo_colorVBO"> <widget class="QComboBox" name="combo_colorVBO">
<property name="sizePolicy"> <property name="sizePolicy">
...@@ -83,17 +83,17 @@ ...@@ -83,17 +83,17 @@
<item row="3" column="0" colspan="2"> <item row="3" column="0" colspan="2">
<widget class="Line" name="line"/> <widget class="Line" name="line"/>
</item> </item>
<item row="4" column="0" colspan="2"> <item row="6" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>
<widget class="QCheckBox" name="check_renderVertices"> <widget class="QCheckBox" name="check_renderEdges">
<property name="text"> <property name="text">
<string>render vertices</string> <string>render edges</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer_3">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
...@@ -106,7 +106,7 @@ ...@@ -106,7 +106,7 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="vcolorButton"> <widget class="QPushButton" name="scolorButton">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
...@@ -126,27 +126,17 @@ ...@@ -126,27 +126,17 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="5" column="0" colspan="2"> <item row="4" column="0" colspan="2">
<widget class="QSlider" name="slider_verticesScaleFactor"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<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> <item>
<widget class="QCheckBox" name="check_renderEdges"> <widget class="QCheckBox" name="check_renderVertices">
<property name="text"> <property name="text">
<string>render edges</string> <string>render vertices</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer_3"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
...@@ -159,7 +149,7 @@ ...@@ -159,7 +149,7 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="scolorButton"> <widget class="QPushButton" name="vcolorButton">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
...@@ -179,6 +169,39 @@ ...@@ -179,6 +169,39 @@
</item> </item>
</layout> </layout>
</item> </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"> <item row="7" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
...@@ -343,37 +366,7 @@ ...@@ -343,37 +366,7 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="8" column="0"> <item row="16" column="0" colspan="2">
<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">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
...@@ -386,6 +379,54 @@ ...@@ -386,6 +379,54 @@
</property> </property>
</spacer> </spacer>
</item> </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> </layout>
</widget> </widget>
<resources/> <resources/>
......
...@@ -37,7 +37,8 @@ struct MapParameters ...@@ -37,7 +37,8 @@ struct MapParameters
faceStyle(FLAT), faceStyle(FLAT),
diffuseColor(0.85f,0.25f,0.19f,0.0f),