summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@theqtcompany.com>2014-10-13 15:55:32 +0300
committerMiikka Heikkinen <miikka.heikkinen@theqtcompany.com>2014-10-14 08:56:31 +0300
commit4f70d3777e036f131cf8d39e1072b276132e32a1 (patch)
tree26b47c5af111f5b4f0c5cf9771a86659a3319e3a
parent631d9bead3aac19bcc5bdbd79df54e7aa216ecff (diff)
Fix gradient artifacts on some edge cases
When static optimization is in use with mesh objects and range gradient, and the object Y-value resolves into a texture coordinate that is exactly on the texel boundary, the rendered fragments of the object are not all same colors on some graphics cards, despite all vertices having the same UV value. Fixed by adjusting the Y-value slightly if it is close to the boundary. Task-number: QTRD-3370 Change-Id: Ie028602cbd9a00bb0e17049eb8f40feb8b18a6bf Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
-rw-r--r--src/datavisualization/utils/scatterobjectbufferhelper.cpp13
-rw-r--r--tests/scattertest/scatterchart.cpp15
2 files changed, 27 insertions, 1 deletions
diff --git a/src/datavisualization/utils/scatterobjectbufferhelper.cpp b/src/datavisualization/utils/scatterobjectbufferhelper.cpp
index dae60b96..6135c225 100644
--- a/src/datavisualization/utils/scatterobjectbufferhelper.cpp
+++ b/src/datavisualization/utils/scatterobjectbufferhelper.cpp
@@ -20,6 +20,7 @@
#include "objecthelper_p.h"
#include <QtGui/QVector2D>
#include <QtGui/QMatrix4x4>
+#include <QtCore/qmath.h>
QT_BEGIN_NAMESPACE_DATAVISUALIZATION
@@ -232,6 +233,8 @@ uint ScatterObjectBufferHelper::createRangeGradientUVs(ScatterSeriesRenderCache
const ScatterRenderItemArray &renderArray = cache->renderArray();
const bool updateAll = (cache->updateIndices().size() == 0);
const int updateSize = updateAll ? renderArray.size() : cache->updateIndices().size();
+ const float yAdjustment = 0.1f / gradientTextureHeight;
+ const float flippedYAdjustment = 0.9f / gradientTextureHeight;
QVector2D uv;
uv.setX(0.0f);
@@ -243,7 +246,17 @@ uint ScatterObjectBufferHelper::createRangeGradientUVs(ScatterSeriesRenderCache
continue;
float y = ((item.translation().y() + m_scaleY) * 0.5f) / m_scaleY;
+
+ // Avoid values near gradient texel boundary, as this causes artifacts
+ // with some graphics cards.
+ const float floorY = float(qFloor(y * gradientTextureHeight));
+ const float diff = y - floorY;
+ if (diff < yAdjustment)
+ y += yAdjustment;
+ else if (diff > flippedYAdjustment)
+ y -= yAdjustment;
uv.setY(y);
+
int offset = pos * uvsCount;
for (int j = 0; j < uvsCount; j++)
buffered_uvs[j + offset] = uv;
diff --git a/tests/scattertest/scatterchart.cpp b/tests/scattertest/scatterchart.cpp
index c7b93c32..e5a7acc3 100644
--- a/tests/scattertest/scatterchart.cpp
+++ b/tests/scattertest/scatterchart.cpp
@@ -723,8 +723,21 @@ void ScatterDataModifier::changeBunch()
if (m_targetSeries->dataProxy()->array()->size()) {
int amount = qMin(m_targetSeries->dataProxy()->array()->size(), 100);
QScatterDataArray items(amount);
- for (int i = 0; i < items.size(); i++)
+ for (int i = 0; i < items.size(); i++) {
items[i].setPosition(randVector());
+ // Change the Y-values of first few items to exact gradient boundaries
+ if (i == 0)
+ items[i].setY(0.65f);
+ else if (i == 1)
+ items[i].setY(0.1f);
+ else if (i == 2)
+ items[i].setY(-0.45f);
+ else if (i == 3)
+ items[i].setY(-1.0f);
+ else if (i == 4)
+ items[i].setY(1.2f);
+ }
+
m_targetSeries->dataProxy()->setItems(0, items);
qDebug() << m_loopCounter << "Changed bunch, array size:" << m_targetSeries->dataProxy()->array()->size();
}