Commit cb3bcd83 authored by Maire Nicolas's avatar Maire Nicolas

Essai de rajout de clipping avec des sections de plans. Quelques bugs à régler...

Essai de rajout de clipping avec des sections de plans. Quelques bugs à régler encore, voir tout refaire à part des plans traditionels.
Un peu de cleanup dans clippingShader.
Cleanup complet dans shaderMutator.
parent 163a2e9e
......@@ -40,14 +40,12 @@ void StageShader::slot_drawVertices(bool b)
updateGL();
}
void StageShader::slot_drawLines(bool b)
{
m_drawLines = b;
updateGL();
}
void StageShader::slot_drawFaces(bool b)
{
m_drawFaces = b;
......@@ -77,9 +75,9 @@ void StageShader::slot_explodTopoPhi3(double c)
void StageShader::slot_pushButton_addPlane()
{
m_shader->setClippingPlanesCount(dock.comboBox_PlaneIndex->count() + 1);
m_shader->setClipPlanesCount(dock.comboBox_PlaneIndex->count() + 1);
m_shader->setClippingPlaneOrigin(m_bb.center(), dock.comboBox_PlaneIndex->count() + 1 - 1);
m_shader->setClipPlaneOrigin(m_bb.center(), dock.comboBox_PlaneIndex->count() + 1 - 1);
std::string indexStr;
std::stringstream ss;
......@@ -98,7 +96,7 @@ void StageShader::slot_pushButton_addPlane()
void StageShader::slot_pushButton_deletePlane()
{
m_shader->setClippingPlanesCount(dock.comboBox_PlaneIndex->count() - 1);
m_shader->setClipPlanesCount(dock.comboBox_PlaneIndex->count() - 1);
dock.comboBox_PlaneIndex->removeItem(dock.comboBox_PlaneIndex->count() - 1);
......@@ -112,17 +110,17 @@ void StageShader::slot_comboBox_PlaneIndexChanged(int newIndex)
{
if (newIndex >= 0)
{
Geom::Vec3f currPlaneVec1 = m_shader->getClippingPlaneFirstVec(newIndex);
Geom::Vec3f currPlaneVec1 = m_shader->getClipPlaneFirstVec(newIndex);
dock.doubleSpinBox_PlaneVec1x->setValue(currPlaneVec1[0]);
dock.doubleSpinBox_PlaneVec1y->setValue(currPlaneVec1[1]);
dock.doubleSpinBox_PlaneVec1z->setValue(currPlaneVec1[2]);
Geom::Vec3f currPlaneVec2 = m_shader->getClippingPlaneSecondVec(newIndex);
Geom::Vec3f currPlaneVec2 = m_shader->getClipPlaneSecondVec(newIndex);
dock.doubleSpinBox_PlaneVec2x->setValue(currPlaneVec2[0]);
dock.doubleSpinBox_PlaneVec2y->setValue(currPlaneVec2[1]);
dock.doubleSpinBox_PlaneVec2z->setValue(currPlaneVec2[2]);
Geom::Vec3f currPlaneOrigin = m_shader->getClippingPlaneOrigin(newIndex);
Geom::Vec3f currPlaneOrigin = m_shader->getClipPlaneOrigin(newIndex);
dock.doubleSpinBox_PlaneOriginx->setValue(currPlaneOrigin[0]);
dock.doubleSpinBox_PlaneOriginy->setValue(currPlaneOrigin[1]);
dock.doubleSpinBox_PlaneOriginz->setValue(currPlaneOrigin[2]);
......@@ -136,7 +134,7 @@ void StageShader::slot_doubleSpinBox_PlaneVec1(double c)
float x = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec1x->value();
float y = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec1y->value();
float z = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec1z->value();
m_shader->setClippingPlaneFirstVec(Geom::Vec3f(x, y, z), dock.comboBox_PlaneIndex->currentIndex());
m_shader->setClipPlaneFirstVec(Geom::Vec3f(x, y, z), dock.comboBox_PlaneIndex->currentIndex());
updateGL();
}
}
......@@ -148,7 +146,7 @@ void StageShader::slot_doubleSpinBox_PlaneVec2(double c)
float x = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec2x->value();
float y = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec2y->value();
float z = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneVec2z->value();
m_shader->setClippingPlaneSecondVec(Geom::Vec3f(x, y, z), dock.comboBox_PlaneIndex->currentIndex());
m_shader->setClipPlaneSecondVec(Geom::Vec3f(x, y, z), dock.comboBox_PlaneIndex->currentIndex());
updateGL();
}
}
......@@ -160,14 +158,14 @@ void StageShader::slot_doubleSpinBox_PlaneOrigin(double c)
float x = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneOriginx->value();
float y = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneOriginy->value();
float z = dynamic_cast<Utils::QT::uiDockInterface*>(dockWidget())->doubleSpinBox_PlaneOriginz->value();
m_shader->setClippingPlaneOrigin(Geom::Vec3f(x, y, z), dock.comboBox_PlaneIndex->currentIndex());
m_shader->setClipPlaneOrigin(Geom::Vec3f(x, y, z), dock.comboBox_PlaneIndex->currentIndex());
updateGL();
}
}
void StageShader::slot_doubleSpinBox_ColorAttenuationFactor(double c)
{
m_shader->setClippingColorAttenuationFactor((float)c);
m_shader->setClipColorAttenuationFactor((float)c);
updateGL();
}
......@@ -287,7 +285,7 @@ void StageShader::initGUI()
dock.vertexEdit->setPlainText(QString(m_shader->getVertexShaderSrc()));
dock.fragmentEdit->setPlainText(QString(m_shader->getFragmentShaderSrc()));
dock.doubleSpinBox_ColorAttenuationFactor->setValue(m_shader->getClippingColorAttenuationFactor());
dock.doubleSpinBox_ColorAttenuationFactor->setValue(m_shader->getClipColorAttenuationFactor());
dock.doubleSpinBox_GridDisplaySize->setValue(m_shader->getPlaneDisplaySize());
dock.spinBox_GridResolutionX->setValue(m_shader->getPlaneDisplayXRes());
dock.spinBox_GridResolutionY->setValue(m_shader->getPlaneDisplayYRes());
......@@ -436,7 +434,7 @@ void StageShader::cb_redraw()
if (m_drawTopo)
m_render_topo->drawTopo();
m_shader->displayClippingPlanes();
m_shader->displayClipPlanes();
}
......
......@@ -268,7 +268,11 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBox_GridDisplaySize"/>
<widget class="QDoubleSpinBox" name="doubleSpinBox_GridDisplaySize">
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_GridSize">
......
......@@ -61,84 +61,84 @@ public:
~ClippingShader();
/**
* set all parameters for one clipping plane
* set all parameters for one clip plane
* @warning planeIndex starts at 0
* @param vec1 first basis vector
* @param vec2 second basis vector
* @param origin point of the plane that will be used as origin to display it
* @param planeIndex index of the plane to modify
*/
void setClippingPlane(Geom::Vec3f vec1, Geom::Vec3f vec2, Geom::Vec3f origin, int planeIndex = 0);
void setClipPlane(Geom::Vec3f vec1, Geom::Vec3f vec2, Geom::Vec3f origin, int planeIndex = 0);
/**
* set first vector parameter for one clipping plane
* set first vector for one clip plane
* @warning planeIndex starts at 0
* @param vec1 first basis vector
* @param planeIndex index of the plane to modify
*/
void setClippingPlaneFirstVec(Geom::Vec3f vec1, int planeIndex = 0);
void setClipPlaneFirstVec(Geom::Vec3f vec1, int planeIndex = 0);
/**
* set second vector parameter for one clipping plane
* set second vector for one clip plane
* @warning planeIndex starts at 0
* @param vec2 second basis vector
* @param planeIndex index of the plane to modify
*/
void setClippingPlaneSecondVec(Geom::Vec3f vec2, int planeIndex = 0);
void setClipPlaneSecondVec(Geom::Vec3f vec2, int planeIndex = 0);
/**
* set origin parameter for one clipping plane
* set origin for one clip plane
* @warning planeIndex starts at 0
* @param origin point of the plane that will be used as origin to display it
* @param planeIndex index of the plane to modify
*/
void setClippingPlaneOrigin(Geom::Vec3f origin, int planeIndex = 0);
void setClipPlaneOrigin(Geom::Vec3f origin, int planeIndex = 0);
/**
* get first parameter for one clipping plane
* get first vector for one clip plane
* @warning planeIndex starts at 0
* @param planeIndex index of the plane to modify
*/
Geom::Vec3f getClippingPlaneFirstVec(int planeIndex = 0);
Geom::Vec3f getClipPlaneFirstVec(int planeIndex = 0);
/**
* get second vector parameter for one clipping plane
* get second vector for one clip plane
* @warning planeIndex starts at 0
* @param planeIndex index of the plane to modify
*/
Geom::Vec3f getClippingPlaneSecondVec(int planeIndex = 0);
Geom::Vec3f getClipPlaneSecondVec(int planeIndex = 0);
/**
* get origin parameter for one clipping plane
* get origin for one clip plane
* @warning planeIndex starts at 0
* @param planeIndex index of the plane to modify
*/
Geom::Vec3f getClippingPlaneOrigin(int planeIndex = 0);
Geom::Vec3f getClipPlaneOrigin(int planeIndex = 0);
/**
* set the color attenuation factor for clipping
* @param colorAttenuationFactor color attenuation factor
*/
void setClippingColorAttenuationFactor(float colorAttenuationFactor);
void setClipColorAttenuationFactor(float colorAttenuationFactor);
/**
* get the color attenuation factor for clipping
*/
float getClippingColorAttenuationFactor() { return m_colorAttenuationFactor; }
float getClipColorAttenuationFactor() { return m_colorAttenuationFactor; }
/**
* set the clipping planes count used for plane clipping
* - insert plane clipping instructions into vertex and fragment shader source code
* set the clip planes count
* - inserts plane clipping instructions into vertex and fragment shader source code
* but does not modify the geometry shader source code
* @param planesCount the clipping planes count to use
* @param planesCount the clip planes count to use
* @warning this function is designed for shaders which *do not* use a geometry shader
*/
void setClippingPlanesCount(int planesCount);
void setClipPlanesCount(int planesCount);
/**
* get the clipping planes count used for plane clipping
* get the clip planes count
*/
int getClippingPlanesCount() { return (int)m_clipPlanes.size(); }
int getClipPlanesCount() { return (int)m_clipPlanes.size(); }
/**
* update uniforms (get their locations and send their values again) for clipping
......@@ -148,7 +148,7 @@ public:
/**
* display all clipping planes
*/
void displayClippingPlanes();
void displayClipPlanes();
/**
* set the planes display color
......@@ -198,7 +198,7 @@ public:
* set the planes display size
* @param size the new size
*/
void setPlaneDisplaySize(float size) { m_clipPlanesDisplaySize = size; updateAllClippingPlanesVBOs(); }
void setPlaneDisplaySize(float size) { m_clipPlanesDisplaySize = size;sendClippingPlanesUniform();updateAllClippingPlanesVBOs(); }
/**
* get the planes display size
......@@ -209,7 +209,7 @@ public:
private:
/**
* clipping planes structure
* clip planes structure
*/
struct clipPlane
{
......@@ -217,15 +217,21 @@ private:
};
/**
* sends the clipping planes uniform to shader
* sends the clip planes arrays to shader
*/
void sendClippingPlanesUniform();
/**
* sends the color attenuation factor uniform to shader
* sends the color attenuation factor to shader
*/
void sendColorAttenuationFactorUniform();
/**
* update clip planes parameters arrays
* @param planeIndex index of the plane
*/
void updateClippingPlanesArrays(int planeIndex);
/**
* update VBO for one plane
* @param planeIndex index of the plane
......@@ -281,6 +287,26 @@ private:
*/
GLint m_unif_clipPlanesEquations;
/**
* clip planes first vectors uniform id
*/
GLint m_unif_clipPlanesFirstVectors;
/**
* clip planes second vectors uniform id
*/
GLint m_unif_clipPlanesSecondVectors;
/**
* clip planes origins uniform id
*/
GLint m_unif_clipPlanesOrigins;
/**
* clip planes size uniform id
*/
GLint m_unif_clipPlanesDisplaySize;
/**
* color attenuation factor
*/
......@@ -321,6 +347,11 @@ private:
*/
float m_clipPlanesDisplaySize;
/**
* use advanced plane clipping ?
*/
bool m_useAdvancedPlaneClipping;
};
......
......@@ -48,52 +48,52 @@ public:
/**
* constructor
* @param vertShaderSrc the vertex shader source to store
* @param fragShaderSrc the fragment shader source to store
* @param geomShaderSrc the geometry shader source to store
* @param vertShaderSrc vertex shader source to store
* @param fragShaderSrc fragment shader source to store
* @param geomShaderSrc geometry shader source to store (optional)
*/
ShaderMutator(const std::string& shaderName, const std::string& vertShaderSrc, const std::string& fragShaderSrc, const std::string& geomShaderSrc = "");
/**
* check if a variable is declared in the shader source
* @param srcType the shader source to use (vertex, fragment or geometry)
* @param variableName the variable to search for
* checks if a variable is declared in the shader source
* @param srcType shader source to use
* @param variableName variable to search for
*/
bool containsVariableDeclaration(shaderSrcType srcType, const std::string& variableName);
/**
* set or change shading language version in the shader source
* sets or changes shading language version in the shader source
* - only if the current version is lower
* @param srcType the shader source to use (vertex, fragment or geometry)
* @param version the version to set (110, 120, 150...)
* @param srcType shader source to use
* @param version version to set (110, 120, 150...)
*/
void setMinShadingLanguageVersion(shaderSrcType srcType, int version);
/**
* change int constant value in the shader source
* @param srcType the shader source to use (vertex, fragment or geometry)
* @param newVal the new value
* changes int constant value in the shader source
* @param srcType shader source to use
* @param newVal new constant value
*/
void changeIntConstantValue(shaderSrcType srcType, const std::string& constantName, int newVal);
/**
* insert code before main function into shader source
* @param srcType the shader source to use (vertex, fragment or geometry)
* inserts code before main function in the shader source
* @param srcType shader source to use
* @param insertedCode source code to insert into shader
*/
void insertCodeBeforeMainFunction(shaderSrcType srcType, const std::string& insertedCode);
/**
* insert code at the beginning of main function into shader source
* @param srcType the shader source to use (vertex, fragment or geometry)
* inserts code at the beginning of main function in the shader source
* @param srcType shader source to use
* @param insertedCode source code to insert into shader
*/
void insertCodeAtMainFunctionBeginning(shaderSrcType srcType, const std::string& insertedCode);
/**
* insert code at the end of main function into shader source
* inserts code at the end of main function in the shader source
* @warning takes the number of opening and closing braces of main function into account
* @param srcType the shader source to use (vertex, fragment or geometry)
* @param srcType shader source to use
* @param insertedCode source code to insert into shader
*/
void insertCodeAtMainFunctionEnd(shaderSrcType srcType, const std::string& insertedCode);
......@@ -136,56 +136,58 @@ private:
std::string m_gShaderMutation;
/**
* check if the given position in the source is commented
* @param pos the position
* @param src the source to analyze
* checks if the given position is commented
* @param pos position in the source (like in a string)
* @param src source to analyze
*/
bool srcIsCommented(size_t pos, const std::string& src);
/**
* check if the given position in the source is commented with a one-line comment
* @param pos the position
* @param src the source to analyze
* checks if the given position is commented with a one-line comment
* @param pos position in the source (like in a string)
* @param src source to analyze
*/
bool srcIsOneLineCommented(size_t pos, const std::string& src);
/**
* check if a variable is declared in a source code
* @param variable the variable to search for
* checks if a variable is declared
* @param variableName variable to search for
* @param src source to analyze
*/
bool srcContainsVariableDeclaration(const std::string& variableName, std::string& src);
/**
* set or change shading language version if the current version is lower
* @param version the version to set (110, 120, 150...)
* sets or changes shading language version if the current version is lower
* @param version version to set (110, 120, 150...)
* @param modifiedSrc shader source code to modify
*/
bool srcSetMinShadingLanguageVersion(int version, std::string& modifiedSrc);
/**
* change int constant value
* @param newVal the new value
* changes int constant value
* @param newVal new constant value
* @param constantName constant name as it is declared
* @param modifiedSrc shader source code to modify
*/
bool srcChangeIntConstantValue(int newVal, const std::string& constantName, std::string& modifiedSrc);
/**
* insert code before main function into source code
* @param insertedCode source code to insert into shader
* inserts code before main function
* @param insertedCode source code to insert
* @param modifiedSrc shader source code to modify
*/
bool srcInsertCodeBeforeMainFunction(const std::string& insertedCode, std::string& modifiedSrc);
/**
* insert code at the beginning of main function into source code
* @param insertedCode source code to insert into shader
* inserts code at the beginning of main function
* @param insertedCode source code to insert
* @param modifiedSrc shader source code to modify
*/
bool srcInsertCodeAtMainFunctionBeginning(const std::string& insertedCode, std::string& modifiedSrc);
/**
* insert code at the end of main function into source code
* @param insertedCode source code to insert into shader
* inserts code at the end of main function
* @param insertedCode source code to insert
* @param modifiedSrc shader source code to modify
*/
bool srcInsertCodeAtMainFunctionEnd(const std::string& insertedCode, std::string& modifiedSrc);
......
......@@ -32,19 +32,22 @@ namespace Utils
ClippingShader::ClippingShader()
{
// Initialize clipping planes variables (planes equations table has zero size by default)
// Initialize uniforms ids
m_unif_clipPlanesEquations = 0;
m_unif_colorAttenuationFactor = 0;
// Initialize color attenuation variables
// Initialize default color attenuation variables
m_colorAttenuationFactor = 1.0;
m_unif_colorAttenuationFactor = 0;
// Initialize display variables
// Initialize default display variables
m_clipPlanesDisplayColor = Geom::Vec3f (1.0, 0.6, 0.0);
m_clipPlanesDisplayType = STRAIGHT_GRID;
m_clipPlanesDisplayXRes = 2;
m_clipPlanesDisplayYRes = 2;
m_clipPlanesDisplaySize = 10.0;
// Initialize default special variables
m_useAdvancedPlaneClipping = false;
}
ClippingShader::~ClippingShader()
......@@ -55,10 +58,10 @@ ClippingShader::~ClippingShader()
delete m_clipPlanesDrawers[i];
}
void ClippingShader::setClippingPlane(Geom::Vec3f vec1, Geom::Vec3f vec2, Geom::Vec3f origin, int planeIndex)
void ClippingShader::setClipPlane(Geom::Vec3f vec1, Geom::Vec3f vec2, Geom::Vec3f origin, int planeIndex)
{
// Check if the given index is not out of range
if ((planeIndex < 0) || (planeIndex > (getClippingPlanesCount() - 1)))
if ((planeIndex < 0) || (planeIndex > (getClipPlanesCount() - 1)))
{
CGoGNerr
<< "ERROR - "
......@@ -75,13 +78,8 @@ void ClippingShader::setClippingPlane(Geom::Vec3f vec1, Geom::Vec3f vec2, Geom::
m_clipPlanes[planeIndex].secondVec.normalize();
m_clipPlanes[planeIndex].origin = origin;
// Update the planes equations array
Geom::Vec3f planeNormal = m_clipPlanes[planeIndex].firstVec ^ m_clipPlanes[planeIndex].secondVec;
float d = -(planeNormal * m_clipPlanes[planeIndex].origin);
m_clipPlanesEquations[4*planeIndex + 0] = planeNormal[0];
m_clipPlanesEquations[4*planeIndex + 1] = planeNormal[1];
m_clipPlanesEquations[4*planeIndex + 2] = planeNormal[2];
m_clipPlanesEquations[4*planeIndex + 3] = d;
// Update the plane arrays
updateClippingPlanesArrays(planeIndex);
// Send again the whole planes equations array to shader
sendClippingPlanesUniform();
......@@ -90,10 +88,10 @@ void ClippingShader::setClippingPlane(Geom::Vec3f vec1, Geom::Vec3f vec2, Geom::
updateClippingPlaneVBO(planeIndex);
}
void ClippingShader::setClippingPlaneFirstVec(Geom::Vec3f vec1, int planeIndex)
void ClippingShader::setClipPlaneFirstVec(Geom::Vec3f vec1, int planeIndex)
{
// Check if the given index is not out of range
if ((planeIndex < 0) || (planeIndex > (getClippingPlanesCount() - 1)))
if ((planeIndex < 0) || (planeIndex > (getClipPlanesCount() - 1)))
{
CGoGNerr
<< "ERROR - "
......@@ -107,13 +105,8 @@ void ClippingShader::setClippingPlaneFirstVec(Geom::Vec3f vec1, int planeIndex)
m_clipPlanes[planeIndex].firstVec = vec1;
m_clipPlanes[planeIndex].firstVec.normalize();
// Update the planes equations array
Geom::Vec3f planeNormal = m_clipPlanes[planeIndex].firstVec ^ m_clipPlanes[planeIndex].secondVec;
float d = -(planeNormal * m_clipPlanes[planeIndex].origin);
m_clipPlanesEquations[4*planeIndex + 0] = planeNormal[0];
m_clipPlanesEquations[4*planeIndex + 1] = planeNormal[1];
m_clipPlanesEquations[4*planeIndex + 2] = planeNormal[2];
m_clipPlanesEquations[4*planeIndex + 3] = d;
// Update the plane arrays
updateClippingPlanesArrays(planeIndex);
// Send again the whole planes equations array to shader
sendClippingPlanesUniform();
......@@ -122,10 +115,10 @@ void ClippingShader::setClippingPlaneFirstVec(Geom::Vec3f vec1, int planeIndex)
updateClippingPlaneVBO(planeIndex);
}
void ClippingShader::setClippingPlaneSecondVec(Geom::Vec3f vec2, int planeIndex)
void ClippingShader::setClipPlaneSecondVec(Geom::Vec3f vec2, int planeIndex)
{
// Check if the given index is not out of range
if ((planeIndex < 0) || (planeIndex > (getClippingPlanesCount() - 1)))
if ((planeIndex < 0) || (planeIndex > (getClipPlanesCount() - 1)))
{
CGoGNerr
<< "ERROR - "
......@@ -139,13 +132,8 @@ void ClippingShader::setClippingPlaneSecondVec(Geom::Vec3f vec2, int planeIndex)
m_clipPlanes[planeIndex].secondVec = vec2;
m_clipPlanes[planeIndex].secondVec.normalize();
// Update the planes equations array
Geom::Vec3f planeNormal = m_clipPlanes[planeIndex].firstVec ^ m_clipPlanes[planeIndex].secondVec;
float d = -(planeNormal * m_clipPlanes[planeIndex].origin);
m_clipPlanesEquations[4*planeIndex + 0] = planeNormal[0];
m_clipPlanesEquations[4*planeIndex + 1] = planeNormal[1];
m_clipPlanesEquations[4*planeIndex + 2] = planeNormal[2];
m_clipPlanesEquations[4*planeIndex + 3] = d;
// Update the plane arrays
updateClippingPlanesArrays(planeIndex);
// Send again the whole planes equations array to shader
sendClippingPlanesUniform();
......@@ -154,10 +142,10 @@ void ClippingShader::setClippingPlaneSecondVec(Geom::Vec3f vec2, int planeIndex)
updateClippingPlaneVBO(planeIndex);
}
void ClippingShader::setClippingPlaneOrigin(Geom::Vec3f origin, int planeIndex)
void ClippingShader::setClipPlaneOrigin(Geom::Vec3f origin, int planeIndex)
{
// Check if the given index is not out of range
if ((planeIndex < 0) || (planeIndex > (getClippingPlanesCount() - 1)))
if ((planeIndex < 0) || (planeIndex > (getClipPlanesCount() - 1)))
{
CGoGNerr
<< "ERROR - "
......@@ -170,13 +158,8 @@ void ClippingShader::setClippingPlaneOrigin(Geom::Vec3f origin, int planeIndex)
// Copy the given clipping plane parameter
m_clipPlanes[planeIndex].origin = origin;
// Update the planes equations array
Geom::Vec3f planeNormal = m_clipPlanes[planeIndex].firstVec ^ m_clipPlanes[planeIndex].secondVec;
float d = -(planeNormal * m_clipPlanes[planeIndex].origin);
m_clipPlanesEquations[4*planeIndex + 0] = planeNormal[0];
m_clipPlanesEquations[4*planeIndex + 1] = planeNormal[1];
m_clipPlanesEquations[4*planeIndex + 2] = planeNormal[2];
m_clipPlanesEquations[4*planeIndex + 3] = d;
// Update the plane arrays
updateClippingPlanesArrays(planeIndex);
// Send again the whole planes equations array to shader
sendClippingPlanesUniform();
......@@ -185,10 +168,10 @@ void ClippingShader::setClippingPlaneOrigin(Geom::Vec3f origin, int planeIndex)
updateClippingPlaneVBO(planeIndex);
}
Geom::Vec3f ClippingShader::getClippingPlaneFirstVec(int planeIndex)
Geom::Vec3f ClippingShader::getClipPlaneFirstVec(int planeIndex)
{
// Check if the given index is not out of range
if ((planeIndex < 0) || (planeIndex > (getClippingPlanesCount() - 1)))
if ((planeIndex < 0) || (planeIndex > (getClipPlanesCount() - 1)))
{
CGoGNerr
<< "ERROR - "
......@@ -202,10 +185,10 @@ Geom::Vec3f ClippingShader::getClippingPlaneFirstVec(int planeIndex)
return m_clipPlanes[planeIndex].firstVec;
}
Geom::Vec3f ClippingShader::getClippingPlaneSecondVec(int planeIndex)
Geom::Vec3f ClippingShader::getClipPlaneSecondVec(int planeIndex)
{
// Check if the given index is not out of range
if ((planeIndex < 0) || (planeIndex > (getClippingPlanesCount() - 1)))
if ((planeIndex < 0) || (planeIndex > (getClipPlanesCount() - 1)))
{
CGoGNerr
<< "ERROR - "
......@@ -219,10 +202,10 @@ Geom::Vec3f ClippingShader::getClippingPlaneSecondVec(int planeIndex)
return m_clipPlanes[planeIndex].secondVec;
}
Geom::Vec3f ClippingShader::getClippingPlaneOrigin(int planeIndex)
Geom::Vec3f ClippingShader::getClipPlaneOrigin(int planeIndex)
{
// Check if the given index is not out of range
if ((planeIndex < 0) || (planeIndex > (getClippingPlanesCount() - 1)))
if ((planeIndex < 0) || (planeIndex > (getClipPlanesCount() - 1)))
{
CGoGNerr
<< "ERROR - "
......@@ -236,7 +219,7 @@ Geom::Vec3f ClippingShader::getClippingPlaneOrigin(int planeIndex)
return m_clipPlanes[planeIndex].origin;
}
void ClippingShader::setClippingColorAttenuationFactor(float colorAttenuationFactor)
void ClippingShader::setClipColorAttenuationFactor(float colorAttenuationFactor)
{
// Copy the given value
m_colorAttenuationFactor = colorAttenuationFactor;
......@@ -245,7 +228,7 @@ void ClippingShader::setClippingColorAttenuationFactor(float colorAttenuationFac
sendColorAttenuationFactorUniform();
}
void ClippingShader::setClippingPlanesCount(int planesCount)
void ClippingShader::setClipPlanesCount(int planesCount)
{
// Verify that the given clipping planes count is valid
if (planesCount < 0)
......@@ -305,7 +288,12 @@ void ClippingShader::setClippingPlanesCount(int planesCount)
" // Pass the non transformed vertex position to the fragment shader for clipping\n"
" clip_NonTransformedPos = VertexPosition;\n";
std::string FS_head_insertion =
std::string FS_head_insertion;
std::string FS_mainBegin_insertion;
if (!m_useAdvancedPlaneClipping) // the shader is slightly different for advanced plane clipping
{
FS_head_insertion =
"\n"
"#define CLIP_PLANES_COUNT " + planesCountStr + "\n"
"\n"
......@@ -315,7 +303,7 @@ void ClippingShader::setClippingPlanesCount(int planesCount)
"VARYING_FRAG vec3 clip_NonTransformedPos;\n"
"\n";
std::string FS_mainBegin_insertion =
FS_mainBegin_insertion =
"\n"
" // Distance to the nearest plane, stored for color attenuation\n"
" float clip_MinDistanceToPlanes = -1.0;\n"
......@@ -352,6 +340,87 @@ void ClippingShader::setClippingPlanesCount(int planesCount)
" clip_MinDistanceToPlanes = min(clip_MinDistanceToPlanes, clip_DistanceToPlane);\n"
" }\n"
" }\n";
}
else
{
FS_head_insertion =
"\n"
"#define CLIP_PLANES_COUNT " + planesCountStr + "\n"
"\n"
"uniform vec4 clip_ClipPlanes[CLIP_PLANES_COUNT];\n"
"uniform vec3 clip_ClipPlanesFirstVec[CLIP_PLANES_COUNT];\n"
"uniform vec3 clip_ClipPlanesSecondVec[CLIP_PLANES_COUNT];\n"
"uniform vec3 clip_ClipPlanesOrigin[CLIP_PLANES_COUNT];\n"
"\n"
"uniform float clip_ClipPlanesSize;\n"
"\n"
"uniform float clip_ColorAttenuationFactor;\n"
"\n"
"VARYING_FRAG vec3 clip_NonTransformedPos;\n"
"\n";
FS_mainBegin_insertion =
"\n"
" // Distance to the nearest plane, stored for color attenuation\n"
" float clip_MinDistanceToPlanes = -1.0;\n"
"\n"
" // Do clipping for each plane\n"
" int i;\n"
" for (i = 0; i < CLIP_PLANES_COUNT; i++)\n"
" {\n"
" // Copy the plane to make it modifiable\n"
" vec4 clip_CurrClipPlane = clip_ClipPlanes[i];\n"
"\n"
" // If the plane normal is zero, use a default normal vector (0.0, 0.0, 1.0)\n"
" float clip_NPlane = length(clip_CurrClipPlane.xyz);\n"
" if (clip_NPlane == 0.0)\n"
" {\n"
" clip_CurrClipPlane.z = 1.0;\n"
" clip_NPlane = 1.0;\n"
" }\n"
"\n"
" // Signed distance between the point and the plane\n"
" float clip_DistanceToPlane = dot(clip_NonTransformedPos, clip_CurrClipPlane.xyz);\n"
" clip_DistanceToPlane += clip_CurrClipPlane.w;\n"
" clip_DistanceToPlane /= clip_NPlane;\n"
"\n"
" // Keep the fragment only if it is 'above' or 'outside' the plane\n"
" if (clip_DistanceToPlane < 0.0)\n"
" {\n"
" // Get the orthogonal projection of the point on the plane\n"
" vec3 clip_PosPlaneProj = clip_NonTransformedPos;\n"
" clip_PosPlaneProj -= (clip_DistanceToPlane*clip_NPlane) * clip_CurrClipPlane.xyz;\n"
"\n"
" // Get the distance of the point to origin on each plane vector\n"
" vec3 clip_ToPlaneOrigin = clip_PosPlaneProj - clip_ClipPlanesOrigin[i];\n"
" float clip_PosVec1Val = abs(dot(clip_ToPlaneOrigin, vec3(clip_ClipPlanesFirstVec[i].x, clip_ClipPlanesFirstVec[i].y, clip_ClipPlanesFirstVec[i].z)));\n"
" clip_PosVec1Val /= length(clip_ClipPlanesFirstVec[i]);\n"
" float clip_PosVec2Val = abs(dot(clip_ToPlaneOrigin, vec3(clip_ClipPlanesSecondVec[i].x, clip_ClipPlanesSecondVec[i].y, clip_ClipPlanesSecondVec[i].z)));\n"
" clip_PosVec2Val /= length(clip_ClipPlanesSecondVec[i]);\n"