Commit cd9d75b8 authored by Sylvain's avatar Sylvain

Modification for VR rendering

parent 333cfee2
......@@ -42,6 +42,8 @@ class ShaderPhong : public ClippingShader
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;
......@@ -53,6 +55,7 @@ protected:
CGoGNGLuint m_unif_specular;
CGoGNGLuint m_unif_shininess;
CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_eyePos;
//values
Geom::Vec4f m_ambiant;
......@@ -60,6 +63,7 @@ protected:
Geom::Vec4f m_specular;
float m_shininess;
Geom::Vec3f m_lightPos;
Geom::Vec3f m_eyePos;
VBO* m_vboPos;
VBO* m_vboNormal;
......@@ -72,7 +76,7 @@ protected:
void restoreUniformsAttribs();
public:
ShaderPhong(bool doubleSided = false);
ShaderPhong(bool doubleSided = false, bool withEyePosition=false);
// inviduals parameter setting functions
void setAmbiant(const Geom::Vec4f& ambiant);
......@@ -84,6 +88,9 @@ public:
void setShininess(float shininess);
void setLightPosition(Geom::Vec3f lp);
/// set eye position for VR environement
void setEyePosition(Geom::Vec3f ep);
const Geom::Vec4f& getAmbiant() const { return m_ambiant; }
......
......@@ -9,18 +9,28 @@ 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 * vec4 (VertexNormal, 0.0));
vec3 Position = vec3 (ModelViewMatrix * vec4 (VertexPosition, 1.0));
LightDir = lightPosition - Position;
EyeVector = -Position;
#ifdef WITH_EYEPOSITION
EyeVector = eyePosition-Position;
#else
EyeVector = -Position;
#endif
#ifdef WITH_COLOR
Color = VertexColor;
Color = VertexColor;
#endif
gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);
}
......@@ -12,31 +12,58 @@ VARYING_OUT vec4 mvpFragIn;
VARYING_OUT vec3 colorsprite;
#endif
#ifdef WITH_PLANE
uniform vec3 planeX;
uniform vec3 planeY;
#endif
void main()
{
vec4 posCenter = ModelViewMatrix * POSITION_IN(0);
vec4 pos = posCenter + vec4(-size, size, 0.0, 0.0);
positionFragIn = posCenter.zw;
#ifdef WITH_COLOR_PER_VERTEX
colorsprite = color[0];
#endif
mvpFragIn.x = ProjectionMatrix[2][2];
mvpFragIn.y = ProjectionMatrix[3][2];
mvpFragIn.z = ProjectionMatrix[2][3];
mvpFragIn.w = ProjectionMatrix[3][3];
texCoord = vec2(0.0,1.0);
vec4 posCenter = ModelViewMatrix * POSITION_IN(0);
positionFragIn = posCenter.zw;
#ifdef WITH_COLOR_PER_VERTEX
colorsprite = color[0];
#endif
texCoord = vec2(0.0,1.0);
#ifdef WITH_PLANE
vec4 pos = posCenter + vec4(-size, size, 0.0, 0.0);
#else
vec4 pos = posCenter - vec4(planeX,0.0) + vec4(planeY,0.0)
#endif
gl_Position = ProjectionMatrix * pos;
EmitVertex();
pos = posCenter + vec4(-size, -size, 0.0, 0.0);
#ifdef WITH_PLANE
pos = posCenter + vec4(-size, -size, 0.0, 0.0);
#else
pos = posCenter - vec4(planeX,0.0) - vec4(planeY,0.0)
#endif
texCoord = vec2(0.0,0.0);
gl_Position = ProjectionMatrix * pos;
EmitVertex();
pos = posCenter + vec4( size, size, 0.0, 0.0);
#ifdef WITH_PLANE
pos = posCenter + vec4(size, size, 0.0, 0.0);
#else
pos = posCenter + vec4(planeX,0.0) + vec4(planeY,0.0)
#endif
texCoord = vec2(1.0,1.0);
gl_Position = ProjectionMatrix * pos;
EmitVertex();
pos = posCenter + vec4( size,-size, 0.0, 0.0);
#ifdef WITH_PLANE
pos = posCenter + vec4(size, -size, 0.0, 0.0);
#else
pos = posCenter + vec4(planeX,0.0) - vec4(planeY,0.0)
#endif
texCoord = vec2(1.0,0.0);
gl_Position = ProjectionMatrix * pos;
EmitVertex();
......
......@@ -61,6 +61,12 @@ protected:
CGoGNGLuint m_idTexture;
CGoGNGLuint m_uniform_texture;
CGoGNGLuint m_uniform_texture;
CGoGNGLuint m_uniform_planeX;
CGoGNGLuint m_uniform_planeY;
public:
/**
......@@ -69,7 +75,7 @@ public:
* @param radius of sphere
*/
PointSprite(bool withColorPerVertex=false, float radius=1.0f);
PointSprite(bool withColorPerVertex=false, float radius=1.0f, bool with_plane=false);
/**
* clean shaders, texture and variables
......@@ -97,6 +103,12 @@ public:
* @param radius
*/
void setSize(float radius);
/**
* set the plane of rendering for VR rendering
*/
void setPlane(const Geom::Vec3f& ox, const Geom::Vec3f& ox);
/**
* set position attribute
......
......@@ -80,9 +80,13 @@ protected:
CGoGNGLuint m_uniform_position;
CGoGNGLuint m_uniform_color;
CGoGNGLuint m_uniform_planeX;
CGoGNGLuint m_uniform_planeY;
public:
Strings3D(bool withBackground = true, const Geom::Vec3f& bgc = Geom::Vec3f(0));
Strings3D(bool withBackground = true, const Geom::Vec3f& bgc = Geom::Vec3f(0), bool with_plane=false);
~Strings3D();
......@@ -112,7 +116,7 @@ public:
void sendToVBO();
/**
* draw on string
* draw one string
* @param idSt the id of string
* @param pos the position of text
*/
......@@ -140,6 +144,11 @@ public:
* @param scale
*/
void setScale(float scale);
/**
* set the plane of rendering for VR rendering
*/
void setPlane(const Geom::Vec3f& ox, const Geom::Vec3f& ox);
void toSVG(Utils::SVG::SVGOut& svg);
......
......@@ -7,9 +7,22 @@ uniform vec3 strPos;
uniform float scale;
VARYING_VERT vec2 tex_coord;
INVARIANT_POS;
#ifdef WITH_PLANE
uniform vec3 planeX;
uniform vec3 planeY;
#endif
void main ()
{
#ifdef WITH_PLANE
vec4 pos = ModelViewMatrix * vec4(strPos,1.0);
pos += scale*VertexPosition[0]*vec4(planeX,0.0);
pos += scale*VertexPosition[1]*vec4(planeY,0.0);
#else
vec4 pos = ModelViewMatrix * vec4(strPos,1.0) + vec4(VertexPosition[0]*scale,VertexPosition[1]*scale,0.0,0.0);
#endif
tex_coord = vec2(VertexPosition[2],VertexPosition[3]);
gl_Position = ProjectionMatrix * pos;
}
......
......@@ -34,8 +34,9 @@ namespace Utils
#include "shaderPhong.frag"
ShaderPhong::ShaderPhong(bool doubleSided):
ShaderPhong::ShaderPhong(bool doubleSided, bool withEyePosition):
m_with_color(false),
m_with_eyepos(false),
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_specular(Geom::Vec4f(1.0f,1.0f,1.0f,0.0f)),
......@@ -43,7 +44,7 @@ ShaderPhong::ShaderPhong(bool doubleSided):
m_lightPos(Geom::Vec3f(10.0f,10.0f,1000.0f)),
m_vboPos(NULL),
m_vboNormal(NULL),
m_vboColor(NULL)
m_vboColor(NULL),
{
m_nameVS = "ShaderPhong_vs";
......@@ -53,6 +54,8 @@ ShaderPhong::ShaderPhong(bool doubleSided):
// get choose GL defines (2 or 3)
// ans compile shaders
std::string glxvert(*GLSLShader::DEFINES_GL);
if (m_with_eyepos)
glxvert.append("#define WITH_EYEPOSITION");
glxvert.append(vertexShaderText);
std::string glxfrag(*GLSLShader::DEFINES_GL);
// Use double sided lighting if set
......@@ -75,6 +78,8 @@ void ShaderPhong::getLocations()
*m_unif_specular = glGetUniformLocation(this->program_handler(), "materialSpecular");
*m_unif_shininess = glGetUniformLocation(this->program_handler(), "shininess");
*m_unif_lightPos = glGetUniformLocation(this->program_handler(), "lightPosition");
if (m_with_eyepos)
*m_unif_eyePos = glGetUniformLocation(this->program_handler(), "eyePosition");
}
void ShaderPhong::sendParams()
......@@ -84,6 +89,8 @@ void ShaderPhong::sendParams()
glUniform4fv(*m_unif_specular, 1, m_specular.data());
glUniform1f(*m_unif_shininess, m_shininess);
glUniform3fv(*m_unif_lightPos, 1, m_lightPos.data());
if (m_with_eyepos)
glUniform3fv(*m_unif_eyePos, 1, m_eyePos.data());
}
void ShaderPhong::setAmbiant(const Geom::Vec4f& ambiant)
......@@ -121,6 +128,16 @@ void ShaderPhong::setLightPosition( Geom::Vec3f lightPos)
m_lightPos = lightPos;
}
void ShaderPhong::setEyePosition( Geom::Vec3f eyePos)
{
if (m_with_eyepos)
{
this->bind();
glUniform3fv(*m_unif_eyetPos,1,eyePos.data());
m_eyePos = eyePos;
}
}
void ShaderPhong::setParams(const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec4f& specular, float shininess, const Geom::Vec3f& lightPos)
{
m_ambiant = ambiant;
......
......@@ -43,7 +43,7 @@ std::string Strings3D::fragmentShaderText2 =
Strings3D* Strings3D::m_instance0 = NULL;
Strings3D::Strings3D(bool withBackground, const Geom::Vec3f& bgc) : m_nbChars(0),m_scale(1.0f)
Strings3D::Strings3D(bool withBackground, const Geom::Vec3f& bgc, bool with_plane) : m_nbChars(0),m_scale(1.0f)
{
if (m_instance0 == NULL)
{
......@@ -67,6 +67,8 @@ Strings3D::Strings3D(bool withBackground, const Geom::Vec3f& bgc) : m_nbChars(0)
}
std::string glxvert(*GLSLShader::DEFINES_GL);
if (with_plane)
glxverte.append("#define WITH_PLANE 1")
glxvert.append(vertexShaderText);
std::string glxfrag(*GLSLShader::DEFINES_GL);
......@@ -98,6 +100,11 @@ Strings3D::Strings3D(bool withBackground, const Geom::Vec3f& bgc) : m_nbChars(0)
*m_uniform_scale = glGetUniformLocation(program_handler(), "scale");
*m_uniform_texture = glGetUniformLocation(program_handler(), "FontTexture");
glUniform1f(*m_uniform_scale, 1.0f);
if (with_plane)
{
*m_uniform_planeX = glGetUniformLocation(program_handler(), "planeX");
*m_uniform_planeY = glGetUniformLocation(program_handler(), "planeY");
}
unbind();
}
......@@ -109,6 +116,14 @@ void Strings3D::setScale(float scale)
unbind();
}
void Strings3D::setPlane(const Geom::Vec3f& ox, const Geom::Vec3f& ox)
{
bind();
glUniform3f(*m_uniform_planeX, ox);
glUniform3f(*m_uniform_planeY, oy);
unbind();
}
Strings3D::~Strings3D()
{
}
......
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