Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

Commit a5777d30 authored by Maire Nicolas's avatar Maire Nicolas
Browse files

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)
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);
else if (i == 1)
else
m_shader->setClipMode(Utils::ClippingShader::CLIPPING_MODE_OR);
dock.vertexEdit->setPlainText(QString(m_shader->getVertexShaderSrc()));
......@@ -163,6 +163,19 @@ void Clipping::slot_horizontalSlider_ClippingMode(int i)
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()
{
if (m_lastPickedObject)
......@@ -294,14 +307,20 @@ void Clipping::initGUI()
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());
Utils::ClippingShader::clippingMode clipMode = m_shader->getClipMode();
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)
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)
Geom::Vec3f planeNewPos = m_lastPickedObject->getPosition();
float planeNewAxisScale; // Not used
Geom::Vec3f planeNewNormal = m_lastPickedObject->getAxisScale(2, planeNewAxisScale); // 2 = Z axis = plane normal
std::cout << planeNewNormal << std::endl;
// Update clipping shape
m_shader->setClipPlaneParamsAll(m_lastPickedObject->id(), planeNewNormal, planeNewPos);
......
......@@ -148,7 +148,8 @@ public slots:
void slot_doubleSpinBox_SphereGridColor(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();
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>424</width>
<height>501</height>
<height>468</height>
</rect>
</property>
<property name="allowedAreas">
......@@ -31,7 +31,7 @@
<string>Visualisation</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<item row="0" column="1">
<widget class="QTabWidget" name="tabWidget_3">
<property name="currentIndex">
<number>0</number>
......@@ -386,57 +386,117 @@
<attribute name="title">
<string>Global Clip</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QGridLayout" name="gridLayout_15">
<item row="0" column="0">
<widget class="QLabel" name="label_ColorAttenuationFactor">
<property name="text">
<string>Color Att.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBox_ColorAttenuationFactor">
<property name="singleStep">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_ClippingMode">
<property name="text">
<string>Clipping Mode</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSlider" name="horizontalSlider_ClippingMode">
<property name="maximum">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
<widget class="QGroupBox" name="groupBox_ClippingMode">
<property name="title">
<string>Clipping Mode</string>
</property>
<widget class="QRadioButton" name="radioButton_ClippingModeAnd">
<property name="geometry">
<rect>
<x>30</x>
<y>30</y>
<width>117</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>AND</string>
</property>
</widget>
<widget class="QRadioButton" name="radioButton_ClippingModeOr">
<property name="geometry">
<rect>
<x>30</x>
<y>60</y>
<width>117</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>OR</string>
</property>
</widget>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_ColorAttenuation">
<property name="title">
<string>Color Attenuation</string>
</property>
<widget class="QLabel" name="label_ColorAttenuationFactor">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>38</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Color Att.</string>
</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>
</layout>
</widget>
......
......@@ -255,6 +255,9 @@ private:
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 clippingMode { CLIPPING_MODE_AND, CLIPPING_MODE_OR };
......@@ -274,6 +277,16 @@ public:
/// gets the color attenuation factor
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
* @param clipMode clipping mode
......@@ -294,6 +307,9 @@ private:
/// color attenuation factor uniform id
GLint m_unif_clipColorAttenuationFactor;
/// color attenuation mode
colorAttenuationMode m_colorAttenuationMode;
/// clipping mode
clippingMode m_clipMode;
......
......@@ -47,6 +47,7 @@ ClippingShader::ClippingShader():
m_hasClippingCodeBeenInserted (false),
m_clipColorAttenuationFactor (1.0),
m_unif_clipColorAttenuationFactor (0),
m_colorAttenuationMode (COLOR_ATTENUATION_MODE_LINEAR),
m_clipMode (CLIPPING_MODE_AND)
{
......@@ -627,6 +628,10 @@ bool ClippingShader::insertClippingCode()
"#define CLIPPING_MODE_OR 1\n"
"#define CLIPPING_MODE 0\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"
"\n"
" #if PLANE_CLIPPING_ENABLED\n"
......@@ -644,7 +649,7 @@ bool ClippingShader::insertClippingCode()
"#endif\n"
"\n"
"#if CLIPPING_ENABLED\n"
"\n"
" float clip_doClippingAndGetClippingDistance()\n"
" {\n"
" // Distance to the nearest clipping object\n"
......@@ -677,33 +682,29 @@ bool ClippingShader::insertClippingCode()
" distanceToPlane += currClipPlane.w;\n"
" distanceToPlane /= clipPlaneNormalLength;\n"
"\n"
" // Keep the fragment only if it is 'above' the plane\n"
" if (distanceToPlane > 0.0)\n"
" {\n"
" // AND clipping mode discards at first unmatched clipping object\n"
" #if (CLIPPING_MODE == CLIPPING_MODE_AND)\n"
" // AND clipping mode discards at first unmatched clipping object\n"
" #if (CLIPPING_MODE == CLIPPING_MODE_AND)\n"
" if (distanceToPlane > 0.0)\n"
" discard;\n"
" #endif\n"
" }\n"
" else\n"
" {\n"
" // In OR clipping mode, one match = no pixel clipping\n"
" #if (CLIPPING_MODE == CLIPPING_MODE_OR)\n"
" #endif\n"
"\n"
" // In OR clipping mode, one match = no pixel clipping\n"
" #if (CLIPPING_MODE == CLIPPING_MODE_OR)\n"
" if (distanceToPlane < 0.0)\n"
" discardPixel = false;\n"
" #endif\n"
" #endif\n"
"\n"
" // Keep the distance to the nearest plane\n"
" if (minDistanceToClipping < 0.0)\n"
" minDistanceToClipping = abs(distanceToPlane);\n"
" else\n"
" minDistanceToClipping = min(minDistanceToClipping, abs(distanceToPlane));\n"
" }\n"
" // Keep the distance to the nearest plane\n"
" if (minDistanceToClipping < 0.0)\n"
" minDistanceToClipping = abs(distanceToPlane);\n"
" else\n"
" minDistanceToClipping = min(minDistanceToClipping, abs(distanceToPlane));\n"
" }\n"
"\n"
" #endif\n"
"\n"
" #if SPHERE_CLIPPING_ENABLED\n"
"\n"
" // Do clipping for each sphere\n"
" for (int i = 0; i < CLIP_SPHERES_COUNT; i++)\n"
" {\n"
......@@ -718,27 +719,23 @@ bool ClippingShader::insertClippingCode()
" // If the sphere radius is negative, this inverses the clipping effect\n"
" distanceToSphere *= sign(currClipSphereRadius);\n"
"\n"
" // Keep the fragment only if it is inside the sphere\n"
" if (distanceToSphere > 0.0)\n"
" {\n"
" // AND clipping mode discards at first unmatched clipping object\n"
" #if (CLIPPING_MODE == CLIPPING_MODE_AND)\n"
" // AND clipping mode discards at first unmatched clipping object\n"
" #if (CLIPPING_MODE == CLIPPING_MODE_AND)\n"
" if (distanceToSphere > 0.0)\n"
" discard;\n"
" #endif\n"
" }\n"
" else\n"
" {\n"
" // In OR clipping mode, one match = no pixel clipping\n"
" #if (CLIPPING_MODE == CLIPPING_MODE_OR)\n"
" #endif\n"
"\n"
" // In OR clipping mode, one match = no pixel clipping\n"
" #if (CLIPPING_MODE == CLIPPING_MODE_OR)\n"
" if (distanceToSphere < 0.0)\n"
" discardPixel = false;\n"
" #endif\n"
" #endif\n"
"\n"
" // Keep the distance to the nearest sphere\n"
" if (minDistanceToClipping < 0.0)\n"
" minDistanceToClipping = abs(distanceToSphere);\n"
" else\n"
" minDistanceToClipping = min(minDistanceToClipping, abs(distanceToSphere));\n"
" }\n"
" // Keep the distance to the nearest sphere\n"
" if (minDistanceToClipping < 0.0)\n"
" minDistanceToClipping = abs(distanceToSphere);\n"
" else\n"
" minDistanceToClipping = min(minDistanceToClipping, abs(distanceToSphere));\n"
" }\n"
"\n"
" #endif\n"
......@@ -765,9 +762,13 @@ bool ClippingShader::insertClippingCode()
std::string FS_mainEndInsertion =
"\n"
" #if CLIPPING_ENABLED\n"
" // Attenuate the final fragment color depending on its distance to the clipping\n"
" gl_FragColor.rgb /= (1.0 + clip_minDistanceToClipping * clip_clipColorAttenuationFactor);\n"
" #endif\n";
" // Attenuate the final fragment color depending on its distance to clipping objects\n"
" float clip_colorAttenuation = clip_minDistanceToClipping * clip_clipColorAttenuationFactor;\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
std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;
......@@ -824,12 +825,63 @@ float ClippingShader::getClipColorAttenuationFactor()
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)
{
if (clipMode != m_clipMode)
{
// Check if the clipping code has been inserted into shader
if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::setClipPlanesCount"))
if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::setClipMode"))
return;
// 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