Commit 8f76f00d authored by Pierre Kraemer's avatar Pierre Kraemer

add shaderScalarField

parent c0fb7beb
// 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);
}
/*******************************************************************************
* 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
// 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;
}
/*******************************************************************************
* 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 <GL/glew.h>
#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
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