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() ...@@ -92,20 +92,20 @@ void Viewer::cb_initGL()
m_positionVBO = new Utils::VBO() ; m_positionVBO = new Utils::VBO() ;
m_normalVBO = 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->setAttributePosition(m_positionVBO) ;
m_phongShader->setAttributeNormal(m_normalVBO) ; m_phongShader->setAttributeNormal(m_normalVBO) ;
m_phongShader->setAmbiant(colClear) ; m_phongShader->setAmbiant(colClear) ;
m_phongShader->setDiffuse(colDif) ; m_phongShader->setDiffuse(colDif) ;
m_phongShader->setSpecular(colSpec) ; m_phongShader->setSpecular(colSpec) ;
m_phongShader->setShininess(shininess) ; 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->setAttributePosition(m_positionVBO) ;
m_flatShader->setAmbiant(colClear) ; m_flatShader->setAmbiant(colClear) ;
m_flatShader->setDiffuse(colDif) ; 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() ; m_vectorShader = new Utils::ShaderVectorPerVertex() ;
...@@ -182,7 +182,7 @@ void Viewer::cb_redraw() ...@@ -182,7 +182,7 @@ void Viewer::cb_redraw()
} }
m_nbFrames++; m_nbFrames++;
if (m_nbFrames >=100) if (m_nbFrames >=500)
{ {
std::cout << 100000.0/m_frame_ch.elapsed()<< " fps"<<std::endl; std::cout << 100000.0/m_frame_ch.elapsed()<< " fps"<<std::endl;
m_nbFrames = 0; m_nbFrames = 0;
...@@ -214,6 +214,34 @@ void Viewer::cb_keyPress(int keycode) ...@@ -214,6 +214,34 @@ void Viewer::cb_keyPress(int keycode)
{ {
switch(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': case 'n':
m_flatShader->setNoClippingPlane(); m_flatShader->setNoClippingPlane();
m_phongShader->setNoClippingPlane(); m_phongShader->setNoClippingPlane();
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "Utils/Shaders/shaderPhong.h" #include "Utils/Shaders/shaderPhong.h"
#include "Utils/Shaders/shaderSimpleFlat.h" #include "Utils/Shaders/shaderSimpleFlat.h"
//#include "Utils/Shaders/shaderFlat.h"
#include "Utils/Shaders/shaderSimpleColor.h" #include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderVectorPerVertex.h" #include "Utils/Shaders/shaderVectorPerVertex.h"
#include "Utils/pointSprite.h" #include "Utils/pointSprite.h"
......
...@@ -2,12 +2,20 @@ ...@@ -2,12 +2,20 @@
uniform vec4 diffuse; uniform vec4 diffuse;
uniform vec4 diffuseBack; uniform vec4 diffuseBack;
uniform vec4 ambient; uniform vec4 ambient;
uniform bool doubleSided;
VARYING_FRAG float lambertTerm; VARYING_FRAG float lambertTerm;
FRAG_OUT_DEF; FRAG_OUT_DEF;
void main() void main()
{ {
if (gl_FrontFacing) if (gl_FrontFacing)
FRAG_OUT = ambient + lambertTerm*diffuse; FRAG_OUT = ambient + lambertTerm*diffuse;
else else
FRAG_OUT = ambient + lambertTerm*diffuseBack; {
if (!doubleSided)
discard;
FRAG_OUT = ambient - lambertTerm*diffuseBack;
}
} }
...@@ -5,6 +5,7 @@ uniform mat4 ModelViewProjectionMatrix; ...@@ -5,6 +5,7 @@ uniform mat4 ModelViewProjectionMatrix;
uniform mat4 NormalMatrix; uniform mat4 NormalMatrix;
uniform mat4 ModelViewMatrix; uniform mat4 ModelViewMatrix;
uniform vec3 lightPosition; uniform vec3 lightPosition;
VARYING_OUT float lambertTerm; VARYING_OUT float lambertTerm;
void main(void) void main(void)
...@@ -18,7 +19,7 @@ void main(void) ...@@ -18,7 +19,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++)
......
...@@ -50,7 +50,9 @@ protected: ...@@ -50,7 +50,9 @@ protected:
CGoGNGLuint m_unif_diffuseback; CGoGNGLuint m_unif_diffuseback;
CGoGNGLuint m_unif_lightPos; CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_explode; CGoGNGLuint m_unif_explode;
CGoGNGLuint m_unif_doubleSided;
int 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,13 +68,15 @@ protected: ...@@ -66,13 +68,15 @@ 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);
void setDiffuse(const Geom::Vec4f& diffuse); void setDiffuse(const Geom::Vec4f& diffuse);
void setDiffuseBack(const Geom::Vec4f& diffuseb); void setBackColor(const Geom::Vec4f& diffuseb);
void setLightPosition(const Geom::Vec3f& lp); void setLightPosition(const Geom::Vec3f& lp);
......
...@@ -8,30 +8,30 @@ VARYING_FRAG vec3 Color; ...@@ -8,30 +8,30 @@ VARYING_FRAG vec3 Color;
uniform vec4 materialDiffuse; uniform vec4 materialDiffuse;
uniform vec4 materialSpecular; uniform vec4 materialSpecular;
uniform vec4 materialAmbient; uniform vec4 materialAmbient;
uniform float shininess;
uniform vec4 backColor; uniform vec4 backColor;
uniform float shininess;
uniform bool doubleSided;
FRAG_OUT_DEF; FRAG_OUT_DEF;
void main() void main()
{ {
vec3 N = normalize (Normal); vec3 N = normalize (Normal);
vec3 L = normalize (LightDir); vec3 L = normalize (LightDir);
//float lambertTerm = clamp(dot(N,L),0.0,1.0);
vec4 finalColor = materialAmbient; vec4 finalColor = materialAmbient;
vec4 currentColor = materialDiffuse;
#ifdef DOUBLE_SIDED
float lambertTerm;
vec4 diffuseColor = materialDiffuse;
if (!gl_FrontFacing) if (!gl_FrontFacing)
{ {
if (!doubleSided)
discard;
N *= -1.0; 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 #ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm; finalColor += currentColor * lambertTerm;
#else #else
finalColor += vec4((Color*lambertTerm),0.0) ; finalColor += vec4((Color*lambertTerm),0.0) ;
#endif #endif
...@@ -39,24 +39,5 @@ void main() ...@@ -39,24 +39,5 @@ void main()
vec3 R = reflect(-L, N); vec3 R = reflect(-L, N);
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
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; 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;
...@@ -61,6 +62,7 @@ protected: ...@@ -61,6 +62,7 @@ protected:
CGoGNGLuint m_unif_lightPos; CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_eyePos; CGoGNGLuint m_unif_eyePos;
CGoGNGLuint m_unif_backColor; CGoGNGLuint m_unif_backColor;
CGoGNGLuint m_unif_doubleSided;
//values //values
Geom::Vec4f m_ambiant; Geom::Vec4f m_ambiant;
...@@ -70,6 +72,7 @@ protected: ...@@ -70,6 +72,7 @@ protected:
Geom::Vec3f m_lightPos; Geom::Vec3f m_lightPos;
Geom::Vec3f m_eyePos; Geom::Vec3f m_eyePos;
Geom::Vec4f m_backColor; Geom::Vec4f m_backColor;
int m_doubleSided;
VBO* m_vboPos; VBO* m_vboPos;
VBO* m_vboNormal; VBO* m_vboNormal;
...@@ -86,7 +89,9 @@ protected: ...@@ -86,7 +89,9 @@ protected:
void restoreUniformsAttribs(); void restoreUniformsAttribs();
public: 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 // inviduals parameter setting functions
void setAmbiant(const Geom::Vec4f& ambiant); void setAmbiant(const Geom::Vec4f& ambiant);
......
...@@ -10,7 +10,7 @@ uniform vec4 materialSpecular; ...@@ -10,7 +10,7 @@ uniform vec4 materialSpecular;
uniform vec4 materialAmbient; uniform vec4 materialAmbient;
uniform float shininess; uniform float shininess;
uniform vec4 backColor; uniform vec4 backColor;
uniform bool doubleSided;
uniform vec4 planeClip; uniform vec4 planeClip;
VARYING_FRAG vec3 posClip; VARYING_FRAG vec3 posClip;
...@@ -26,19 +26,19 @@ void main() ...@@ -26,19 +26,19 @@ void main()
//float lambertTerm = clamp(dot(N,L),0.0,1.0); //float lambertTerm = clamp(dot(N,L),0.0,1.0);
vec4 finalColor = materialAmbient; vec4 finalColor = materialAmbient;
vec4 currentColor = materialDiffuse;
#ifdef DOUBLE_SIDED
float lambertTerm;
vec4 diffuseColor = materialDiffuse;
if (!gl_FrontFacing) if (!gl_FrontFacing)
{ {
if (!doubleSided)
discard;
N *= -1.0; 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 #ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm; finalColor += currentColor * lambertTerm;
#else #else
finalColor += vec4((Color*lambertTerm),0.0) ; finalColor += vec4((Color*lambertTerm),0.0) ;
#endif #endif
...@@ -46,24 +46,6 @@ void main() ...@@ -46,24 +46,6 @@ void main()
vec3 R = reflect(-L, N); vec3 R = reflect(-L, N);
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
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; FRAG_OUT=finalColor;
} }
...@@ -11,6 +11,7 @@ uniform vec4 materialSpecular; ...@@ -11,6 +11,7 @@ uniform vec4 materialSpecular;
uniform vec4 materialAmbient; uniform vec4 materialAmbient;
uniform float shininess; uniform float shininess;
uniform vec4 backColor; uniform vec4 backColor;
uniform bool doubleSided;
FRAG_OUT_DEF; FRAG_OUT_DEF;
...@@ -23,36 +24,21 @@ void main() ...@@ -23,36 +24,21 @@ void main()
vec3 L = normalize (LightDir); vec3 L = normalize (LightDir);
vec4 finalColor = materialAmbient; 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) if (!gl_FrontFacing)
{ {
N *= -1.0; if (!doubleSided)
lambertTerm = clamp(dot(N,L),0.0,1.0); discard;
currentColor = backColor;
} }
else
lambertTerm = clamp(dot(N,L),0.0,1.0);
#ifndef WITH_COLOR #ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm; finalColor += currentColor * lambertTerm;
#else #else
finalColor += vec4((Color*lambertTerm),0.0) ; 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 #endif
FRAG_OUT=finalColor; FRAG_OUT=finalColor;
} }
...@@ -46,7 +46,6 @@ protected: ...@@ -46,7 +46,6 @@ 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;
// shader sources OGL3 // shader sources OGL3
static std::string vertexShaderText; static std::string vertexShaderText;
static std::string fragmentShaderText; static std::string fragmentShaderText;
...@@ -58,12 +57,14 @@ protected: ...@@ -58,12 +57,14 @@ protected:
CGoGNGLuint m_unif_diffuse; CGoGNGLuint m_unif_diffuse;
CGoGNGLuint m_unif_lightPos; CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_backColor; CGoGNGLuint m_unif_backColor;
CGoGNGLuint m_unif_doubleSided;
//values //values
Geom::Vec4f m_ambiant; Geom::Vec4f m_ambiant;
Geom::Vec4f m_diffuse; Geom::Vec4f m_diffuse;
Geom::Vec3f m_lightPos; Geom::Vec3f m_lightPos;
Geom::Vec4f m_backColor; Geom::Vec4f m_backColor;
int m_doubleSided;
VBO* m_vboPos; VBO* m_vboPos;
VBO* m_vboColor; VBO* m_vboColor;
...@@ -82,6 +83,8 @@ protected: ...@@ -82,6 +83,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);
......
...@@ -11,6 +11,7 @@ uniform vec4 materialSpecular; ...@@ -11,6 +11,7 @@ uniform vec4 materialSpecular;
uniform vec4 materialAmbient; uniform vec4 materialAmbient;
uniform float shininess; uniform float shininess;
uniform vec4 backColor; uniform vec4 backColor;
uniform bool doubleSided;
FRAG_OUT_DEF; FRAG_OUT_DEF;
...@@ -28,37 +29,21 @@ void main() ...@@ -28,37 +29,21 @@ void main()
vec3 L = normalize (LightDir); vec3 L = normalize (LightDir);
vec4 finalColor = materialAmbient;
vec4 finalColor = materialAmbient; vec4 finalColor = materialAmbient;
#ifdef DOUBLE_SIDED
float lambertTerm;
vec4 diffuseColor = materialDiffuse;
if (!gl_FrontFacing) if (!gl_FrontFacing)
{ {
if (!doubleSided)
discard;
N *= -1.0; 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 #ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm; finalColor += materialDiffuse * lambertTerm;
#else #else
finalColor += vec4((Color*lambertTerm),0.0) ; 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 #endif
FRAG_OUT=finalColor; FRAG_OUT=finalColor;
} }
...@@ -36,6 +36,10 @@ void VBO::updateData(std::vector<T>& data) ...@@ -36,6 +36,10 @@ void VBO::updateData(std::vector<T>& data)
CGoGNerr << "Error locked VBO" << CGoGNendl; CGoGNerr << "Error locked VBO" << CGoGNendl;
return; return;
} }