Commit 3bf37922 authored by Sylvain Thery's avatar Sylvain Thery

GL3 Lines shaders

parent 116f2b83
// ShaderBold3DColorLines::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);
}
// ShaderBold3DColorLines::geometryShaderText
uniform float lineWidth;
uniform mat4 ProjectionMatrix;
VARYING_IN vec3 vcolor[];
VARYING_OUT vec3 fragColor;
VARYING_IN vec3 posClip[];
VARYING_OUT vec3 fragClip;
void main()
{
vec4 Ap = (ProjectionMatrix*POSITION_IN(0));
vec4 Bp = (ProjectionMatrix*POSITION_IN(1));
vec3 U3 = normalize((Bp.xyz/Bp.w - Ap.xyz/Ap.w));
vec3 U = vec3(lineWidth*U3);
vec3 V = vec3(lineWidth*normalize(vec2(U[1],-U[0])), 0.0);
fragClip = posClip[0];
fragColor = vcolor[0];
gl_Position = ProjectionMatrix*vec4(POSITION_IN(0).xyz-U, 1.0);
EmitVertex();
gl_Position = ProjectionMatrix*vec4(POSITION_IN(0).xyz+V, 1.0);
EmitVertex();
gl_Position = ProjectionMatrix*vec4(POSITION_IN(0).xyz-V, 1.0);
EmitVertex();
fragClip = posClip[1];
fragColor = vcolor[1];
gl_Position = ProjectionMatrix*vec4(POSITION_IN(1).xyz+V, 1.0);
EmitVertex();
gl_Position = ProjectionMatrix*vec4(POSITION_IN(1).xyz-V, 1.0);
EmitVertex();
gl_Position = ProjectionMatrix*vec4(POSITION_IN(1).xyz+U, 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_BOLD3DCOLORLINES__
#define __CGOGN_SHADER_BOLD3DCOLORLINES__
#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 ShaderBold3DColorLines : 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;
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:
ShaderBold3DColorLines();
void setLineWidth(float pix);
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
// ShaderBold3DColorLines::vertexShaderText
ATTRIBUTE vec3 VertexPosition;
ATTRIBUTE vec3 VertexColor;
uniform mat4 ModelViewMatrix;
VARYING_VERT vec3 vcolor;
VARYING_VERT vec3 posClip;
INVARIANT_POS;
void main ()
{
posClip = VertexPosition;
vcolor = VertexColor;
gl_Position = ModelViewMatrix * vec4 (VertexPosition, 1.0);
}
// ShaderBold3DLines::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;
}
// ShaderBold3DLines::geometryShaderText
uniform mat4 ProjectionMatrix;
uniform float lineWidth;
VARYING_IN vec3 posClip[];
VARYING_OUT vec3 fragClip;
void main()
{
vec4 Ap = (ProjectionMatrix*POSITION_IN(0));
vec4 Bp = (ProjectionMatrix*POSITION_IN(1));
vec3 U3 = normalize((Bp.xyz/Bp.w - Ap.xyz/Ap.w));
vec3 U = vec3(lineWidth*U3);
vec3 V = vec3(lineWidth*normalize(vec2(U[1],-U[0])), 0.0);
fragClip = posClip[0];
gl_Position = ProjectionMatrix*vec4(POSITION_IN(0).xyz-U, 1.0);
EmitVertex();
gl_Position = ProjectionMatrix*vec4(POSITION_IN(0).xyz+V, 1.0);
EmitVertex();
gl_Position = ProjectionMatrix*vec4(POSITION_IN(0).xyz-V, 1.0);
EmitVertex();
fragClip = posClip[1];
gl_Position = ProjectionMatrix*vec4(POSITION_IN(1).xyz+V, 1.0);
EmitVertex();
gl_Position = ProjectionMatrix*vec4(POSITION_IN(1).xyz-V, 1.0);
EmitVertex();
gl_Position = ProjectionMatrix*vec4(POSITION_IN(1).xyz+U, 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_BOLD3DLINES__
#define __CGOGN_SHADER_BOLD3DLINES__
#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 ShaderBold3DLines : 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;
Geom::Vec4f m_color;
VBO* m_vboPos;
/// clipping
CGoGNGLuint m_unif_planeClip;
Geom::Vec4f m_planeClip;
void getLocations();
void sendParams();
void restoreUniformsAttribs();
public:
ShaderBold3DLines();
void setLineWidth(float pix);
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
// ShaderBold3DLines::vertexShaderText
ATTRIBUTE vec3 VertexPosition;
uniform mat4 ModelViewMatrix;
VARYING_VERT vec3 posClip;
INVARIANT_POS;
void main ()
{
posClip = VertexPosition;
gl_Position = ModelViewMatrix * vec4 (VertexPosition, 1.0);
}
// ShaderBoldColorLines::geometryShaderText // ShaderBoldColorLines::geometryShaderText
uniform vec2 lineWidth; uniform vec2 lineWidths;
uniform mat4 ProjectionMatrix;
VARYING_IN vec3 vcolor[]; VARYING_IN vec3 vcolor[];
VARYING_OUT vec3 fragColor; VARYING_OUT vec3 fragColor;
...@@ -10,30 +11,49 @@ VARYING_OUT vec3 fragClip; ...@@ -10,30 +11,49 @@ VARYING_OUT vec3 fragClip;
void main() void main()
{ {
vec4 A = POSITION_IN(0);
vec3 A = POSITION_IN(0).xyz / abs(POSITION_IN(0).w); vec4 B = POSITION_IN(1);
vec3 B = POSITION_IN(1).xyz / abs(POSITION_IN(1).w);
// float nearZ = - ProjectionMatrix[3][2] / (ProjectionMatrix[2][2] - 1.0);
vec3 U = normalize(B-A); float nearZ = 1.0;
vec3 V = cross(U,vec3(0.0,0.0,1.0)); if (ProjectionMatrix[2][2] != 1.0)
nearZ = - ProjectionMatrix[3][2] / (ProjectionMatrix[2][2] - 1.0);
vec3 LW = vec3(lineWidth,1.0);
fragClip = posClip[0];
fragColor = vcolor[0]; if ((A.z < nearZ) || (B.z < nearZ))
gl_Position = vec4(A-U*LW, 1.0); {
EmitVertex(); if (A.z >= nearZ)
gl_Position = vec4(A+V*LW, 1.0); A = B + (A-B)*(nearZ-B.z)/(A.z-B.z);
EmitVertex(); if (B.z >= nearZ)
gl_Position = vec4(A-V*LW, 1.0); B = A + (B-A)*(nearZ-A.z)/(B.z-A.z);
EmitVertex();
fragColor = vcolor[1]; A = ProjectionMatrix*A;
fragClip = posClip[1]; B = ProjectionMatrix*B;
gl_Position = vec4(B+V*LW, 1.0);
EmitVertex(); A = A/A.w;
gl_Position = vec4(B-V*LW, 1.0); B = B/B.w;
EmitVertex(); vec2 U2 = normalize((B.xyz - A.xyz).xy);
gl_Position = vec4(B+U*LW, 1.0); vec3 U = vec3(lineWidths*U2,0.0);
EmitVertex(); vec3 V = vec3(lineWidths*vec2(U2[1], -U2[0]), 0.0);
EndPrimitive(); U2 *= (lineWidths[0]+lineWidths[1])/4.0;
fragClip = posClip[0];
fragColor = vcolor[0];
A -= vec4(U2,0.0,0.0);
gl_Position = vec4(A.xyz+V, 1.0);
EmitVertex();
gl_Position = vec4(A.xyz-V, 1.0);
EmitVertex();
fragClip = posClip[1];
fragColor = vcolor[1];
B += vec4(U2,0.0,0.0);
gl_Position = vec4(B.xyz+V, 1.0);
EmitVertex();
gl_Position = vec4(B.xyz-V, 1.0);
EmitVertex();
EndPrimitive();
}
} }
...@@ -49,7 +49,6 @@ protected: ...@@ -49,7 +49,6 @@ protected:
CGoGNGLuint m_unif_alpha; CGoGNGLuint m_unif_alpha;
Geom::Vec2f m_lineWidth; Geom::Vec2f m_lineWidth;
float m_pixWidth;
VBO* m_vboPos; VBO* m_vboPos;
VBO* m_vboCol; VBO* m_vboCol;
...@@ -71,8 +70,6 @@ public: ...@@ -71,8 +70,6 @@ public:
void setLineWidth(float pix); void setLineWidth(float pix);
void updatePixelWidth();
void setOpacity(float op); void setOpacity(float op);
unsigned int setAttributeColor(VBO* vbo); unsigned int setAttributeColor(VBO* vbo);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
ATTRIBUTE vec3 VertexPosition; ATTRIBUTE vec3 VertexPosition;
ATTRIBUTE vec3 VertexColor; ATTRIBUTE vec3 VertexColor;
uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelViewMatrix;
VARYING_VERT vec3 vcolor; VARYING_VERT vec3 vcolor;
VARYING_VERT vec3 posClip; VARYING_VERT vec3 posClip;
...@@ -11,5 +11,5 @@ void main () ...@@ -11,5 +11,5 @@ void main ()
{ {
posClip = VertexPosition; posClip = VertexPosition;
vcolor = VertexColor; vcolor = VertexColor;
gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0); gl_Position = ModelViewMatrix * vec4 (VertexPosition, 1.0);
} }
// ShaderBoldLines::geometryShaderText // ShaderBoldLines::geometryShaderText
uniform vec2 lineWidth; uniform mat4 ProjectionMatrix;
uniform vec2 lineWidths;
VARYING_IN vec3 posClip[]; VARYING_IN vec3 posClip[];
VARYING_OUT vec3 fragClip; VARYING_OUT vec3 fragClip;
void main() void main()
{ {
vec3 A = POSITION_IN(0).xyz / abs(POSITION_IN(0).w); vec4 A = POSITION_IN(0);
vec3 B = POSITION_IN(1).xyz / abs(POSITION_IN(1).w); vec4 B = POSITION_IN(1);
float nearZ = 1.0;
if (ProjectionMatrix[2][2] != 1.0)
nearZ = - ProjectionMatrix[3][2] / (ProjectionMatrix[2][2] - 1.0);
vec3 U = normalize(B-A); if ((A.z < nearZ) || (B.z < nearZ))
vec3 V = cross(U,vec3(0.0,0.0,1.0)); {
if (A.z >= nearZ)
A = B + (A-B)*(nearZ-B.z)/(A.z-B.z);
if (B.z >= nearZ)
B = A + (B-A)*(nearZ-A.z)/(B.z-A.z);
vec3 LW = vec3(lineWidth,1.0); A = ProjectionMatrix*A;
fragClip = posClip[0]; B = ProjectionMatrix*B;
gl_Position = vec4(A-U*LW, 1.0);
EmitVertex(); A = A/A.w;
gl_Position = vec4(A+V*LW, 1.0); B = B/B.w;
EmitVertex(); vec2 U2 = normalize((B.xyz - A.xyz).xy);
gl_Position = vec4(A-V*LW, 1.0); vec3 U = vec3(lineWidths*U2,0.0);
EmitVertex(); vec3 V = vec3(lineWidths*vec2(U2[1], -U2[0]), 0.0);
fragClip = posClip[1];
gl_Position = vec4(B+V*LW, 1.0); U2 *= (lineWidths[0]+lineWidths[1])/4.0;
EmitVertex();
gl_Position = vec4(B-V*LW, 1.0); fragClip = posClip[0];
EmitVertex(); A -= vec4(U2,0.0,0.0);
gl_Position = vec4(B+U*LW, 1.0); gl_Position = vec4(A.xyz+V, 1.0);
EmitVertex(); EmitVertex();
EndPrimitive(); gl_Position = vec4(A.xyz-V, 1.0);
EmitVertex();
fragClip = posClip[1];
B += vec4(U2,0.0,0.0);
gl_Position = vec4(B.xyz+V, 1.0);
EmitVertex();
gl_Position = vec4(B.xyz-V, 1.0);
EmitVertex();
EndPrimitive();
}
} }
...@@ -49,7 +49,6 @@ protected: ...@@ -49,7 +49,6 @@ protected:
CGoGNGLuint m_uniform_color; CGoGNGLuint m_uniform_color;
Geom::Vec2f m_lineWidth; Geom::Vec2f m_lineWidth;
float m_pixWidth;
Geom::Vec4f m_color; Geom::Vec4f m_color;
...@@ -70,8 +69,6 @@ public: ...@@ -70,8 +69,6 @@ public:
void setLineWidth(float pix); void setLineWidth(float pix);
void updatePixelWidth();
void setColor(const Geom::Vec4f& color); void setColor(const Geom::Vec4f& color);
unsigned int setAttributePosition(VBO* vbo); unsigned int setAttributePosition(VBO* vbo);
......
// ShaderBoldLines::vertexShaderText // ShaderBoldLines::vertexShaderText
ATTRIBUTE vec3 VertexPosition; ATTRIBUTE vec3 VertexPosition;
uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelViewMatrix;
VARYING_VERT vec3 posClip; VARYING_VERT vec3 posClip;
INVARIANT_POS; INVARIANT_POS;
void main () void main ()
{ {
posClip = VertexPosition; posClip = VertexPosition;
gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0); gl_Position = ModelViewMatrix * vec4 (VertexPosition, 1.0);
} }
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "Geometry/vector_gen.h" #include "Geometry/vector_gen.h"
#include "Utils/Shaders/shaderColorPerVertex.h" #include "Utils/Shaders/shaderColorPerVertex.h"
#include "Utils/Shaders/shaderBoldColorLines.h" #include "Utils/Shaders/shaderBoldColorLines.h"
#include "Utils/Shaders/shaderBold3DColorLines.h"
namespace CGoGN { namespace Utils { class VBO; } } namespace CGoGN { namespace Utils { class VBO; } }
namespace CGoGN { namespace Utils { namespace SVG { class SVGOut ; } } } namespace CGoGN { namespace Utils { namespace SVG { class SVGOut ; } } }
...@@ -71,21 +72,26 @@ protected: ...@@ -71,21 +72,26 @@ protected:
float m_currentSize; float m_currentSize;
GLenum m_compile; GLenum m_compile;
Utils::ShaderColorPerVertex* m_shader; Utils::ShaderColorPerVertex* m_shader;
Utils::ShaderBoldColorLines* m_shader2; Utils::ShaderBoldColorLines* m_shaderCL;
Utils::ShaderBold3DColorLines* m_shader3DCL;
int m_lineMode;
public: public:
/** /**
* constructor, init all buffers (data and OpenGL) and shader * constructor, init all buffers (data and OpenGL) and shader
* @param lineMode 0:simple thin Line / 1:line with possible width /2:3D Lines
* @Warning need OpenGL context * @Warning need OpenGL context
*/ */
Drawer(); Drawer(int lineMode=0);
/** /**
* release buffers and shader * release buffers and shader
*/ */
~Drawer(); ~Drawer();
// Utils::ShaderColorPerVertex* getShader(); // Utils::ShaderColorPerVertex* getShader();
std::vector<Utils::GLSLShader*> getShaders(); std::vector<Utils::GLSLShader*> getShaders();
......
/*******************************************************************************
* 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/shaderBold3DColorLines.h"
#include <algorithm>
namespace CGoGN
{
namespace Utils
{
#include "ShaderBold3DColorLines.vert"