diff --git a/include/Utils/Shaders/shaderScalarField.frag b/include/Utils/Shaders/shaderScalarField.frag new file mode 100644 index 0000000000000000000000000000000000000000..f8c2c16619d82e9a2c68882b5bf97a6fa0916c27 --- /dev/null +++ b/include/Utils/Shaders/shaderScalarField.frag @@ -0,0 +1,14 @@ +// ShaderScalarField::fragmentShaderText + +PRECISON; +VARYING_FRAG vec3 color; +VARYING_FRAG float scalar; +FRAG_OUT_DEF; +void main() +{ + float s = scalar * 50.0; + if( s - floor(s) <= 0.01 ) + gl_FragColor = vec4(0.0); + else + gl_FragColor = vec4(color, 0.0); +} diff --git a/include/Utils/Shaders/shaderScalarField.h b/include/Utils/Shaders/shaderScalarField.h new file mode 100644 index 0000000000000000000000000000000000000000..eebc8726a004e6ac66fdf1dae6d7e416bc8f7ccd --- /dev/null +++ b/include/Utils/Shaders/shaderScalarField.h @@ -0,0 +1,62 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009-2011, 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.u-strasbg.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#ifndef __CGOGN_SHADER_SCALARFIELD__ +#define __CGOGN_SHADER_SCALARFIELD__ + +#include "Utils/GLSLShader.h" +#include "Utils/clippingShader.h" +#include "Geometry/vector_gen.h" + +namespace CGoGN +{ + +namespace Utils +{ + +class ShaderScalarField : public ClippingShader +{ +protected: + // shader sources + static std::string vertexShaderText; + static std::string fragmentShaderText; + + VBO* m_vboPos; + VBO* m_vboScal; + + void restoreUniformsAttribs(); + +public: + ShaderScalarField(); + + unsigned int setAttributePosition(VBO* vbo); + + unsigned int setAttributeScalar(VBO* vbo); +}; + +} // namespace Utils + +} // namespace CGoGN + +#endif diff --git a/include/Utils/Shaders/shaderScalarField.vert b/include/Utils/Shaders/shaderScalarField.vert new file mode 100644 index 0000000000000000000000000000000000000000..d6ce2c39a391a52b60c5c5f33132165b81d0ec68 --- /dev/null +++ b/include/Utils/Shaders/shaderScalarField.vert @@ -0,0 +1,37 @@ +// ShaderScalarField::vertexShaderText + +ATTRIBUTE vec3 VertexPosition; +ATTRIBUTE float VertexScalar; +uniform mat4 ModelViewProjectionMatrix; +VARYING_VERT vec3 color; +VARYING_VERT float scalar; +INVARIANT_POS; + +vec3 color_map_blue_white_red(float x) +{ + vec3 c = vec3(0); + if (x < 0.0) + c.b = 1.0; + else if (x < 0.5) + { + c.r = 2.0 * x; + c.g = 2.0 * x; + c.b = 1.0; + } + else if (x < 1.0) + { + c.r = 1.0; + c.g = 2.0 - 2.0 * x; + c.b = 2.0 - 2.0 * x; + } + else + c.r = 1.0; + return c; +} + +void main () +{ + gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0); + color = color_map_blue_white_red(VertexScalar); + scalar = VertexScalar; +} diff --git a/src/Utils/Shaders/shaderScalarField.cpp b/src/Utils/Shaders/shaderScalarField.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2f7c52179e6f8f3649bf3252a375749e8de5ab88 --- /dev/null +++ b/src/Utils/Shaders/shaderScalarField.cpp @@ -0,0 +1,75 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009-2011, 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.u-strasbg.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#include +#include "Utils/Shaders/shaderScalarField.h" + + +namespace CGoGN +{ + +namespace Utils +{ + +#include "shaderScalarField.vert" +#include "shaderScalarField.frag" + +ShaderScalarField::ShaderScalarField() +{ + m_nameVS = "ShaderColorPerVertex_vs"; + m_nameFS = "ShaderColorPerVertex_fs"; + m_nameGS = "ShaderColorPerVertex_gs"; + + std::string glxvert(*GLSLShader::DEFINES_GL); + glxvert.append(vertexShaderText); + + std::string glxfrag(*GLSLShader::DEFINES_GL); + glxfrag.append(fragmentShaderText); + + loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str()); +} + +unsigned int ShaderScalarField::setAttributePosition(VBO* vbo) +{ + m_vboPos = vbo; + return bindVA_VBO("VertexPosition", vbo); +} + +unsigned int ShaderScalarField::setAttributeScalar(VBO* vbo) +{ + m_vboScal = vbo; + return bindVA_VBO("VertexScalar", vbo); +} + +void ShaderScalarField::restoreUniformsAttribs() +{ + bind(); + bindVA_VBO("VertexPosition", m_vboPos); + bindVA_VBO("VertexScalar", m_vboScal); + unbind(); +} + +} // namespace Utils + +} // namespace CGoGN