Commit 2433e28a authored by Sylvain Thery's avatar Sylvain Thery

debug Sprite Rendering on VRjuggler

parent 0fe57133
......@@ -87,10 +87,10 @@ public:
void setShininess(float shininess);
void setLightPosition(Geom::Vec3f lp);
void setLightPosition(const Geom::Vec3f& lp);
/// set eye position for VR environement
void setEyePosition(Geom::Vec3f ep);
void setEyePosition(const Geom::Vec3f& ep);
const Geom::Vec4f& getAmbiant() const { return m_ambiant; }
......
......@@ -19,8 +19,10 @@ void main(void)
if (lum==0.0)
discard;
vec2 v = texCoord-vec2(0.5,0.5);
#ifndef WITH_PLANE
float z = size * sqrt(1.0-dot(v,v));
vec2 zfrag = positionFragIn + vec2(z,0.0);
gl_FragDepth = 0.5 + 0.5 * dot(zfrag, mvpFragIn.xy) / dot(zfrag, mvpFragIn.zw);
#endif
gl_FragColor = vec4(colorsprite,0.0)*lum;
}
......@@ -34,35 +34,35 @@ void main()
texCoord = vec2(0.0,1.0);
#ifdef WITH_PLANE
vec4 pos = posCenter + vec4(-size, size, 0.0, 0.0);
vec4 pos = posCenter - size*vec4(planeX,0.0) + size*vec4(planeY,0.0) + size*vec4(0.0,0.0,0.5,0.0);
#else
vec4 pos = posCenter - vec4(planeX,0.0) + vec4(planeY,0.0)
vec4 pos = posCenter + vec4(-size, size, 0.0, 0.0);
#endif
gl_Position = ProjectionMatrix * pos;
EmitVertex();
#ifdef WITH_PLANE
pos = posCenter + vec4(-size, -size, 0.0, 0.0);
pos = posCenter - size*vec4(planeX,0.0) - size*vec4(planeY,0.0) + size*vec4(0.0,0.0,0.5,0.0);
#else
pos = posCenter - vec4(planeX,0.0) - vec4(planeY,0.0)
pos = posCenter + vec4(-size, -size, 0.0, 0.0);
#endif
texCoord = vec2(0.0,0.0);
gl_Position = ProjectionMatrix * pos;
EmitVertex();
#ifdef WITH_PLANE
pos = posCenter + vec4(size, size, 0.0, 0.0);
pos = posCenter + size*vec4(planeX,0.0) + size*vec4(planeY,0.0) + size*vec4(0.0,0.0,0.5,0.0);
#else
pos = posCenter + vec4(planeX,0.0) + vec4(planeY,0.0)
pos = posCenter + vec4(size, size, 0.0, 0.0);
#endif
texCoord = vec2(1.0,1.0);
gl_Position = ProjectionMatrix * pos;
EmitVertex();
#ifdef WITH_PLANE
pos = posCenter + vec4(size, -size, 0.0, 0.0);
pos = posCenter + size*vec4(planeX,0.0) - size*vec4(planeY,0.0) + size*vec4(0.0,0.0,0.5,0.0);
#else
pos = posCenter + vec4(planeX,0.0) - vec4(planeY,0.0)
pos = posCenter + vec4(size, -size, 0.0, 0.0);
#endif
texCoord = vec2(1.0,0.0);
gl_Position = ProjectionMatrix * pos;
......
......@@ -36,7 +36,7 @@ namespace Utils
ShaderPhong::ShaderPhong(bool doubleSided, bool withEyePosition):
m_with_color(false),
m_with_eyepos(false),
m_with_eyepos(withEyePosition),
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)),
......@@ -121,14 +121,14 @@ void ShaderPhong::setShininess(float shininess)
m_shininess = shininess;
}
void ShaderPhong::setLightPosition( Geom::Vec3f lightPos)
void ShaderPhong::setLightPosition(const Geom::Vec3f& lightPos)
{
this->bind();
glUniform3fv(*m_unif_lightPos,1,lightPos.data());
m_lightPos = lightPos;
}
void ShaderPhong::setEyePosition( Geom::Vec3f eyePos)
void ShaderPhong::setEyePosition(const Geom::Vec3f& eyePos)
{
if (m_with_eyepos)
{
......
......@@ -53,11 +53,16 @@ PointSprite::PointSprite(bool withColorPervertex, float radius, bool with_plane
std::string glxgeom = GLSLShader::defines_Geom("points","triangle_strip",4);
if (withColorPervertex)
glxgeom.append(defineColor);
if (with_plane)
glxgeom.append("#define WITH_PLANE 1\n");
glxgeom.append(geometryShaderText);
std::string glxfrag(*GLSLShader::DEFINES_GL);
if (withColorPervertex)
glxfrag.append(defineColor);
if (with_plane)
glxfrag.append("#define WITH_PLANE 1\n");
glxfrag.append(fragmentShaderText);
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_POINTS, GL_TRIANGLE_STRIP,4);
......@@ -85,6 +90,12 @@ PointSprite::PointSprite(bool withColorPervertex, float radius, bool with_plane
}
*m_uniform_texture = glGetUniformLocation(program_handler(),"SpriteTexture");
if (with_plane)
{
*m_uniform_planeX = glGetUniformLocation(program_handler(),"planeX");
*m_uniform_planeY = glGetUniformLocation(program_handler(),"planeY");
}
}
PointSprite::~PointSprite()
......@@ -138,6 +149,15 @@ void PointSprite::setSize(float radius)
unbind();
}
void PointSprite::setPlane(const Geom::Vec3f& ox, const Geom::Vec3f& oy)
{
bind();
glUniform3fv(*m_uniform_planeX, 1, ox.data());
glUniform3fv(*m_uniform_planeY, 1, oy.data());
unbind();
}
void PointSprite::computeSphere()
{
if (m_ptrSphere == NULL) // normally useless
......
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