Commit 549167d9 authored by boustila's avatar boustila

update VRJ

parent da400179
......@@ -294,6 +294,8 @@ public:
const Geom::BoundingBox<VEC3>& getGroupBB(unsigned int i) const { return m_groupBBs[i];}
Geom::BoundingBox<VEC3>& getGroupBB(unsigned int i) { return m_groupBBs[i];}
const std::string& objGroupName(unsigned int i) const { return m_groupNames[i];}
/**
......
// ShaderCustom::fragmentShaderText
VARYING_FRAG vec4 ColorFS;
VARYING_FRAG vec3 N;
void main()
{
gl_FragData[0] = ColorFS;
gl_FragData[1] = vec4( 0.5*normalize(N)+vec3(0.5), 1.0 );
}
// ShaderCustom::geometryShaderText
uniform float explode;
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 NormalMatrix;
uniform mat4 ModelViewMatrix;
uniform vec3 lightPosition;
uniform vec4 diffuse;
uniform vec4 ambient;
VARYING_OUT vec4 ColorFS;
VARYING_OUT vec3 N;
VARYING_OUT vec2 texCoord;
void main(void)
{
vec3 v1 = POSITION_IN(1).xyz - POSITION_IN(0).xyz;
vec3 v2 = POSITION_IN(2).xyz - POSITION_IN(0).xyz;
N = cross(v1,v2);
N = normalize (vec3(NormalMatrix*vec4(N,0.0)));
vec3 center = POSITION_IN(0).xyz + POSITION_IN(1).xyz + POSITION_IN(2).xyz;
center /= 3.0;
vec4 newPos = ModelViewMatrix * vec4(center,0.0);
vec3 L = normalize (lightPosition - newPos.xyz);
float lambertTerm = dot(N,L);
ColorFS = ambient;
if(lambertTerm > 0.0)
ColorFS += diffuse * lambertTerm;
int i;
for(i=0; i< NBVERTS_IN; i++)
{
vec4 pos = explode * POSITION_IN(i) + (1.0-explode)* vec4(center,1.0);
gl_Position = ModelViewProjectionMatrix * pos;
EmitVertex();
}
EndPrimitive();
}
#ifndef __SHADER_CUSTOM__
#define __SHADER_CUSTOM__
#include "Utils/GLSLShader.h"
#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"
using namespace CGoGN;
class ShaderCustom : public Utils::GLSLShader
{
protected:
// shader sources
static std::string vertexShaderText;
static std::string fragmentShaderText;
static std::string geometryShaderText;
// uniform locations
CGoGNGLuint m_unif_ambiant;
CGoGNGLuint m_unif_diffuse;
CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_explode;
float m_explode;
Geom::Vec4f m_ambiant;
Geom::Vec4f m_diffuse;
Geom::Vec3f m_light_pos;
Utils::VBO* m_vboPos;
void getLocations();
void restoreUniformsAttribs();
public:
ShaderCustom();
void setExplode(float explode);
void setAmbiant(const Geom::Vec4f& ambiant);
void setDiffuse(const Geom::Vec4f& diffuse);
void setLightPosition(const Geom::Vec3f& lp);
void setParams(float explode, const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec3f& lightPos);
unsigned int setAttributePosition(Utils::VBO* vbo);
void setTransformation(Geom::Matrix44f t);
};
#endif
// ShaderCustom::vertexShaderText
uniform mat4 TransformationMatrix;
uniform mat4 ModelViewProjectionMatrix;
ATTRIBUTE vec3 VertexPosition;
void main()
{
gl_Position = TransformationMatrix *vec4(VertexPosition, 1.0);
}
// ShaderCustomTex::fragmentShaderText
PRECISON;
uniform sampler2D textureUnit;
in vec3 N;
in vec2 fragTexCoord;
uniform vec4 ambient;
FRAG_OUT_DEF;
void main()
{
gl_FragData[0] = ambient*texture2D(textureUnit,fragTexCoord);
gl_FragData[1] = vec4( 0.5*normalize(N)+vec3(0.5), 1.0 );
}
\ No newline at end of file
// ShaderCustomTex::geometryShaderText
VARYING_IN vec2 texCoord[];
VARYING_IN vec3 Normal[];
VARYING_OUT vec2 fragTexCoord;
VARYING_OUT vec3 N;
void main(void)
{
//vec3 v1 = POSITION_IN(1).xyz - POSITION_IN(0).xyz;
//vec3 v2 = POSITION_IN(2).xyz - POSITION_IN(0).xyz;
//N = cross(v1,v2);
//N = normalize(N);
int i;
for(i=0; i< NBVERTS_IN; i++)
{
gl_Position = POSITION_IN(i);
fragTexCoord = texCoord[i];
N = Normal[i];
EmitVertex();
}
EndPrimitive();
}
#ifndef __SHADER_CUSTOMTEX__
#define __SHADER_CUSTOMTEX__
#include "Utils/GLSLShader.h"
#include "Geometry/vector_gen.h"
#include "Utils/clippingShader.h"
#include "Utils/textures.h"
#include "Utils/gl_def.h"
#include "Geometry/matrix.h"
using namespace CGoGN;
class ShaderCustomTex : public Utils::ClippingShader
{
protected:
// shader sources
static std::string vertexShaderText;
static std::string fragmentShaderText;
static std::string geometryShaderText;
CGoGNGLuint m_unif_unit;
int m_unit;
Geom::Vec4f m_col;
Utils::GTexture* m_tex_ptr;
Utils::VBO* m_vboPos;
Utils::VBO* m_vboNormal;
Utils::VBO* m_vboTexCoord;
void restoreUniformsAttribs();
public:
ShaderCustomTex();
/**
* choose the texture unit engine to use for this texture
*/
void setTextureUnit(GLenum texture_unit);
/**
* set the texture to use
*/
void setTexture(Utils::GTexture* tex);
/**
* activation of texture unit with set texture
*/
void activeTexture();
/**
* activation of texture unit with texture id
*/
void activeTexture(CGoGNGLuint texId);
unsigned int setAttributePosition(Utils::VBO* vbo);
unsigned int setAttributeNormal(Utils::VBO* vbo);
unsigned int setAttributeTexCoord(Utils::VBO* vbo);
void setBaseColor(Geom::Vec4f col);
void setTransformation(Geom::Matrix44f t);
};
#endif
// ShaderCustomTex::vertexShaderText
ATTRIBUTE vec3 VertexPosition, VertexNormal;
ATTRIBUTE vec2 VertexTexCoord;
uniform mat4 TransformationMatrix;
uniform mat4 ModelViewProjectionMatrix;
VARYING_VERT vec2 texCoord;
VARYING_VERT vec3 Normal;
INVARIANT_POS;
void main ()
{
Normal = vec3 (ModelViewProjectionMatrix * TransformationMatrix * vec4 (VertexNormal , 1.0));
gl_Position = ModelViewProjectionMatrix * TransformationMatrix * vec4 (VertexPosition, 1.0);
texCoord = VertexTexCoord;
}
//ShaderMatCustom::fragmentShaderText
PRECISON;
VARYING_FRAG vec3 EyeVector, Normal, LightDir;
#ifdef WITH_COLOR
VARYING_FRAG vec3 Color;
#endif
uniform vec4 materialDiffuse;
uniform vec4 materialSpecular;
uniform vec4 materialAmbient;
uniform float shininess;
FRAG_OUT_DEF;
void main()
{
vec3 N = normalize (Normal);
vec3 L = normalize (LightDir);
//float lambertTerm = dot(N,L);
float lambertTerm = 0.15*dot(N,L)+0.80;
vec4 finalColor = materialAmbient;
#ifdef DOUBLE_SIDED
if (lambertTerm < 0.0)
{
N = -1.0*N;
lambertTerm = -1.0*lambertTerm;
#else
if (lambertTerm > 0.0)
{
#endif
#ifndef WITH_COLOR
finalColor += materialDiffuse * lambertTerm;
#else
finalColor += vec4((Color*lambertTerm),0.0) ;
#endif
vec3 E = normalize(EyeVector);
vec3 R = reflect(-L, N);
float specular = pow( max(dot(R, E), 0.0), shininess );
finalColor += materialSpecular * specular;
}
gl_FragColor=finalColor;
//gl_FragColor = vec4(lambertTerm,lambertTerm,lambertTerm,0);
}
// ShaderMatCustom::geometryShaderText
uniform float explode;
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 NormalMatrix;
uniform mat4 ModelViewMatrix;
uniform vec3 lightPosition;
uniform vec4 diffuse;
uniform vec4 ambient;
//VARYING_OUT vec4 ColorFS;
VARYING_OUT vec3 N;
VARYING_OUT vec2 texCoord;
void main(void)
{
vec3 v1 = POSITION_IN(1).xyz - POSITION_IN(0).xyz;
vec3 v2 = POSITION_IN(2).xyz - POSITION_IN(0).xyz;
N = cross(v1,v2);
N = normalize (vec3(NormalMatrix*vec4(N,0.0)));
vec3 center = POSITION_IN(0).xyz + POSITION_IN(1).xyz + POSITION_IN(2).xyz;
center /= 3.0;
vec4 newPos = ModelViewMatrix * vec4(center,0.0);
vec3 L = normalize (lightPosition - newPos.xyz);
float lambertTerm = dot(N,L);
ColorFS = ambient;
if(lambertTerm > 0.0)
ColorFS += diffuse * lambertTerm;
int i;
for(i=0; i< NBVERTS_IN; i++)
{
vec4 pos = explode * POSITION_IN(i) + (1.0-explode)* vec4(center,1.0);
gl_Position = ModelViewProjectionMatrix * pos;
EmitVertex();
}
EndPrimitive();
}
#ifndef SHADER_MATCUST
#define SHADER_MATCUST
#include "Utils/GLSLShader.h"
#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"
#include <string>
using namespace CGoGN;
class ShaderMatCustom : public Utils::GLSLShader
{
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;
static std::string fragmentShaderText;
static std::string geometryShaderText;
// uniform locations
CGoGNGLuint m_unif_ambiant;
CGoGNGLuint m_unif_diffuse;
CGoGNGLuint m_unif_specular;
CGoGNGLuint m_unif_shininess;
CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_eyePos;
//values
Geom::Vec4f m_ambiant;
Geom::Vec4f m_diffuse;
Geom::Vec4f m_specular;
float m_shininess;
Geom::Vec3f m_lightPos;
Geom::Vec3f m_eyePos;
Utils::VBO* m_vboPos;
Utils::VBO* m_vboNormal;
Utils::VBO* m_vboColor;
void getLocations();
void sendParams();
void restoreUniformsAttribs();
public:
ShaderMatCustom(bool doubleSided = false, bool withEyePosition=false);
// inviduals parameter setting functions
void setAmbiant(const Geom::Vec4f& ambiant);
void setDiffuse(const Geom::Vec4f& diffuse);
void setSpecular(const Geom::Vec4f& specular);
void setShininess(float shininess);
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; }
const Geom::Vec4f& getDiffuse() const { return m_diffuse; }
const Geom::Vec4f& getSpecular() const { return m_specular; }
float getShininess() const { return m_shininess; }
const Geom::Vec3f& getLightPosition() const { return m_lightPos; }
/**
* set all parameter in on call (one bind also)
*/
void setParams(const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec4f& specular, float shininess, const Geom::Vec3f& lightPos);
// attributes
unsigned int setAttributePosition(Utils::VBO* vbo);
unsigned int setAttributeNormal(Utils::VBO* vbo);
// optional attributes
unsigned int setAttributeColor(::Utils::VBO* vbo);
void unsetAttributeColor();
void setTransformation(Geom::Matrix44f t);
};
#endif
//ShaderMatCustom::vertexShaderText
ATTRIBUTE vec3 VertexPosition, VertexNormal;
#ifdef WITH_COLOR
ATTRIBUTE vec3 VertexColor;
#endif
uniform mat4 TransformationMatrix;
uniform mat4 ModelViewProjectionMatrix;
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 * TransformationMatrix * vec4 (VertexNormal, 0.0));
vec3 Position = vec3 (ModelViewMatrix * TransformationMatrix * vec4 (VertexPosition, 1.0));
LightDir = lightPosition - Position;
#ifdef WITH_EYEPOSITION
EyeVector = eyePosition-Position;
#else
EyeVector = -Position;
#endif
#ifdef WITH_COLOR
Color = VertexColor;
#endif
gl_Position = ModelViewProjectionMatrix * (TransformationMatrix * vec4 (VertexPosition, 1.0));
}
......@@ -70,25 +70,26 @@ public:
void rotate(float angle, const Geom::Vec3f& Axis)
{
glm::mat4 X = glm::rotate(m_matrices[2], angle, glm::vec3(Axis[0],Axis[1],Axis[2])) * m_matrices[2];
glm::mat4 X = glm::rotate(glm::mat4(1.f), angle, glm::vec3(Axis[0],Axis[1],Axis[2])) * m_matrices[2];
m_matrices[2] = X;
}
void translate(const Geom::Vec3f& P)
{
glm::mat4 X = glm::translate(m_matrices[2], glm::vec3(P[0],P[1],P[2])) * m_matrices[2];
glm::mat4 X = glm::translate(glm::mat4(1.f), glm::vec3(P[0],P[1],P[2])) * m_matrices[2];
m_matrices[2] = X;
}
void scale(const Geom::Vec3f& S)
{
glm::mat4 X = glm::scale(m_matrices[2], glm::vec3(S[0],S[1],S[2])) * m_matrices[2];
glm::mat4 X = glm::scale(glm::mat4(1.f), glm::vec3(S[0],S[1],S[2])) * m_matrices[2];
m_matrices[2] = X;
}
void scale(float s)
{
glm::mat4 X = glm::scale(m_matrices[2], glm::vec3(s,s,s)) * m_matrices[2];
glm::mat4 X = glm::scale(glm::mat4(1.f), glm::vec3(s,s,s)) * m_matrices[2];
m_matrices[2] = X;
}
......
#include <string.h>
#include "Utils/Shaders/shaderCustom.h"
#include "shaderCustom.vert"
#include "shaderCustom.frag"
#include "shaderCustom.geom"
ShaderCustom::ShaderCustom()
{
m_nameVS = "ShaderCustom_vs";
m_nameFS = "ShaderCustom_fs";
m_nameGS = "ShaderCustom_gs";
std::string glxvert(*GLSLShader::DEFINES_GL);
glxvert.append(vertexShaderText);
std::string glxgeom = GLSLShader::defines_Geom("triangles", "triangle_strip", 3);
glxgeom.append(geometryShaderText);
std::string glxfrag(*GLSLShader::DEFINES_GL);
glxfrag.append(fragmentShaderText);
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_TRIANGLES, GL_TRIANGLE_STRIP, 3);
bind();
getLocations();
unbind();
//Default values
m_explode = 1.0f;
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_light_pos = Geom::Vec3f(10.0f, 10.0f, 1000.0f);
Geom::Matrix44f id;
id.identity();
setTransformation(id);
setParams(m_explode, m_ambiant, m_diffuse, m_light_pos);
}
void ShaderCustom::getLocations()
{
*m_unif_explode = glGetUniformLocation(program_handler(), "explode");
*m_unif_ambiant = glGetUniformLocation(program_handler(), "ambient");
*m_unif_diffuse = glGetUniformLocation(program_handler(), "diffuse");
*m_unif_lightPos = glGetUniformLocation(program_handler(), "lightPosition");
}
unsigned int ShaderCustom::setAttributePosition(Utils::VBO* vbo)
{
m_vboPos = vbo;
bind();
unsigned int id = bindVA_VBO("VertexPosition", vbo);
unbind();
return id;
}
void ShaderCustom::setParams(float expl, const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec3f& lightPos)
{
m_explode = expl;
m_ambiant = ambiant;
m_diffuse = diffuse;
m_light_pos = lightPos;
bind();
glUniform1f(*m_unif_explode, expl);
glUniform4fv(*m_unif_ambiant, 1, ambiant.data());
glUniform4fv(*m_unif_diffuse, 1, diffuse.data());
glUniform3fv(*m_unif_lightPos, 1, lightPos.data());
unbind();
}
void ShaderCustom::setExplode(float explode)
{
m_explode = explode;
bind();
glUniform1f(*m_unif_explode, explode);
unbind();
}
void ShaderCustom::setAmbiant(const Geom::Vec4f& ambiant)
{
m_ambiant = ambiant;
bind();
glUniform4fv(*m_unif_ambiant,1, ambiant.data());
unbind();
}
void ShaderCustom::setDiffuse(const Geom::Vec4f& diffuse)
{
m_diffuse = diffuse;
bind();
glUniform4fv(*m_unif_diffuse,1, diffuse.data());
unbind();
}
void ShaderCustom::setLightPosition(const Geom::Vec3f& lp)
{
m_light_pos = lp;
bind();
glUniform3fv(*m_unif_lightPos,1,lp.data());
unbind();
}
void ShaderCustom::restoreUniformsAttribs()
{
*m_unif_explode = glGetUniformLocation(program_handler(),"explode");
*m_unif_ambiant = glGetUniformLocation(program_handler(),"ambient");
*m_unif_diffuse = glGetUniformLocation(program_handler(),"diffuse");
*m_unif_lightPos = glGetUniformLocation(program_handler(),"lightPosition");
bind();
glUniform1f (*m_unif_explode, m_explode);
glUniform4fv(*m_unif_ambiant, 1, m_ambiant.data());
glUniform4fv(*m_unif_diffuse, 1, m_diffuse.data());
glUniform3fv(*m_unif_lightPos, 1, m_light_pos.data());
bindVA_VBO("VertexPosition", m_vboPos);
unbind();
}
void ShaderCustom::setTransformation(Geom::Matrix44f t)
{
bind();
CGoGNGLuint m_transf;
*m_transf = glGetUniformLocation(program_handler(),"TransformationMatrix");
glUniformMatrix4fv(*m_transf, 1, false, &t(0,0));
unbind();
}
/*******************************************************************************
* 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 *
* *
*******************************************************************************/
#include <GL/glew.h>
#include "Utils/Shaders/shaderCustomTex.h"
#include "shaderCustomTex.vert"
#include "shaderCustomTex.frag"
#include "shaderCustomTex.geom"
//std::string ShaderCustomTex::vertexShaderText =
// "ATTRIBUTE vec3 VertexPosition;\n"
// "ATTRIBUTE vec2 VertexTexCoord;\n"
// "uniform mat4 ModelViewProjectionMatrix;\n"
// "VARYING_VERT vec2 texCoord;\n"
// "INVARIANT_POS;\n"
// "void main ()\n"
// "{\n"
// " gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);\n"