Commit dc66829a authored by Sylvain Thery's avatar Sylvain Thery

better with the shaders

parent de2c656c
// ShaderBoldColorLines::fragmentShaderText
PRECISION;
VARYING_FRAG vec3 fragColor;
uniform float alpha;
uniform vec4 planeClip;
VARYING_FRAG vec3 fragClip;
FRAG_OUT_DEF;
void main()
{
if (dot(planeClip,vec4(fragClip,1.0))>0.0)
discard;
FRAG_OUT = vec4(fragColor,alpha);
}
// ShaderBoldColorLines::geometryShaderText
uniform float lineWidth;
VARYING_IN vec3 vcolor[];
VARYING_OUT vec3 fragColor;
VARYING_IN vec3 posClip[];
VARYING_OUT vec3 fragClip;
void main()
{
vec3 A = POSITION_IN(0).xyz / POSITION_IN(0).w;
vec3 B = POSITION_IN(1).xyz / POSITION_IN(1).w;
vec3 U = normalize(B-A);
vec3 V = cross(U,vec3(0.0,0.0,1.0));
fragClip = posClip[0];
fragColor = vcolor[0];
gl_Position = vec4(A-U*lineWidth, 1.0);
EmitVertex();
gl_Position = vec4(A+V*lineWidth, 1.0);
EmitVertex();
gl_Position = vec4(A-V*lineWidth, 1.0);
EmitVertex();
fragColor = vcolor[1];
fragClip = posClip[1];
gl_Position = vec4(B+V*lineWidth, 1.0);
EmitVertex();
gl_Position = vec4(B-V*lineWidth, 1.0);
EmitVertex();
gl_Position = vec4(B+U*lineWidth, 1.0);
EmitVertex();
EndPrimitive();
}
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __CGOGN_SHADER_BOLDCOLORLINES__
#define __CGOGN_SHADER_BOLDCOLORLINES__
#include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h"
#include "Geometry/vector_gen.h"
#include "Utils/dll.h"
namespace CGoGN
{
namespace Utils
{
class CGoGN_UTILS_API ShaderBoldColorLines : public ClippingShader
{
protected:
// shader sources
static std::string vertexShaderText;
static std::string geometryShaderText;
static std::string fragmentShaderText;
CGoGNGLuint m_uniform_lineWidth;
CGoGNGLuint m_unif_alpha;
float m_lineWidth;
float m_pixWidth;
VBO* m_vboPos;
VBO* m_vboCol;
float m_opacity;
/// clipping
CGoGNGLuint m_unif_planeClip;
Geom::Vec4f m_planeClip;
void getLocations();
void sendParams();
void restoreUniformsAttribs();
public:
ShaderBoldColorLines();
void setLineWidth(float pix);
void updatePixelWidth();
void setOpacity(float op);
unsigned int setAttributeColor(VBO* vbo);
unsigned int setAttributePosition(VBO* vbo);
void setClippingPlane(const Geom::Vec4f& plane);
inline void setNoClippingPlane() { setClippingPlane(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f)); }
};
} // namespace Utils
} // namespace CGoGN
#endif
// ShaderBoldColorLines::vertexShaderText
ATTRIBUTE vec3 VertexPosition;
ATTRIBUTE vec3 VertexColor;
uniform mat4 ModelViewProjectionMatrix;
VARYING_VERT vec3 vcolor;
VARYING_VERT vec3 posClip;
INVARIANT_POS;
void main ()
{
posClip = VertexPosition;
vcolor = VertexColor;
gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);
}
// ShaderBoldLines::fragmentShaderText
PRECISION;
uniform vec4 lineColor;
uniform vec4 planeClip;
VARYING_FRAG vec3 fragClip;
FRAG_OUT_DEF;
void main()
{
if (dot(planeClip,vec4(fragClip,1.0))>0.0)
discard;
FRAG_OUT = lineColor;
}
// ShaderBoldLines::geometryShaderText
uniform float lineWidth;
VARYING_IN vec3 posClip[];
VARYING_OUT vec3 fragClip;
void main()
{
vec3 A = POSITION_IN(0).xyz / POSITION_IN(0).w;
vec3 B = POSITION_IN(1).xyz / POSITION_IN(1).w;
vec3 U = normalize(B-A);
vec3 V = cross(U,vec3(0.0,0.0,1.0));
fragClip = posClip[0];
gl_Position = vec4(A-U*lineWidth, 1.0);
EmitVertex();
gl_Position = vec4(A+V*lineWidth, 1.0);
EmitVertex();
gl_Position = vec4(A-V*lineWidth, 1.0);
EmitVertex();
fragClip = posClip[1];
gl_Position = vec4(B+V*lineWidth, 1.0);
EmitVertex();
gl_Position = vec4(B-V*lineWidth, 1.0);
EmitVertex();
gl_Position = vec4(B+U*lineWidth, 1.0);
EmitVertex();
EndPrimitive();
}
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __CGOGN_SHADER_BOLDLINES__
#define __CGOGN_SHADER_BOLDLINES__
#include "Utils/GLSLShader.h"
#include "Utils/clippingShader.h"
#include "Geometry/vector_gen.h"
#include "Utils/dll.h"
namespace CGoGN
{
namespace Utils
{
class CGoGN_UTILS_API ShaderBoldLines : public ClippingShader
{
protected:
// shader sources
static std::string vertexShaderText;
static std::string geometryShaderText;
static std::string fragmentShaderText;
CGoGNGLuint m_uniform_lineWidth;
CGoGNGLuint m_uniform_color;
float m_lineWidth;
float m_pixWidth;
Geom::Vec4f m_color;
VBO* m_vboPos;
/// clipping
CGoGNGLuint m_unif_planeClip;
Geom::Vec4f m_planeClip;
void getLocations();
void sendParams();
void restoreUniformsAttribs();
public:
ShaderBoldLines();
void setLineWidth(float pix);
void updatePixelWidth();
void setColor(const Geom::Vec4f& color);
unsigned int setAttributePosition(VBO* vbo);
void setClippingPlane(const Geom::Vec4f& plane);
inline void setNoClippingPlane() { setClippingPlane(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f)); }
};
} // namespace Utils
} // namespace CGoGN
#endif
// ShaderBoldLines::vertexShaderText
ATTRIBUTE vec3 VertexPosition;
uniform mat4 ModelViewProjectionMatrix;
VARYING_VERT vec3 posClip;
INVARIANT_POS;
void main ()
{
posClip = VertexPosition;
gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);
}
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#define CGoGN_UTILS_DLL_EXPORT 1
#include "Utils/Shaders/shaderBoldColorLines.h"
namespace CGoGN
{
namespace Utils
{
#include "ShaderBoldColorLines.vert"
#include "ShaderBoldColorLines.geom"
#include "ShaderBoldColorLines.frag"
ShaderBoldColorLines::ShaderBoldColorLines() :
m_lineWidth(0.01f),
m_opacity(1.0f),
m_planeClip(0.0f,0.0f,0.0f,0.0f)
{
m_nameVS = "ShaderBoldColorLines_vs";
m_nameFS = "ShaderBoldColorLines_fs";
m_nameGS = "ShaderBoldColorLines_gs";
std::string glxvert(GLSLShader::defines_gl());
glxvert.append(vertexShaderText);
std::string glxgeom = GLSLShader::defines_Geom("lines", "triangle_strip", 6);
glxgeom.append(geometryShaderText);
std::string glxfrag(GLSLShader::defines_gl());
glxfrag.append(fragmentShaderText);
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_LINES, GL_LINE_STRIP,6);
// get and fill uniforms
getLocations();
sendParams();
}
void ShaderBoldColorLines::getLocations()
{
bind();
*m_uniform_lineWidth = glGetUniformLocation(this->program_handler(), "lineWidth");
*m_unif_planeClip = glGetUniformLocation(this->program_handler(), "planeClip");
*m_unif_alpha = glGetUniformLocation(this->program_handler(), "alpha");
unbind();
}
void ShaderBoldColorLines::sendParams()
{
bind();
glUniform1f(*m_uniform_lineWidth, m_lineWidth);
glUniform1f (*m_unif_alpha, m_opacity);
if (*m_unif_planeClip > 0)
glUniform4fv(*m_unif_planeClip, 1, m_planeClip.data());
unbind();
}
void ShaderBoldColorLines::setLineWidth(float pix)
{
glm::i32vec4 viewport;
glGetIntegerv(GL_VIEWPORT, &(viewport[0]));
float lw = float((0.5*pix)/double(viewport[2]));
bind();
glUniform1f(*m_uniform_lineWidth, lw);
m_lineWidth = lw;
m_pixWidth = pix;
unbind();
}
void ShaderBoldColorLines::updatePixelWidth()
{
glm::i32vec4 viewport;
glGetIntegerv(GL_VIEWPORT, &(viewport[0]));
float lw = float((0.5*m_pixWidth)/double(viewport[2]));
bind();
glUniform1f(*m_uniform_lineWidth, lw);
m_lineWidth = lw;
unbind();
}
unsigned int ShaderBoldColorLines::setAttributeColor(VBO* vbo)
{
m_vboCol = vbo;
bind();
unsigned int id = bindVA_VBO("VertexColor", vbo);
unbind();
return id;
}
unsigned int ShaderBoldColorLines::setAttributePosition(VBO* vbo)
{
m_vboPos = vbo;
bind();
unsigned int id = bindVA_VBO("VertexPosition", vbo);
unbind();
return id;
}
void ShaderBoldColorLines::restoreUniformsAttribs()
{
getLocations();
sendParams();
bind();
bindVA_VBO("VertexPosition", m_vboPos);
bindVA_VBO("VertexColor", m_vboCol);
unbind();
}
void ShaderBoldColorLines::setOpacity(float op)
{
m_opacity = op;
bind();
glUniform1f (*m_unif_alpha, m_opacity);
unbind();
}
void ShaderBoldColorLines::setClippingPlane(const Geom::Vec4f& plane)
{
if (*m_unif_planeClip > 0)
{
m_planeClip = plane;
bind();
glUniform4fv(*m_unif_planeClip, 1, plane.data());
unbind();
}
}
} // namespace Utils
} // namespace CGoGN
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#define CGoGN_UTILS_DLL_EXPORT 1
#include "Utils/Shaders/shaderBoldLines.h"
namespace CGoGN
{
namespace Utils
{
#include "shaderBoldLines.vert"
#include "shaderBoldLines.geom"
#include "shaderBoldLines.frag"
ShaderBoldLines::ShaderBoldLines() :
m_lineWidth(0.01f),
m_color (0.0f, 0.0f, 0.0f, 0.0f),
m_planeClip(0.0f,0.0f,0.0f,0.0f)
{
m_nameVS = "ShaderBoldLines_vs";
m_nameFS = "ShaderBoldLines_fs";
m_nameGS = "ShaderBoldLines_gs";
std::string glxvert(GLSLShader::defines_gl());
glxvert.append(vertexShaderText);
std::string glxgeom = GLSLShader::defines_Geom("lines", "triangle_strip", 6);
glxgeom.append(geometryShaderText);
std::string glxfrag(GLSLShader::defines_gl());
glxfrag.append(fragmentShaderText);
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_LINES, GL_LINE_STRIP,6);
// get and fill uniforms
getLocations();
sendParams();
}
void ShaderBoldLines::getLocations()
{
bind();
*m_uniform_lineWidth = glGetUniformLocation(this->program_handler(), "lineWidth");
*m_uniform_color = glGetUniformLocation(this->program_handler(), "lineColor");
*m_unif_planeClip = glGetUniformLocation(this->program_handler(), "planeClip");
unbind();
}
void ShaderBoldLines::sendParams()
{
bind();
glUniform1f(*m_uniform_lineWidth, m_lineWidth);
glUniform4fv(*m_uniform_color, 1, m_color.data());
if (*m_unif_planeClip > 0)
glUniform4fv(*m_unif_planeClip, 1, m_planeClip.data());
unbind();
}
void ShaderBoldLines::setLineWidth(float pix)
{
glm::i32vec4 viewport;
glGetIntegerv(GL_VIEWPORT, &(viewport[0]));
float lw = float((0.5*pix)/double(viewport[2]));
bind();
glUniform1f(*m_uniform_lineWidth, lw);
m_lineWidth = lw;
m_pixWidth =pix;
unbind();
}
void ShaderBoldLines::updatePixelWidth()
{
glm::i32vec4 viewport;
glGetIntegerv(GL_VIEWPORT, &(viewport[0]));
float lw = float((0.5*m_pixWidth)/double(viewport[2]));
bind();
glUniform1f(*m_uniform_lineWidth, lw);
m_lineWidth = lw;
unbind();
}
void ShaderBoldLines::setColor(const Geom::Vec4f& color)
{
bind();
glUniform4fv(*m_uniform_color, 1, color.data());
m_color = color;
unbind();
}
unsigned int ShaderBoldLines::setAttributePosition(VBO* vbo)
{
m_vboPos = vbo;
bind();
unsigned int id = bindVA_VBO("VertexPosition", vbo);
std::cout << "setAttributePosition => " << id << std::endl;
unbind();
return id;
}
void ShaderBoldLines::restoreUniformsAttribs()
{
getLocations();
sendParams();
bind();
bindVA_VBO("VertexPosition", m_vboPos);
unbind();
}
void ShaderBoldLines::setClippingPlane(const Geom::Vec4f& plane)
{
if (*m_unif_planeClip > 0)
{
m_planeClip = plane;
bind();
glUniform4fv(*m_unif_planeClip, 1, plane.data());