Commit 72f0a449 authored by Sylvain Thery's avatar Sylvain Thery

add clipping plane to pointSprite

parent 77aaa844
...@@ -67,6 +67,9 @@ public: ...@@ -67,6 +67,9 @@ public:
unsigned int setAttributePosition(VBO* vbo); unsigned int setAttributePosition(VBO* vbo);
void setClippingPlane(const Geom::Vec4f& plane); void setClippingPlane(const Geom::Vec4f& plane);
inline void setNoClippingPlane() { setClippingPlane(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f)); }
}; };
} // namespace Utils } // namespace Utils
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
uniform float size; uniform float size;
uniform mat4 ModelViewMatrix; uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix; uniform mat4 ProjectionMatrix;
uniform vec4 planeClip;
VARYING_IN vec3 posClip[1];
#ifdef WITH_PLANE #ifdef WITH_PLANE
uniform vec3 eyePos; uniform vec3 eyePos;
...@@ -37,10 +40,11 @@ void corner( vec4 center, float x, float y) ...@@ -37,10 +40,11 @@ void corner( vec4 center, float x, float y)
void main() void main()
{ {
if (dot(planeClip,vec4(posClip[0],1.0))<0.0)
{
#ifdef WITH_COLOR_PER_VERTEX #ifdef WITH_COLOR_PER_VERTEX
colorsprite = color[0]; colorsprite = color[0];
#endif #endif
vec4 posCenter = ModelViewMatrix * POSITION_IN(0); vec4 posCenter = ModelViewMatrix * POSITION_IN(0);
sphereCenter = posCenter.xyz; sphereCenter = posCenter.xyz;
...@@ -65,5 +69,6 @@ void main() ...@@ -65,5 +69,6 @@ void main()
#endif #endif
EndPrimitive(); EndPrimitive();
}
} }
...@@ -63,6 +63,11 @@ protected: ...@@ -63,6 +63,11 @@ protected:
Geom::Vec3f m_ambiant; Geom::Vec3f m_ambiant;
Geom::Vec3f m_eyePos; Geom::Vec3f m_eyePos;
/// clipping
CGoGNGLuint m_unif_planeClip;
Geom::Vec4f m_planeClip;
void getLocations(); void getLocations();
void sendParams(); void sendParams();
...@@ -93,6 +98,11 @@ public: ...@@ -93,6 +98,11 @@ public:
* set the plane of rendering for VR rendering * set the plane of rendering for VR rendering
*/ */
void setEyePosition(const Geom::Vec3f& ep); void setEyePosition(const Geom::Vec3f& ep);
void setClippingPlane(const Geom::Vec4f& plane);
inline void setNoClippingPlane() { setClippingPlane(Geom::Vec4f(0.0f,0.0f,0.0f,0.0f)); }
}; };
} // namespace Utils } // namespace Utils
......
...@@ -6,8 +6,11 @@ ATTRIBUTE vec3 VertexPosition; ...@@ -6,8 +6,11 @@ ATTRIBUTE vec3 VertexPosition;
VARYING_VERT vec4 color; VARYING_VERT vec4 color;
#endif #endif
VARYING_VERT vec3 posClip;
void main () void main ()
{ {
posClip = VertexPosition;
gl_Position = vec4(VertexPosition, 1.0); gl_Position = vec4(VertexPosition, 1.0);
#ifdef WITH_COLOR_PER_VERTEX #ifdef WITH_COLOR_PER_VERTEX
color = VertexColor; color = VertexColor;
......
...@@ -79,6 +79,7 @@ void PointSprite::getLocations() ...@@ -79,6 +79,7 @@ void PointSprite::getLocations()
*m_uniform_lightPos = glGetUniformLocation(program_handler(),"lightPos"); *m_uniform_lightPos = glGetUniformLocation(program_handler(),"lightPos");
if (plane) if (plane)
*m_uniform_eyePos = glGetUniformLocation(program_handler(),"eyePos"); *m_uniform_eyePos = glGetUniformLocation(program_handler(),"eyePos");
*m_unif_planeClip = glGetUniformLocation(this->program_handler(), "planeClip");
unbind(); unbind();
} }
...@@ -92,6 +93,8 @@ void PointSprite::sendParams() ...@@ -92,6 +93,8 @@ void PointSprite::sendParams()
glUniform3fv(*m_uniform_lightPos, 1, m_lightPos.data()); glUniform3fv(*m_uniform_lightPos, 1, m_lightPos.data());
if (plane) if (plane)
glUniform3fv(*m_uniform_eyePos, 1, m_eyePos.data()); glUniform3fv(*m_uniform_eyePos, 1, m_eyePos.data());
if (*m_unif_planeClip > 0)
glUniform4fv(*m_unif_planeClip, 1, m_planeClip.data());
unbind(); unbind();
} }
...@@ -163,6 +166,15 @@ void PointSprite::setEyePosition(const Geom::Vec3f& ep) ...@@ -163,6 +166,15 @@ void PointSprite::setEyePosition(const Geom::Vec3f& ep)
} }
} }
void PointSprite::setClippingPlane(const Geom::Vec4f& plane)
{
m_planeClip = plane;
bind();
glUniform4fv(*m_unif_planeClip, 1, plane.data());
unbind();
}
void PointSprite::restoreUniformsAttribs() void PointSprite::restoreUniformsAttribs()
{ {
getLocations(); getLocations();
......
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