summaryrefslogtreecommitdiffstats
path: root/src/datavisualization
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 /src/datavisualization
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>
Diffstat (limited to 'src/datavisualization')
-rw-r--r--src/datavisualization/utils/scatterobjectbufferhelper.cpp13
1 files changed, 13 insertions, 0 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;