Commit fabd57e6 authored by Pierre Kraemer's avatar Pierre Kraemer

SCHNApps - Surface Radiance : switch between per vertex and per fragment color evaluation

parent d13f94c0
......@@ -21,7 +21,44 @@
</property>
</widget>
</item>
<item row="5" column="1">
<item row="1" column="1">
<widget class="QComboBox" name="combo_normalVBO">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>- select VBO -</string>
</property>
</item>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="combo_positionVBO">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>- select VBO -</string>
</property>
</item>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QPushButton" name="button_decimate">
<property name="text">
<string>Decimate</string>
</property>
</widget>
</item>
<item row="6" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -34,13 +71,6 @@
</property>
</spacer>
</item>
<item row="4" column="0" colspan="2">
<widget class="QPushButton" name="button_decimate">
<property name="text">
<string>Decimate</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
......@@ -48,22 +78,14 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="combo_normalVBO">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="checkbox_halfCollapse">
<property name="text">
<string>Half Collapse</string>
</property>
<item>
<property name="text">
<string>- select VBO -</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0" colspan="2">
<item row="3" column="0" colspan="2">
<widget class="QSlider" name="slider_decimationGoal">
<property name="maximum">
<number>100</number>
......@@ -76,25 +98,10 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="combo_positionVBO">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>- select VBO -</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="checkbox_halfCollapse">
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="checkbox_fragInterp">
<property name="text">
<string>Half Collapse</string>
<string>Fragment interpolation</string>
</property>
</widget>
</item>
......
......@@ -32,6 +32,7 @@ private:
private slots:
void positionVBOChanged(int index);
void normalVBOChanged(int index);
void fragmentInterpolationChanged(int state);
void decimateClicked();
private:
......
......@@ -264,7 +264,7 @@ MapHandlerGen* Surface_Radiance_Plugin::importFromFile(const QString& fileName)
mapParams.radianceTexture->update();
// map->removeAttribute(mapParams.radiance);
map->removeAttribute(mapParams.radiance);
mapParams.paramVBO = new Utils::VBO();
mapParams.paramVBO->updateData(mapParams.param);
......
......@@ -19,6 +19,7 @@ Surface_Radiance_DockTab::Surface_Radiance_DockTab(SCHNApps* s, Surface_Radiance
connect(combo_positionVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(positionVBOChanged(int)));
connect(combo_normalVBO, SIGNAL(currentIndexChanged(int)), this, SLOT(normalVBOChanged(int)));
connect(checkbox_fragInterp, SIGNAL(stateChanged(int)), this, SLOT(fragmentInterpolationChanged(int)));
connect(button_decimate, SIGNAL(clicked()), this, SLOT(decimateClicked()));
}
......@@ -34,6 +35,8 @@ void Surface_Radiance_DockTab::positionVBOChanged(int index)
if(map)
{
m_plugin->h_mapParameterSet[map].positionVBO = map->getVBO(combo_positionVBO->currentText());
foreach (View* v, map->getLinkedViews())
v->updateGL();
}
}
}
......@@ -46,6 +49,22 @@ void Surface_Radiance_DockTab::normalVBOChanged(int index)
if(map)
{
m_plugin->h_mapParameterSet[map].normalVBO = map->getVBO(combo_normalVBO->currentText());
foreach (View* v, map->getLinkedViews())
v->updateGL();
}
}
}
void Surface_Radiance_DockTab::fragmentInterpolationChanged(int state)
{
if(!b_updatingUI)
{
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(map)
{
m_plugin->h_mapParameterSet[map].radiancePerVertexShader->setFragInterp(state == Qt::Checked);
foreach (View* v, map->getLinkedViews())
v->updateGL();
}
}
}
......@@ -130,6 +149,8 @@ void Surface_Radiance_DockTab::updateMapParameters()
++i;
}
}
checkbox_fragInterp->setChecked(p.radiancePerVertexShader->getFragInterp());
}
b_updatingUI = false;
......
......@@ -48,7 +48,7 @@ View::View(const QString& name, SCHNApps* s, QGLFormat& format) :
setSnapshotFormat("JPEG");
setSnapshotFileName(m_name);
setSnapshotQuality(95);
setSnapshotQuality(100);
m_currentCamera = m_schnapps->addCamera();
m_currentCamera->linkView(this);
......@@ -111,7 +111,7 @@ View::View(const QString& name, SCHNApps* s, QGLFormat& format, const QGLWidget*
setSnapshotFormat("JPEG");
setSnapshotFileName(m_name);
setSnapshotQuality(95);
setSnapshotQuality(100);
m_currentCamera = m_schnapps->addCamera();
m_currentCamera->linkView(this);
......
......@@ -44,6 +44,10 @@ protected:
static std::string geometryShaderText;
static std::string fragmentShaderText;
static std::string vertexShaderInterpText;
static std::string geometryShaderInterpText;
static std::string fragmentShaderInterpText;
CGoGNGLuint m_uniform_resolution;
CGoGNGLuint m_uniform_tex;
CGoGNGLuint m_uniform_K_tab;
......@@ -59,16 +63,21 @@ protected:
float* K_tab;
Geom::Vec3f m_camera;
bool m_fragInterp;
static int index (int l, int m) { return l*(l+1)+m; } // compute indices in K_tab
public:
ShaderRadiancePerVertex(int resolution);
ShaderRadiancePerVertex(int resolution, bool fraginterp = false);
~ShaderRadiancePerVertex() ;
~ShaderRadiancePerVertex();
void compile();
void setCamera(Geom::Vec3f camera) ;
void setCamera(Geom::Vec3f& camera);
void setFragInterp(bool fraginterp);
bool getFragInterp() { return m_fragInterp; }
unsigned int setAttributePosition(VBO* vbo);
......
// ShaderRadiancePerVertex::fragmentShaderInterpText
#extension GL_EXT_gpu_shader4 : enable // need GLSL v1.30 -> if not available, use a uniform for passing textureSize instead of calling textureSize2D
PRECISION;
VARYING_FRAG vec3 vxPos;
VARYING_FRAG vec3 vxNorm;
VARYING_FRAG vec3 barycentricCoord;
flat in ivec2 vx0TexCoord;
flat in ivec2 vx1TexCoord;
flat in ivec2 vx2TexCoord;
uniform vec3 camera;
uniform sampler2D texture;
uniform int resolution;
uniform float K_tab[NB_COEFS];
FRAG_OUT_DEF;
float F_tab[NB_COEFS];
int index (int l, int m)
{
return l*(l+1)+m;
}
void compute_P_tab (float t)
{
F_tab[index(0,0)] = 1;
for (int l=1; l<= resolution; l++)
{
F_tab[index(l,l)] = (1-2*l) * sqrt(1-t*t) * F_tab[index(l-1,l-1)]; // first diago
F_tab[index(l,l-1)] = t * (2*l-1) * F_tab[index(l-1,l-1)];// second diago
for (int m=0; m<=l-2; m++)
{// remaining of the line under the 2 diago
F_tab[index(l,m)] = t * (2*l-1) / float(l-m) * F_tab[index(l-1,m)] - (l+m-1) / float(l-m) * F_tab[index(l-2,m)];
}
}
}
void compute_y_tab (float phi)
{
for (int l=0; l<= resolution; l++)
{
F_tab[index(l,0)] *= K_tab[index(l,0)]; // remove for plotting
}
for (int m=1; m<=resolution; m++)
{
float cos_m_phi = cos ( m * phi );
float sin_m_phi = sin ( m * phi );
for (int l=m; l<=resolution; l++)
{
F_tab[index(l,m)] *= sqrt(2.0);
F_tab[index(l,m)] *= K_tab[index(l,m)];
F_tab[index(l,-m)] = F_tab[index(l,m)] * sin_m_phi ; // store the values for -m<0 in the upper triangle
F_tab[index(l,m)] *= cos_m_phi;
}
}
}
void set_eval_direction (vec3 v)
{
compute_P_tab(v.z);
float phi = 0;
if ((v.x*v.x+v.y*v.y) > 0.0)
phi = atan(v.y,v.x); // equiv to atan2 in C++
compute_y_tab(phi);
}
void main (void)
{
int size = (textureSize2D(texture,0)).x; // supposed square matrix
vec3 eyeV = normalize(camera - vxPos); // normalized outgoing line-of-sight vector
eyeV = 2*dot(vxNorm,eyeV)*vxNorm-eyeV ; // symmetrize
set_eval_direction(eyeV);
ivec2 param0 = vx0TexCoord;
ivec2 param1 = vx1TexCoord;
ivec2 param2 = vx2TexCoord;
vec3 color = vec3(0.);
for(int l=0; l<=resolution; l++)
{
for (int m = -l; m<=l; m++)
{
// compute texture index
if (param0.y >= size) // if texture newline
{
param0.y -= size ;
param0.x += 1 ;
}
if (param1.y >= size) // if texture newline
{
param1.y -= size ;
param1.x += 1 ;
}
if (param2.y >= size) // if texture newline
{
param2.y -= size ;
param2.x += 1 ;
}
// get corresponding coef
vec3 coefLM0 = (texelFetch(texture,param0,0)).rgb;
vec3 coefLM1 = (texelFetch(texture,param1,0)).rgb;
vec3 coefLM2 = (texelFetch(texture,param2,0)).rgb;
// multiply by basis function
float f = F_tab[index(l,m)];
color += barycentricCoord.x * coefLM0 * f;
color += barycentricCoord.y * coefLM1 * f;
color += barycentricCoord.z * coefLM2 * f;
param0.y ++ ;
param1.y ++ ;
param2.y ++ ;
}
}
FRAG_OUT = vec4(color, 1.0) ;
}
// ShaderRadiancePerVertex::geometryShaderInterpText
VARYING_IN vec3 vpos[];
VARYING_IN vec3 vnorm[];
VARYING_IN ivec2 vtexcoord[];
VARYING_OUT vec3 vxPos;
VARYING_OUT vec3 vxNorm;
VARYING_OUT vec3 barycentricCoord;
flat out ivec2 vx0TexCoord;
flat out ivec2 vx1TexCoord;
flat out ivec2 vx2TexCoord;
void main()
{
vx0TexCoord = vtexcoord[0];
vx1TexCoord = vtexcoord[1];
vx2TexCoord = vtexcoord[2];
gl_Position = POSITION_IN(0);
vxPos = vpos[0];
vxNorm = vnorm[0];
barycentricCoord = vec3(1., 0., 0.);
EmitVertex();
gl_Position = POSITION_IN(1);
vxPos = vpos[1];
vxNorm = vnorm[1];
barycentricCoord = vec3(0., 1., 0.);
EmitVertex();
gl_Position = POSITION_IN(2);
vxPos = vpos[2];
vxNorm = vnorm[2];
barycentricCoord = vec3(0., 0., 1.);
EmitVertex();
EndPrimitive();
}
// ShaderRadiancePerVertex::vertexShaderInterpText
ATTRIBUTE vec3 VertexPosition;
ATTRIBUTE vec3 VertexNormal;
ATTRIBUTE ivec2 VertexParam;
uniform mat4 ModelViewProjectionMatrix ;
VARYING_VERT vec3 vnorm;
VARYING_VERT vec3 vpos;
VARYING_VERT ivec2 vtexcoord ;
INVARIANT_POS;
void main ()
{
vpos = VertexPosition;
vnorm = VertexNormal;
vtexcoord = VertexParam;
gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0);
}
......@@ -34,14 +34,19 @@ namespace Utils
#include "shaderRadiancePerVertex.geom"
#include "shaderRadiancePerVertex.frag"
ShaderRadiancePerVertex::ShaderRadiancePerVertex(int resolution) :
#include "shaderRadiancePerVertexInterp.vert"
#include "shaderRadiancePerVertexInterp.geom"
#include "shaderRadiancePerVertexInterp.frag"
ShaderRadiancePerVertex::ShaderRadiancePerVertex(int resolution, bool fraginterp) :
m_vboPos(NULL),
m_vboNorm(NULL),
m_vboParam(NULL),
m_tex_ptr(NULL),
m_tex_unit(-1),
m_resolution(resolution),
K_tab(NULL)
K_tab(NULL),
m_fragInterp(fraginterp)
{
compile();
}
......@@ -54,9 +59,18 @@ ShaderRadiancePerVertex::~ShaderRadiancePerVertex()
void ShaderRadiancePerVertex::compile()
{
m_nameVS = "ShaderRadiancePerVertex_vs";
m_nameFS = "ShaderRadiancePerVertex_fs";
m_nameGS = "ShaderRadiancePerVertex_gs";
if (m_fragInterp)
{
m_nameVS = "ShaderRadiancePerVertexInterp_vs";
m_nameFS = "ShaderRadiancePerVertexInterp_fs";
m_nameGS = "ShaderRadiancePerVertexInterp_gs";
}
else
{
m_nameVS = "ShaderRadiancePerVertex_vs";
m_nameFS = "ShaderRadiancePerVertex_fs";
m_nameGS = "ShaderRadiancePerVertex_gs";
}
const int nb_coefs = (m_resolution+1)*(m_resolution+1);
if (m_resolution != -1)
......@@ -80,20 +94,34 @@ void ShaderRadiancePerVertex::compile()
}
}
std::string glxvert(*GLSLShader::DEFINES_GL);
std::stringstream s ;
s << "\n#define M_PI " << std::setprecision(23) << M_PI << std::endl ;
s << "#define NB_COEFS " << nb_coefs << std::endl ;
glxvert.append(s.str()) ;
glxvert.append(vertexShaderText);
std::string glxvert(*GLSLShader::DEFINES_GL);
if (!m_fragInterp)
{
glxvert.append(s.str()) ;
glxvert.append(vertexShaderText);
}
else
glxvert.append(vertexShaderInterpText);
std::string glxgeom = GLSLShader::defines_Geom("triangles", "triangle_strip", 3) ;
glxgeom.append(geometryShaderText);
if (!m_fragInterp)
glxgeom.append(geometryShaderText);
else
glxgeom.append(geometryShaderInterpText);
std::string glxfrag(*GLSLShader::DEFINES_GL);
glxfrag.append(fragmentShaderText);
if (!m_fragInterp)
glxfrag.append(fragmentShaderText) ;
else
{
glxfrag.append(s.str()) ;
glxfrag.append(fragmentShaderInterpText) ;
}
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_POINTS, GL_LINE_STRIP, 2);
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_TRIANGLES, GL_TRIANGLE_STRIP, 3);
bind();
*m_uniform_resolution = glGetUniformLocation(this->program_handler(), "resolution");
......@@ -106,7 +134,7 @@ void ShaderRadiancePerVertex::compile()
unbind();
}
void ShaderRadiancePerVertex::setCamera(Geom::Vec3f camera)
void ShaderRadiancePerVertex::setCamera(Geom::Vec3f& camera)
{
m_camera = camera;
bind();
......@@ -132,11 +160,18 @@ unsigned int ShaderRadiancePerVertex::setAttributeNormal(VBO* vbo)
return id;
}
void ShaderRadiancePerVertex::setFragInterp(bool fraginterp)
{
m_fragInterp = fraginterp ;
compile() ;
}
unsigned int ShaderRadiancePerVertex::setAttributeRadiance(VBO* vbo, Utils::Texture<2, Geom::Vec3f>* texture, GLenum tex_unit)
{
m_vboParam = vbo;
m_tex_ptr = texture;
m_tex_unit = tex_unit - GL_TEXTURE0;
bind();
unsigned int id = bindVA_VBO("VertexParam", vbo);
glUniform1iARB(*m_uniform_tex, m_tex_unit);
......
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