From 4f70d3777e036f131cf8d39e1072b276132e32a1 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 13 Oct 2014 15:55:32 +0300 Subject: Fix gradient artifacts on some edge cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ää --- src/datavisualization/utils/scatterobjectbufferhelper.cpp | 13 +++++++++++++ tests/scattertest/scatterchart.cpp | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) 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 #include +#include 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(); } -- cgit v1.2.3