Commit a67bbdf2 authored by Thery Sylvain's avatar Thery Sylvain

Merge branch 'master' of cgogn:CGoGN

parents 81751915 2433e28a
......@@ -212,7 +212,7 @@ void verticesRaySelection(typename PFP::MAP& map, const VertexAttribute<typename
template<typename PFP>
void volumesRaySelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const FunctorSelect& good, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector<Dart>& vecVolumes)
{
std::vector<Dart>& vecFaces;
std::vector<Dart> vecFaces;
std::vector<typename PFP::VEC3> iPoints;
// get back intersected faces
......@@ -425,7 +425,7 @@ void facesPlanSelection(typename PFP::MAP& map, const VertexAttribute<typename P
* @param angle angle of the code in degree.
*/
template<typename PFP>
void verticesConeSelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, float angle, std::vector<Dart>& vecVertices, const FunctorSelect& good= allDarts)
void verticesConeSelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, float angle, std::vector<Dart>& vecVertices, const FunctorSelect& good)
{
typename PFP::REAL AB2 = rayAB * rayAB;
......@@ -533,7 +533,7 @@ void edgesConeSelection(typename PFP::MAP& map, const VertexAttribute<typename P
template<typename PFP>
Dart verticesBubbleSelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const typename PFP::VEC3& cursor, typename PFP::REAL radiusMax, const FunctorSelect& good=allDarts)
Dart verticesBubbleSelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const typename PFP::VEC3& cursor, typename PFP::REAL radiusMax, const FunctorSelect& good)
{
typename PFP::REAL l2max = radiusMax*radiusMax;
typename PFP::REAL l2min(std::numeric_limits<float>::max());
......@@ -555,7 +555,7 @@ Dart verticesBubbleSelection(typename PFP::MAP& map, const VertexAttribute<typen
template<typename PFP>
Dart edgesBubbleSelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const typename PFP::VEC3& cursor, typename PFP::REAL radiusMax, const FunctorSelect& good=allDarts)
Dart edgesBubbleSelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const typename PFP::VEC3& cursor, typename PFP::REAL radiusMax, const FunctorSelect& good)
{
typename PFP::REAL l2max = radiusMax*radiusMax;
typename PFP::REAL l2min(std::numeric_limits<float>::max());
......@@ -661,7 +661,7 @@ Dart edgesBubbleSelection(typename PFP::MAP& map, const VertexAttribute<typename
//
//
//template<typename PFP>
//void verticesRaySelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector<Dart>& vecVertices, float dist, const FunctorSelect& good= allDarts, unsigned int nbth=0, unsigned int current_thread=0)
//void verticesRaySelection(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const typename PFP::VEC3& rayA, const typename PFP::VEC3& rayAB, std::vector<Dart>& vecVertices, float dist, const FunctorSelect& good , unsigned int nbth=0, unsigned int current_thread=0)
//{
// typename PFP::REAL dist2 = dist * dist;
// typename PFP::REAL AB2 = rayAB * rayAB;
......
......@@ -42,6 +42,8 @@ class ShaderPhong : public ClippingShader
protected:
// flag color per vertex or not
bool m_with_color;
// flag color per vertex or not
bool m_with_eyepos;
// shader sources OGL3
static std::string vertexShaderText;
......@@ -53,6 +55,7 @@ protected:
CGoGNGLuint m_unif_specular;
CGoGNGLuint m_unif_shininess;
CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_eyePos;
//values
Geom::Vec4f m_ambiant;
......@@ -60,6 +63,7 @@ protected:
Geom::Vec4f m_specular;
float m_shininess;
Geom::Vec3f m_lightPos;
Geom::Vec3f m_eyePos;
VBO* m_vboPos;
VBO* m_vboNormal;
......@@ -72,7 +76,7 @@ protected:
void restoreUniformsAttribs();
public:
ShaderPhong(bool doubleSided = false);
ShaderPhong(bool doubleSided = false, bool withEyePosition=false);
// inviduals parameter setting functions
void setAmbiant(const Geom::Vec4f& ambiant);
......@@ -83,7 +87,10 @@ public:
void setShininess(float shininess);
void setLightPosition(Geom::Vec3f lp);
void setLightPosition(const Geom::Vec3f& lp);
/// set eye position for VR environement
void setEyePosition(const Geom::Vec3f& ep);
const Geom::Vec4f& getAmbiant() const { return m_ambiant; }
......
......@@ -9,18 +9,28 @@ uniform mat4 ModelViewMatrix;
uniform mat4 NormalMatrix;
uniform vec3 lightPosition;
VARYING_VERT vec3 EyeVector, Normal, LightDir;
#ifdef WITH_COLOR
VARYING_VERT vec3 Color;
#endif
#ifdef WITH_EYEPOSITION
uniform vec3 eyePosition;
#endif
INVARIANT_POS;
void main ()
{
Normal = vec3 (NormalMatrix * vec4 (VertexNormal, 0.0));
vec3 Position = vec3 (ModelViewMatrix * vec4 (VertexPosition, 1.0));
LightDir = lightPosition - Position;
EyeVector = -Position;
#ifdef WITH_EYEPOSITION
EyeVector = eyePosition-Position;
#else
EyeVector = -Position;
#endif
#ifdef WITH_COLOR
Color = VertexColor;
Color = VertexColor;
#endif
gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);
}
......@@ -19,8 +19,10 @@ void main(void)
if (lum==0.0)
discard;
vec2 v = texCoord-vec2(0.5,0.5);
#ifndef WITH_PLANE
float z = size * sqrt(1.0-dot(v,v));
vec2 zfrag = positionFragIn + vec2(z,0.0);
gl_FragDepth = 0.5 + 0.5 * dot(zfrag, mvpFragIn.xy) / dot(zfrag, mvpFragIn.zw);
#endif
gl_FragColor = vec4(colorsprite,0.0)*lum;
}
......@@ -12,31 +12,58 @@ VARYING_OUT vec4 mvpFragIn;
VARYING_OUT vec3 colorsprite;
#endif
#ifdef WITH_PLANE
uniform vec3 planeX;
uniform vec3 planeY;
#endif
void main()
{
vec4 posCenter = ModelViewMatrix * POSITION_IN(0);
vec4 pos = posCenter + vec4(-size, size, 0.0, 0.0);
positionFragIn = posCenter.zw;
#ifdef WITH_COLOR_PER_VERTEX
colorsprite = color[0];
#endif
mvpFragIn.x = ProjectionMatrix[2][2];
mvpFragIn.y = ProjectionMatrix[3][2];
mvpFragIn.z = ProjectionMatrix[2][3];
mvpFragIn.w = ProjectionMatrix[3][3];
texCoord = vec2(0.0,1.0);
vec4 posCenter = ModelViewMatrix * POSITION_IN(0);
positionFragIn = posCenter.zw;
#ifdef WITH_COLOR_PER_VERTEX
colorsprite = color[0];
#endif
texCoord = vec2(0.0,1.0);
#ifdef WITH_PLANE
vec4 pos = posCenter - size*vec4(planeX,0.0) + size*vec4(planeY,0.0) + size*vec4(0.0,0.0,0.5,0.0);
#else
vec4 pos = posCenter + vec4(-size, size, 0.0, 0.0);
#endif
gl_Position = ProjectionMatrix * pos;
EmitVertex();
pos = posCenter + vec4(-size, -size, 0.0, 0.0);
#ifdef WITH_PLANE
pos = posCenter - size*vec4(planeX,0.0) - size*vec4(planeY,0.0) + size*vec4(0.0,0.0,0.5,0.0);
#else
pos = posCenter + vec4(-size, -size, 0.0, 0.0);
#endif
texCoord = vec2(0.0,0.0);
gl_Position = ProjectionMatrix * pos;
EmitVertex();
pos = posCenter + vec4( size, size, 0.0, 0.0);
#ifdef WITH_PLANE
pos = posCenter + size*vec4(planeX,0.0) + size*vec4(planeY,0.0) + size*vec4(0.0,0.0,0.5,0.0);
#else
pos = posCenter + vec4(size, size, 0.0, 0.0);
#endif
texCoord = vec2(1.0,1.0);
gl_Position = ProjectionMatrix * pos;
EmitVertex();
pos = posCenter + vec4( size,-size, 0.0, 0.0);
#ifdef WITH_PLANE
pos = posCenter + size*vec4(planeX,0.0) - size*vec4(planeY,0.0) + size*vec4(0.0,0.0,0.5,0.0);
#else
pos = posCenter + vec4(size, -size, 0.0, 0.0);
#endif
texCoord = vec2(1.0,0.0);
gl_Position = ProjectionMatrix * pos;
EmitVertex();
......
......@@ -61,6 +61,10 @@ protected:
CGoGNGLuint m_idTexture;
CGoGNGLuint m_uniform_texture;
CGoGNGLuint m_uniform_planeX;
CGoGNGLuint m_uniform_planeY;
public:
/**
......@@ -69,7 +73,7 @@ public:
* @param radius of sphere
*/
PointSprite(bool withColorPerVertex=false, float radius=1.0f);
PointSprite(bool withColorPerVertex=false, float radius=1.0f, bool with_plane=false);
/**
* clean shaders, texture and variables
......@@ -97,6 +101,12 @@ public:
* @param radius
*/
void setSize(float radius);
/**
* set the plane of rendering for VR rendering
*/
void setPlane(const Geom::Vec3f& ox, const Geom::Vec3f& oy);
/**
* set position attribute
......
......@@ -80,9 +80,13 @@ protected:
CGoGNGLuint m_uniform_position;
CGoGNGLuint m_uniform_color;
CGoGNGLuint m_uniform_planeX;
CGoGNGLuint m_uniform_planeY;
public:
Strings3D(bool withBackground = true, const Geom::Vec3f& bgc = Geom::Vec3f(0));
Strings3D(bool withBackground = true, const Geom::Vec3f& bgc = Geom::Vec3f(0), bool with_plane=false);
~Strings3D();
......@@ -112,7 +116,7 @@ public:
void sendToVBO();
/**
* draw on string
* draw one string
* @param idSt the id of string
* @param pos the position of text
*/
......@@ -140,6 +144,11 @@ public:
* @param scale
*/
void setScale(float scale);
/**
* set the plane of rendering for VR rendering
*/
void setPlane(const Geom::Vec3f& ox, const Geom::Vec3f& oy);
void toSVG(Utils::SVG::SVGOut& svg);
......
......@@ -7,9 +7,22 @@ uniform vec3 strPos;
uniform float scale;
VARYING_VERT vec2 tex_coord;
INVARIANT_POS;
#ifdef WITH_PLANE
uniform vec3 planeX;
uniform vec3 planeY;
#endif
void main ()
{
#ifdef WITH_PLANE
vec4 pos = ModelViewMatrix * vec4(strPos,1.0);
pos += scale*VertexPosition[0]*vec4(planeX,0.0);
pos += scale*VertexPosition[1]*vec4(planeY,0.0);
#else
vec4 pos = ModelViewMatrix * vec4(strPos,1.0) + vec4(VertexPosition[0]*scale,VertexPosition[1]*scale,0.0,0.0);
#endif
tex_coord = vec2(VertexPosition[2],VertexPosition[3]);
gl_Position = ProjectionMatrix * pos;
}
......
......@@ -34,8 +34,9 @@ namespace Utils
#include "shaderPhong.frag"
ShaderPhong::ShaderPhong(bool doubleSided):
ShaderPhong::ShaderPhong(bool doubleSided, bool withEyePosition):
m_with_color(false),
m_with_eyepos(withEyePosition),
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)),
......@@ -53,6 +54,8 @@ ShaderPhong::ShaderPhong(bool doubleSided):
// get choose GL defines (2 or 3)
// ans compile shaders
std::string glxvert(*GLSLShader::DEFINES_GL);
if (m_with_eyepos)
glxvert.append("#define WITH_EYEPOSITION");
glxvert.append(vertexShaderText);
std::string glxfrag(*GLSLShader::DEFINES_GL);
// Use double sided lighting if set
......@@ -75,6 +78,8 @@ void ShaderPhong::getLocations()
*m_unif_specular = glGetUniformLocation(this->program_handler(), "materialSpecular");
*m_unif_shininess = glGetUniformLocation(this->program_handler(), "shininess");
*m_unif_lightPos = glGetUniformLocation(this->program_handler(), "lightPosition");
if (m_with_eyepos)
*m_unif_eyePos = glGetUniformLocation(this->program_handler(), "eyePosition");
}
void ShaderPhong::sendParams()
......@@ -84,6 +89,8 @@ 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());
if (m_with_eyepos)
glUniform3fv(*m_unif_eyePos, 1, m_eyePos.data());
}
void ShaderPhong::setAmbiant(const Geom::Vec4f& ambiant)
......@@ -114,13 +121,23 @@ void ShaderPhong::setShininess(float shininess)
m_shininess = shininess;
}
void ShaderPhong::setLightPosition( Geom::Vec3f lightPos)
void ShaderPhong::setLightPosition(const Geom::Vec3f& lightPos)
{
this->bind();
glUniform3fv(*m_unif_lightPos,1,lightPos.data());
m_lightPos = lightPos;
}
void ShaderPhong::setEyePosition(const Geom::Vec3f& eyePos)
{
if (m_with_eyepos)
{
this->bind();
glUniform3fv(*m_unif_eyePos,1,eyePos.data());
m_eyePos = eyePos;
}
}
void ShaderPhong::setParams(const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec4f& specular, float shininess, const Geom::Vec3f& lightPos)
{
m_ambiant = ambiant;
......
......@@ -41,7 +41,7 @@ PointSprite* PointSprite::m_instance0 = NULL;
PointSprite::PointSprite(bool withColorPervertex, float radius)
PointSprite::PointSprite(bool withColorPervertex, float radius, bool with_plane)
{
std::string defineColor("#define WITH_COLOR_PER_VERTEX 1\n");
......@@ -53,11 +53,16 @@ PointSprite::PointSprite(bool withColorPervertex, float radius)
std::string glxgeom = GLSLShader::defines_Geom("points","triangle_strip",4);
if (withColorPervertex)
glxgeom.append(defineColor);
if (with_plane)
glxgeom.append("#define WITH_PLANE 1\n");
glxgeom.append(geometryShaderText);
std::string glxfrag(*GLSLShader::DEFINES_GL);
if (withColorPervertex)
glxfrag.append(defineColor);
if (with_plane)
glxfrag.append("#define WITH_PLANE 1\n");
glxfrag.append(fragmentShaderText);
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_POINTS, GL_TRIANGLE_STRIP,4);
......@@ -85,6 +90,12 @@ PointSprite::PointSprite(bool withColorPervertex, float radius)
}
*m_uniform_texture = glGetUniformLocation(program_handler(),"SpriteTexture");
if (with_plane)
{
*m_uniform_planeX = glGetUniformLocation(program_handler(),"planeX");
*m_uniform_planeY = glGetUniformLocation(program_handler(),"planeY");
}
}
PointSprite::~PointSprite()
......@@ -138,6 +149,15 @@ void PointSprite::setSize(float radius)
unbind();
}
void PointSprite::setPlane(const Geom::Vec3f& ox, const Geom::Vec3f& oy)
{
bind();
glUniform3fv(*m_uniform_planeX, 1, ox.data());
glUniform3fv(*m_uniform_planeY, 1, oy.data());
unbind();
}
void PointSprite::computeSphere()
{
if (m_ptrSphere == NULL) // normally useless
......
......@@ -43,7 +43,7 @@ std::string Strings3D::fragmentShaderText2 =
Strings3D* Strings3D::m_instance0 = NULL;
Strings3D::Strings3D(bool withBackground, const Geom::Vec3f& bgc) : m_nbChars(0),m_scale(1.0f)
Strings3D::Strings3D(bool withBackground, const Geom::Vec3f& bgc, bool with_plane) : m_nbChars(0),m_scale(1.0f)
{
if (m_instance0 == NULL)
{
......@@ -67,6 +67,8 @@ Strings3D::Strings3D(bool withBackground, const Geom::Vec3f& bgc) : m_nbChars(0)
}
std::string glxvert(*GLSLShader::DEFINES_GL);
if (with_plane)
glxvert.append("#define WITH_PLANE 1");
glxvert.append(vertexShaderText);
std::string glxfrag(*GLSLShader::DEFINES_GL);
......@@ -98,6 +100,11 @@ Strings3D::Strings3D(bool withBackground, const Geom::Vec3f& bgc) : m_nbChars(0)
*m_uniform_scale = glGetUniformLocation(program_handler(), "scale");
*m_uniform_texture = glGetUniformLocation(program_handler(), "FontTexture");
glUniform1f(*m_uniform_scale, 1.0f);
if (with_plane)
{
*m_uniform_planeX = glGetUniformLocation(program_handler(), "planeX");
*m_uniform_planeY = glGetUniformLocation(program_handler(), "planeY");
}
unbind();
}
......@@ -109,6 +116,14 @@ void Strings3D::setScale(float scale)
unbind();
}
void Strings3D::setPlane(const Geom::Vec3f& ox, const Geom::Vec3f& oy)
{
bind();
glUniform3fv(*m_uniform_planeX, 1, ox.data());
glUniform3fv(*m_uniform_planeY, 1, oy.data());
unbind();
}
Strings3D::~Strings3D()
{
}
......
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