Commit d8af79ed authored by Sylvain Thery's avatar Sylvain Thery

PointSprite:raytracing instead of texture

parent c2668883
......@@ -67,6 +67,8 @@ public:
* set opacity (0=transparent / 1=opaque)
*/
void setOpacity(float op);
float getOpacity() const { return m_opacity;}
};
} // namespace Utils
......
......@@ -36,6 +36,8 @@ namespace Utils
/**
* Shader to draw iso-lines on a triangles mesh.
* Iso-line are computed on a data vertex attribute (float)
* nb iso-lines, min/max attributes value and colors can be changed on the fly
* For better rendering result use glEnable(GL_LINE_SMOOTH)
*/
class ShaderIsoLines : public GLSLShader
{
......@@ -83,11 +85,10 @@ public:
void setColors(const Geom::Vec4f& colorMin, const Geom::Vec4f& colorMax);
/**
* Set min and max value of used atribute
* Set min and max value of used atribute.
* @param attMin minimun of attribute
* @param attMax maximun of attribute
*/
void setDataBound(float attMin, float attMax);
/**
......
// PointSprite::fragmentShaderText
uniform sampler2D SpriteTexture;
uniform mat4 ProjectionMatrix;
uniform vec3 lightPos;
uniform vec3 ambiant;
uniform float size;
#ifdef WITH_PLANE
uniform vec3 eyePos;
uniform vec3 eyeY;
VARYING_FRAG vec3 eyePosFrag;
#endif
#ifdef WITH_COLOR_PER_VERTEX
VARYING_FRAG vec3 colorsprite;
......@@ -11,18 +19,36 @@ uniform float size;
VARYING_FRAG vec2 texCoord;
VARYING_FRAG vec2 positionFragIn;
VARYING_FRAG vec4 mvpFragIn;
VARYING_FRAG vec3 sphereCenter;
void main(void)
{
float lum = texture2D(SpriteTexture, texCoord).s;
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);
vec3 billboard_frag_pos = sphereCenter + vec3(texCoord, 0.0) * size;
#ifdef WITH_PLANE
vec3 ray_direction = normalize(billboard_frag_pos - eyePosFrag;);
#else
vec3 ray_direction = normalize(billboard_frag_pos);
#endif
gl_FragColor = vec4(colorsprite,0.0)*lum;
float TD = -dot(ray_direction,sphereCenter);
float c = dot(sphereCenter, sphereCenter) - size * size;
float arg = TD * TD - c;
if (arg < 0.0)
discard;
float t = -c / (TD - sqrt(arg));
vec3 frag_position_eye = ray_direction * t;
vec4 pos = ProjectionMatrix * vec4(frag_position_eye, 1.0);
gl_FragDepth = (pos.z / pos.w + 1.0) / 2.0;
vec3 N = normalize(frag_position_eye - sphereCenter);
vec3 L = normalize (lightPos - frag_position_eye);
float lambertTerm = dot(N,L);
gl_FragColor = vec4(colorsprite*lambertTerm + ambiant ,1.0);
}
......@@ -3,18 +3,35 @@
uniform float size;
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix;
VARYING_OUT vec2 texCoord;
VARYING_OUT vec2 positionFragIn;
VARYING_OUT vec4 mvpFragIn;
#ifdef WITH_PLANE
uniform vec3 eyePos;
uniform vec3 eyeY;
VARYING_OUT vec4 eyePosFrag;
#endif
VARYING_OUT vec2 texCoord;
VARYING_OUT vec3 sphereCenter;
#ifdef WITH_COLOR_PER_VERTEX
VARYING_IN vec3 color[1];
VARYING_OUT vec3 colorsprite;
#endif
#ifdef WITH_PLANE
uniform vec3 planeX;
uniform vec3 planeY;
void corner( vec4 center, vec3 planeX, vec3 planeY, float x, float y)
{
texCoord = vec2(1.4*x,1.4*y);
vec4 pos = center + size( x*vec4(planeX,0.0) + y*vec4(planeY,0.0)+ vec4(0.0,0.0,0.5,0.0));
gl_Position = ProjectionMatrix * pos;
EmitVertex();
}
#else
void corner( vec4 center, float x, float y)
{
texCoord = vec2(1.4*x,1.4*y);
vec4 pos = center + vec4( size*x, size*y, 0.0, 0.0);
gl_Position = ProjectionMatrix * pos;
EmitVertex();
}
#endif
void main()
......@@ -24,48 +41,29 @@ void main()
colorsprite = color[0];
#endif
mvpFragIn.x = ProjectionMatrix[2][2];
mvpFragIn.y = ProjectionMatrix[3][2];
mvpFragIn.z = ProjectionMatrix[2][3];
mvpFragIn.w = ProjectionMatrix[3][3];
vec4 posCenter = ModelViewMatrix * POSITION_IN(0);
positionFragIn = posCenter.zw;
texCoord = vec2(0.0,1.0);
#ifdef WITH_PLANE
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(-size, size, 0.0, 0.0);
#endif
gl_Position = ProjectionMatrix * pos;
EmitVertex();
sphereCenter = posCenter.xyz;
#ifdef WITH_PLANE
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(-size, -size, 0.0, 0.0);
#endif
texCoord = vec2(0.0,0.0);
gl_Position = ProjectionMatrix * pos;
EmitVertex();
#ifdef WITH_PLANE
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(size, size, 0.0, 0.0);
#endif
texCoord = vec2(1.0,1.0);
gl_Position = ProjectionMatrix * pos;
EmitVertex();
#ifdef WITH_PLANE
vec4 EPF = ModelViewMatrix * vec4(eyePos,1.0);
eyePosFrag = EPF.xyz;
#ifdef WITH_PLANE
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(size, -size, 0.0, 0.0);
#endif
texCoord = vec2(1.0,0.0);
gl_Position = ProjectionMatrix * pos;
EmitVertex();
vec3 V = sphereCenter-eyePosFrag;
V.normalize();
vec3 planeX = cross(V, eyeY);
vec3 planeY = cross(X,V);
corner(posCenter, planeX, planeY, -1.0, 1.0);
corner(posCenter, planeX, planeY, -1.0,-1.0);
corner(posCenter, planeX, planeY, 1.0, 1.0);
corner(posCenter, planeX, planeY, 1.0,-1.0);
#else
corner(posCenter, -1.0, 1.0);
corner(posCenter, -1.0,-1.0);
corner(posCenter, 1.0, 1.0);
corner(posCenter, 1.0,-1.0);
#endif
EndPrimitive();
}
......@@ -62,9 +62,13 @@ protected:
CGoGNGLuint m_uniform_texture;
CGoGNGLuint m_uniform_planeX;
CGoGNGLuint m_uniform_EyePos;
CGoGNGLuint m_uniform_planeY;
CGoGNGLuint m_uniform_EyeY;
CGoGNGLuint m_uniform_ambiant;
CGoGNGLuint m_uniform_lightPos;
public:
/**
......@@ -105,7 +109,7 @@ public:
/**
* set the plane of rendering for VR rendering
*/
void setPlane(const Geom::Vec3f& ox, const Geom::Vec3f& oy);
void setEyePosition(const Geom::Vec3f& ox, const Geom::Vec3f& oy);
/**
......@@ -117,6 +121,12 @@ public:
* set color attribute
*/
unsigned int setAttributeColor(VBO* vbo);
void setLightPosition(const Geom::Vec3f& pos);
void setAmbiantColor(const Geom::Vec3f& amb);
};
} // namespace Utils
......
......@@ -45,7 +45,7 @@ ShaderExplodeVolumesLines::ShaderExplodeVolumesLines()
std::string glxvert(*GLSLShader::DEFINES_GL);
glxvert.append(vertexShaderText);
std::string glxgeom(GLSLShader::defines_Geom("triangles", "triangle_strip", 4));
std::string glxgeom(GLSLShader::defines_Geom("triangles", "line_strip", 4));
glxgeom.append(geometryShaderText);
std::string glxfrag(*GLSLShader::DEFINES_GL);
......
......@@ -93,11 +93,18 @@ PointSprite::PointSprite(bool withColorPervertex, float radius, bool with_plane
if (with_plane)
{
*m_uniform_planeX = glGetUniformLocation(program_handler(),"planeX");
*m_uniform_planeY = glGetUniformLocation(program_handler(),"planeY");
*m_uniform_EyePos = glGetUniformLocation(program_handler(),"eyePos");
*m_uniform_EyeY = glGetUniformLocation(program_handler(),"eyeY");
}
*m_uniform_ambiant = glGetUniformLocation(program_handler(),"ambiant");
*m_uniform_lightPos = glGetUniformLocation(program_handler(),"lightPos");
setLightPosition(Geom::Vec3f(2000.0,2000.0,2000.0));
setAmbiantColor(Geom::Vec3f(0.1f,0.1f,0.1f));
}
PointSprite::~PointSprite()
{
if (m_ptrSphere!=NULL)
......@@ -149,11 +156,11 @@ void PointSprite::setSize(float radius)
unbind();
}
void PointSprite::setPlane(const Geom::Vec3f& ox, const Geom::Vec3f& oy)
void PointSprite::setEyePosition(const Geom::Vec3f& ox, const Geom::Vec3f& oy)
{
bind();
glUniform3fv(*m_uniform_planeX, 1, ox.data());
glUniform3fv(*m_uniform_planeY, 1, oy.data());
glUniform3fv(*m_uniform_EyePos, 1, ox.data());
glUniform3fv(*m_uniform_EyeY, 1, oy.data());
unbind();
}
......@@ -197,6 +204,22 @@ void PointSprite::computeSphere()
}
}
void PointSprite::setLightPosition(const Geom::Vec3f& pos)
{
bind();
glUniform3fv(*m_uniform_lightPos, 1, pos.data());
unbind();
}
void PointSprite::setAmbiantColor(const Geom::Vec3f& amb)
{
bind();
glUniform3fv(*m_uniform_ambiant, 1, amb.data());
unbind();
}
} // namespace Utils
} // namespace CGoGN
......@@ -90,11 +90,6 @@ Strings3D::Strings3D(bool withBackground, const Geom::Vec3f& bgc, bool with_plan
glxfrag.append(fragmentShaderText3);
}
std::cout << "===================================="<< std::endl;
std::cout << glxfrag << std::endl;
std::cout << "===================================="<< std::endl;
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str());
m_vbo1 = new Utils::VBO();
......
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