Commit a5777d30 authored by Maire Nicolas's avatar Maire Nicolas

Amélioration du système d'attenuation des couleurs en mode de clipping OR.

Rajout de modes d'attenuation : linéaire ou quadratique.
Implémentation dans l'interface Qt de l'appli clipping.
parent 4ba00cbe
...@@ -150,11 +150,11 @@ void Clipping::slot_doubleSpinBox_ColorAttenuationFactor(double c) ...@@ -150,11 +150,11 @@ void Clipping::slot_doubleSpinBox_ColorAttenuationFactor(double c)
updateGL(); updateGL();
} }
void Clipping::slot_horizontalSlider_ClippingMode(int i) void Clipping::slot_radioButton_ClippingMode(bool b)
{ {
if (i == 0) if (b)
m_shader->setClipMode(Utils::ClippingShader::CLIPPING_MODE_AND); m_shader->setClipMode(Utils::ClippingShader::CLIPPING_MODE_AND);
else if (i == 1) else
m_shader->setClipMode(Utils::ClippingShader::CLIPPING_MODE_OR); m_shader->setClipMode(Utils::ClippingShader::CLIPPING_MODE_OR);
dock.vertexEdit->setPlainText(QString(m_shader->getVertexShaderSrc())); dock.vertexEdit->setPlainText(QString(m_shader->getVertexShaderSrc()));
...@@ -163,6 +163,19 @@ void Clipping::slot_horizontalSlider_ClippingMode(int i) ...@@ -163,6 +163,19 @@ void Clipping::slot_horizontalSlider_ClippingMode(int i)
updateGLMatrices(); updateGLMatrices();
} }
void Clipping::slot_radioButton_ColorAttenuationMode(bool b)
{
if (b)
m_shader->setClipColorAttenuationMode(Utils::ClippingShader::COLOR_ATTENUATION_MODE_LINEAR);
else
m_shader->setClipColorAttenuationMode(Utils::ClippingShader::COLOR_ATTENUATION_MODE_QUADRATIC);
dock.vertexEdit->setPlainText(QString(m_shader->getVertexShaderSrc()));
dock.fragmentEdit->setPlainText(QString(m_shader->getFragmentShaderSrc()));
updateGLMatrices();
}
void Clipping::slot_pushButton_deleteSelectedObject() void Clipping::slot_pushButton_deleteSelectedObject()
{ {
if (m_lastPickedObject) if (m_lastPickedObject)
...@@ -294,14 +307,20 @@ void Clipping::initGUI() ...@@ -294,14 +307,20 @@ void Clipping::initGUI()
setCallBack(dock.doubleSpinBox_ColorAttenuationFactor, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_ColorAttenuationFactor(double))); setCallBack(dock.doubleSpinBox_ColorAttenuationFactor, SIGNAL(valueChanged(double)), SLOT(slot_doubleSpinBox_ColorAttenuationFactor(double)));
setCallBack(dock.horizontalSlider_ClippingMode, SIGNAL(valueChanged(int)), SLOT(slot_horizontalSlider_ClippingMode(int))); setCallBack(dock.radioButton_ClippingModeAnd, SIGNAL(toggled(bool)), SLOT(slot_radioButton_ClippingMode(bool)));
setCallBack(dock.radioButton_ColorAttenuationModeLinear, SIGNAL(toggled(bool)), SLOT(slot_radioButton_ColorAttenuationMode(bool)));
dock.doubleSpinBox_ColorAttenuationFactor->setValue(m_shader->getClipColorAttenuationFactor()); dock.doubleSpinBox_ColorAttenuationFactor->setValue(m_shader->getClipColorAttenuationFactor());
Utils::ClippingShader::clippingMode clipMode = m_shader->getClipMode(); Utils::ClippingShader::clippingMode clipMode = m_shader->getClipMode();
if (clipMode == Utils::ClippingShader::CLIPPING_MODE_AND) if (clipMode == Utils::ClippingShader::CLIPPING_MODE_AND)
dock.horizontalSlider_ClippingMode->setValue(0); dock.radioButton_ClippingModeAnd->setChecked(true);
else if (clipMode == Utils::ClippingShader::CLIPPING_MODE_OR) else if (clipMode == Utils::ClippingShader::CLIPPING_MODE_OR)
dock.horizontalSlider_ClippingMode->setValue(1); dock.radioButton_ClippingModeOr->setChecked(true);
Utils::ClippingShader::colorAttenuationMode colorAttMode = m_shader->getClipColorAttenuationMode();
if (colorAttMode == Utils::ClippingShader::COLOR_ATTENUATION_MODE_LINEAR)
dock.radioButton_ColorAttenuationModeLinear->setChecked(true);
else if (colorAttMode == Utils::ClippingShader::COLOR_ATTENUATION_MODE_QUADRATIC)
dock.radioButton_ColorAttenuationModeQuadratic->setChecked(true);
} }
...@@ -573,7 +592,6 @@ void Clipping::cb_mouseMove(int buttons, int x, int y) ...@@ -573,7 +592,6 @@ void Clipping::cb_mouseMove(int buttons, int x, int y)
Geom::Vec3f planeNewPos = m_lastPickedObject->getPosition(); Geom::Vec3f planeNewPos = m_lastPickedObject->getPosition();
float planeNewAxisScale; // Not used float planeNewAxisScale; // Not used
Geom::Vec3f planeNewNormal = m_lastPickedObject->getAxisScale(2, planeNewAxisScale); // 2 = Z axis = plane normal Geom::Vec3f planeNewNormal = m_lastPickedObject->getAxisScale(2, planeNewAxisScale); // 2 = Z axis = plane normal
std::cout << planeNewNormal << std::endl;
// Update clipping shape // Update clipping shape
m_shader->setClipPlaneParamsAll(m_lastPickedObject->id(), planeNewNormal, planeNewPos); m_shader->setClipPlaneParamsAll(m_lastPickedObject->id(), planeNewNormal, planeNewPos);
......
...@@ -148,7 +148,8 @@ public slots: ...@@ -148,7 +148,8 @@ public slots:
void slot_doubleSpinBox_SphereGridColor(double c); void slot_doubleSpinBox_SphereGridColor(double c);
void slot_doubleSpinBox_ColorAttenuationFactor(double c); void slot_doubleSpinBox_ColorAttenuationFactor(double c);
void slot_horizontalSlider_ClippingMode(int i); void slot_radioButton_ClippingMode(bool b);
void slot_radioButton_ColorAttenuationMode(bool b);
void slot_pushButton_deleteSelectedObject(); void slot_pushButton_deleteSelectedObject();
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>424</width> <width>424</width>
<height>501</height> <height>468</height>
</rect> </rect>
</property> </property>
<property name="allowedAreas"> <property name="allowedAreas">
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
<string>Visualisation</string> <string>Visualisation</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_6"> <layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0"> <item row="0" column="1">
<widget class="QTabWidget" name="tabWidget_3"> <widget class="QTabWidget" name="tabWidget_3">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>0</number>
...@@ -386,57 +386,117 @@ ...@@ -386,57 +386,117 @@
<attribute name="title"> <attribute name="title">
<string>Global Clip</string> <string>Global Clip</string>
</attribute> </attribute>
<layout class="QHBoxLayout" name="horizontalLayout_6"> <layout class="QVBoxLayout" name="verticalLayout_6">
<item> <item>
<layout class="QGridLayout" name="gridLayout_15"> <widget class="QGroupBox" name="groupBox_ClippingMode">
<item row="0" column="0"> <property name="title">
<widget class="QLabel" name="label_ColorAttenuationFactor"> <string>Clipping Mode</string>
<property name="text"> </property>
<string>Color Att.</string> <widget class="QRadioButton" name="radioButton_ClippingModeAnd">
</property> <property name="geometry">
<property name="wordWrap"> <rect>
<bool>true</bool> <x>30</x>
</property> <y>30</y>
</widget> <width>117</width>
</item> <height>23</height>
<item row="0" column="1"> </rect>
<widget class="QDoubleSpinBox" name="doubleSpinBox_ColorAttenuationFactor"> </property>
<property name="singleStep"> <property name="text">
<double>1.000000000000000</double> <string>AND</string>
</property> </property>
</widget> </widget>
</item> <widget class="QRadioButton" name="radioButton_ClippingModeOr">
<item row="1" column="0"> <property name="geometry">
<widget class="QLabel" name="label_ClippingMode"> <rect>
<property name="text"> <x>30</x>
<string>Clipping Mode</string> <y>60</y>
</property> <width>117</width>
</widget> <height>23</height>
</item> </rect>
<item row="1" column="1"> </property>
<widget class="QSlider" name="horizontalSlider_ClippingMode"> <property name="text">
<property name="maximum"> <string>OR</string>
<number>1</number> </property>
</property> </widget>
<property name="orientation"> </widget>
<enum>Qt::Horizontal</enum> </item>
</property> <item>
</widget> <widget class="QGroupBox" name="groupBox_ColorAttenuation">
</item> <property name="title">
<item row="2" column="1"> <string>Color Attenuation</string>
<spacer name="verticalSpacer_2"> </property>
<property name="orientation"> <widget class="QLabel" name="label_ColorAttenuationFactor">
<enum>Qt::Vertical</enum> <property name="geometry">
</property> <rect>
<property name="sizeHint" stdset="0"> <x>10</x>
<size> <y>30</y>
<width>20</width> <width>38</width>
<height>40</height> <height>41</height>
</size> </rect>
</property> </property>
</spacer> <property name="text">
</item> <string>Color Att.</string>
</layout> </property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="QDoubleSpinBox" name="doubleSpinBox_ColorAttenuationFactor">
<property name="geometry">
<rect>
<x>60</x>
<y>40</y>
<width>73</width>
<height>28</height>
</rect>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
</property>
</widget>
<widget class="QLabel" name="label_ColorAttenuationMode">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>41</width>
<height>61</height>
</rect>
</property>
<property name="text">
<string>Color Att. Mode</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="QRadioButton" name="radioButton_ColorAttenuationModeLinear">
<property name="geometry">
<rect>
<x>70</x>
<y>90</y>
<width>117</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Linear</string>
</property>
</widget>
<widget class="QRadioButton" name="radioButton_ColorAttenuationModeQuadratic">
<property name="geometry">
<rect>
<x>70</x>
<y>110</y>
<width>117</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Quadratic</string>
</property>
</widget>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
......
...@@ -255,6 +255,9 @@ private: ...@@ -255,6 +255,9 @@ private:
public: public:
// enum used to choose clipping color attenuation mode
enum colorAttenuationMode { COLOR_ATTENUATION_MODE_LINEAR, COLOR_ATTENUATION_MODE_QUADRATIC };
/// enum used to choose clipping mode /// enum used to choose clipping mode
enum clippingMode { CLIPPING_MODE_AND, CLIPPING_MODE_OR }; enum clippingMode { CLIPPING_MODE_AND, CLIPPING_MODE_OR };
...@@ -274,6 +277,16 @@ public: ...@@ -274,6 +277,16 @@ public:
/// gets the color attenuation factor /// gets the color attenuation factor
float getClipColorAttenuationFactor(); float getClipColorAttenuationFactor();
/**
* sets the color attenuation mode
* @param colAttMode color attenuation mode
*/
void setClipColorAttenuationMode(colorAttenuationMode colAttMode);
/// gets the color attenuation mode
colorAttenuationMode getClipColorAttenuationMode();
/* /*
* sets the clipping mode * sets the clipping mode
* @param clipMode clipping mode * @param clipMode clipping mode
...@@ -294,6 +307,9 @@ private: ...@@ -294,6 +307,9 @@ private:
/// color attenuation factor uniform id /// color attenuation factor uniform id
GLint m_unif_clipColorAttenuationFactor; GLint m_unif_clipColorAttenuationFactor;
/// color attenuation mode
colorAttenuationMode m_colorAttenuationMode;
/// clipping mode /// clipping mode
clippingMode m_clipMode; clippingMode m_clipMode;
......
...@@ -47,6 +47,7 @@ ClippingShader::ClippingShader(): ...@@ -47,6 +47,7 @@ ClippingShader::ClippingShader():
m_hasClippingCodeBeenInserted (false), m_hasClippingCodeBeenInserted (false),
m_clipColorAttenuationFactor (1.0), m_clipColorAttenuationFactor (1.0),
m_unif_clipColorAttenuationFactor (0), m_unif_clipColorAttenuationFactor (0),
m_colorAttenuationMode (COLOR_ATTENUATION_MODE_LINEAR),
m_clipMode (CLIPPING_MODE_AND) m_clipMode (CLIPPING_MODE_AND)
{ {
...@@ -627,6 +628,10 @@ bool ClippingShader::insertClippingCode() ...@@ -627,6 +628,10 @@ bool ClippingShader::insertClippingCode()
"#define CLIPPING_MODE_OR 1\n" "#define CLIPPING_MODE_OR 1\n"
"#define CLIPPING_MODE 0\n" "#define CLIPPING_MODE 0\n"
"\n" "\n"
"#define CLIPPING_COLOR_ATTENUATION_MODE_LINEAR 0\n"
"#define CLIPPING_COLOR_ATTENUATION_MODE_QUADRATIC 1\n"
"#define CLIPPING_COLOR_ATTENUATION_MODE 0\n"
"\n"
"#if CLIPPING_ENABLED\n" "#if CLIPPING_ENABLED\n"
"\n" "\n"
" #if PLANE_CLIPPING_ENABLED\n" " #if PLANE_CLIPPING_ENABLED\n"
...@@ -644,7 +649,7 @@ bool ClippingShader::insertClippingCode() ...@@ -644,7 +649,7 @@ bool ClippingShader::insertClippingCode()
"#endif\n" "#endif\n"
"\n" "\n"
"#if CLIPPING_ENABLED\n" "#if CLIPPING_ENABLED\n"
"\n"
" float clip_doClippingAndGetClippingDistance()\n" " float clip_doClippingAndGetClippingDistance()\n"
" {\n" " {\n"
" // Distance to the nearest clipping object\n" " // Distance to the nearest clipping object\n"
...@@ -677,33 +682,29 @@ bool ClippingShader::insertClippingCode() ...@@ -677,33 +682,29 @@ bool ClippingShader::insertClippingCode()
" distanceToPlane += currClipPlane.w;\n" " distanceToPlane += currClipPlane.w;\n"
" distanceToPlane /= clipPlaneNormalLength;\n" " distanceToPlane /= clipPlaneNormalLength;\n"
"\n" "\n"
" // Keep the fragment only if it is 'above' the plane\n" " // AND clipping mode discards at first unmatched clipping object\n"
" if (distanceToPlane > 0.0)\n" " #if (CLIPPING_MODE == CLIPPING_MODE_AND)\n"
" {\n" " if (distanceToPlane > 0.0)\n"
" // AND clipping mode discards at first unmatched clipping object\n"
" #if (CLIPPING_MODE == CLIPPING_MODE_AND)\n"
" discard;\n" " discard;\n"
" #endif\n" " #endif\n"
" }\n" "\n"
" else\n" " // In OR clipping mode, one match = no pixel clipping\n"
" {\n" " #if (CLIPPING_MODE == CLIPPING_MODE_OR)\n"
" // In OR clipping mode, one match = no pixel clipping\n" " if (distanceToPlane < 0.0)\n"
" #if (CLIPPING_MODE == CLIPPING_MODE_OR)\n"
" discardPixel = false;\n" " discardPixel = false;\n"
" #endif\n" " #endif\n"
"\n" "\n"
" // Keep the distance to the nearest plane\n" " // Keep the distance to the nearest plane\n"
" if (minDistanceToClipping < 0.0)\n" " if (minDistanceToClipping < 0.0)\n"
" minDistanceToClipping = abs(distanceToPlane);\n" " minDistanceToClipping = abs(distanceToPlane);\n"
" else\n" " else\n"
" minDistanceToClipping = min(minDistanceToClipping, abs(distanceToPlane));\n" " minDistanceToClipping = min(minDistanceToClipping, abs(distanceToPlane));\n"
" }\n"
" }\n" " }\n"
"\n" "\n"
" #endif\n" " #endif\n"
"\n" "\n"
" #if SPHERE_CLIPPING_ENABLED\n" " #if SPHERE_CLIPPING_ENABLED\n"
"\n"
" // Do clipping for each sphere\n" " // Do clipping for each sphere\n"
" for (int i = 0; i < CLIP_SPHERES_COUNT; i++)\n" " for (int i = 0; i < CLIP_SPHERES_COUNT; i++)\n"
" {\n" " {\n"
...@@ -718,27 +719,23 @@ bool ClippingShader::insertClippingCode() ...@@ -718,27 +719,23 @@ bool ClippingShader::insertClippingCode()
" // If the sphere radius is negative, this inverses the clipping effect\n" " // If the sphere radius is negative, this inverses the clipping effect\n"
" distanceToSphere *= sign(currClipSphereRadius);\n" " distanceToSphere *= sign(currClipSphereRadius);\n"
"\n" "\n"
" // Keep the fragment only if it is inside the sphere\n" " // AND clipping mode discards at first unmatched clipping object\n"
" if (distanceToSphere > 0.0)\n" " #if (CLIPPING_MODE == CLIPPING_MODE_AND)\n"
" {\n" " if (distanceToSphere > 0.0)\n"
" // AND clipping mode discards at first unmatched clipping object\n"
" #if (CLIPPING_MODE == CLIPPING_MODE_AND)\n"
" discard;\n" " discard;\n"
" #endif\n" " #endif\n"
" }\n" "\n"
" else\n" " // In OR clipping mode, one match = no pixel clipping\n"
" {\n" " #if (CLIPPING_MODE == CLIPPING_MODE_OR)\n"
" // In OR clipping mode, one match = no pixel clipping\n" " if (distanceToSphere < 0.0)\n"
" #if (CLIPPING_MODE == CLIPPING_MODE_OR)\n"
" discardPixel = false;\n" " discardPixel = false;\n"
" #endif\n" " #endif\n"
"\n" "\n"
" // Keep the distance to the nearest sphere\n" " // Keep the distance to the nearest sphere\n"
" if (minDistanceToClipping < 0.0)\n" " if (minDistanceToClipping < 0.0)\n"
" minDistanceToClipping = abs(distanceToSphere);\n" " minDistanceToClipping = abs(distanceToSphere);\n"
" else\n" " else\n"
" minDistanceToClipping = min(minDistanceToClipping, abs(distanceToSphere));\n" " minDistanceToClipping = min(minDistanceToClipping, abs(distanceToSphere));\n"
" }\n"
" }\n" " }\n"
"\n" "\n"
" #endif\n" " #endif\n"
...@@ -765,9 +762,13 @@ bool ClippingShader::insertClippingCode() ...@@ -765,9 +762,13 @@ bool ClippingShader::insertClippingCode()
std::string FS_mainEndInsertion = std::string FS_mainEndInsertion =
"\n" "\n"
" #if CLIPPING_ENABLED\n" " #if CLIPPING_ENABLED\n"
" // Attenuate the final fragment color depending on its distance to the clipping\n" " // Attenuate the final fragment color depending on its distance to clipping objects\n"
" gl_FragColor.rgb /= (1.0 + clip_minDistanceToClipping * clip_clipColorAttenuationFactor);\n" " float clip_colorAttenuation = clip_minDistanceToClipping * clip_clipColorAttenuationFactor;\n"
" #endif\n"; " #if (CLIPPING_COLOR_ATTENUATION_MODE == CLIPPING_COLOR_ATTENUATION_MODE_QUADRATIC)\n"
" clip_colorAttenuation *= clip_colorAttenuation;\n"
" #endif\n"
" gl_FragColor.rgb /= (1.0 + clip_colorAttenuation);\n"
" #endif;\n";
// Shader name string // Shader name string
std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS; std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;
...@@ -824,12 +825,63 @@ float ClippingShader::getClipColorAttenuationFactor() ...@@ -824,12 +825,63 @@ float ClippingShader::getClipColorAttenuationFactor()
return m_clipColorAttenuationFactor; return m_clipColorAttenuationFactor;
} }
void ClippingShader::setClipColorAttenuationMode(colorAttenuationMode colAttMode)
{
if (colAttMode != m_colorAttenuationMode)
{
// Check if the clipping code has been inserted into shader
if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::setClipColorAttenuationMode"))
return;
// Shader name string
std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;
// Copy the given value
m_colorAttenuationMode = colAttMode;
// Use a shader mutator
ShaderMutator SM(shaderName, getVertexShaderSrc(), getFragmentShaderSrc());
// Change color attenuation mode constant
int newConstantValue;
switch (colAttMode)
{
case COLOR_ATTENUATION_MODE_LINEAR :
newConstantValue = 0;
break;
case COLOR_ATTENUATION_MODE_QUADRATIC :
newConstantValue = 1;
break;
default :
newConstantValue = 0;
break;
}
if (errorRaiseShaderMutatorFailure(
(!SM.changeIntConstantValue(ShaderMutator::FRAGMENT_SHADER, "CLIPPING_COLOR_ATTENUATION_MODE", newConstantValue)),
"ClippingShader::setClipColorAttenuationMode"))
return;
// Reload modified shader
reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str());
// Recompile shaders (automatically calls updateClippingUniforms)
recompile();
}
}
ClippingShader::colorAttenuationMode ClippingShader::getClipColorAttenuationMode()
{
return m_colorAttenuationMode;
}
void ClippingShader::setClipMode(clippingMode clipMode) void ClippingShader::setClipMode(clippingMode clipMode)
{ {
if (clipMode != m_clipMode) if (clipMode != m_clipMode)
{ {
// Check if the clipping code has been inserted into shader // Check if the clipping code has been inserted into shader
if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::setClipPlanesCount")) if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::setClipMode"))
return; return;
// Shader name string // Shader name string
......
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