From 4e9ed2481a1960a2fc4a31ecd14d1904b76cad2e Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 1 Jul 2014 15:47:07 +0300 Subject: Fix labels and grid lines changing size when aspect ratio is changed Since shaders needed fixing anyway for surface because of this, also implements the support for object gradients for surface, which was missing. Task-number: QTRD-2666 Task-number: QTRD-3211 Change-Id: I0c5da7fdfef308a96ec0bae4750fd22035da4e82 Reviewed-by: Mika Salmela --- .../engine/abstract3drenderer.cpp | 25 ++++---- .../engine/abstract3drenderer_p.h | 1 + src/datavisualization/engine/scatter3drenderer.cpp | 68 +++++++++++++--------- src/datavisualization/engine/scatter3drenderer_p.h | 2 +- src/datavisualization/engine/shaders/surface.frag | 4 +- .../engine/shaders/surfaceFlat.frag | 4 +- .../engine/shaders/surfaceShadowFlat.frag | 6 +- .../engine/shaders/surfaceShadowNoTex.frag | 6 +- .../engine/shaders/surface_ES2.frag | 4 +- src/datavisualization/engine/surface3drenderer.cpp | 68 +++++++++++++++------- src/datavisualization/engine/surface3drenderer_p.h | 1 + 11 files changed, 118 insertions(+), 71 deletions(-) (limited to 'src/datavisualization/engine') diff --git a/src/datavisualization/engine/abstract3drenderer.cpp b/src/datavisualization/engine/abstract3drenderer.cpp index 782b1480..c2ed43da 100644 --- a/src/datavisualization/engine/abstract3drenderer.cpp +++ b/src/datavisualization/engine/abstract3drenderer.cpp @@ -69,6 +69,7 @@ Abstract3DRenderer::Abstract3DRenderer(Abstract3DController *controller) m_graphHorizontalAspectRatio(0.0f), m_polarGraph(false), m_radialLabelOffset(1.0f), + m_polarRadius(2.0f), m_xRightAngleRotation(QQuaternion::fromAxisAndAngle(1.0f, 0.0f, 0.0f, 90.0f)), m_yRightAngleRotation(QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, 90.0f)), m_zRightAngleRotation(QQuaternion::fromAxisAndAngle(0.0f, 0.0f, 1.0f, 90.0f)), @@ -313,8 +314,6 @@ void Abstract3DRenderer::updateSelectionMode(QAbstract3DGraph::SelectionFlags mo void Abstract3DRenderer::updateAspectRatio(float ratio) { m_graphAspectRatio = ratio; - calculateZoomLevel(); - m_cachedScene->activeCamera()->d_ptr->updateViewMatrix(m_autoScaleAdjustment); foreach (SeriesRenderCache *cache, m_renderCacheList) cache->setDataDirty(true); updateCustomItemPositions(); @@ -369,9 +368,9 @@ void Abstract3DRenderer::calculateZoomLevel() GLfloat div; GLfloat zoomAdjustment; div = qMin(m_primarySubViewport.width(), m_primarySubViewport.height()); - zoomAdjustment = 2.0f * defaultRatio + zoomAdjustment = defaultRatio * ((m_primarySubViewport.width() / div) - / (m_primarySubViewport.height() / div)) / m_graphAspectRatio; + / (m_primarySubViewport.height() / div)); m_autoScaleAdjustment = qMin(zoomAdjustment, 1.0f); // clamp to 1.0f } @@ -1206,8 +1205,8 @@ void Abstract3DRenderer::calculatePolarXZ(const QVector3D &dataPos, float &x, fl qreal radius = m_axisCacheZ.formatter()->positionAt(dataPos.z()); // Convert angle & radius to X and Z coords - x = float(radius * qSin(angle)) * m_graphAspectRatio; - z = -float(radius * qCos(angle)) * m_graphAspectRatio; + x = float(radius * qSin(angle)) * m_polarRadius; + z = -float(radius * qCos(angle)) * m_polarRadius; } void Abstract3DRenderer::drawRadialGrid(ShaderHelper *shader, float yFloorLinePos, @@ -1234,10 +1233,10 @@ void Abstract3DRenderer::drawRadialGrid(ShaderHelper *shader, float yFloorLinePo for (int i = 0; i < gridLineCount; i++) { float gridPosition = (i >= mainSize) ? subGridPositions.at(i - mainSize) : gridPositions.at(i); - float radiusFraction = m_graphAspectRatio * gridPosition; + float radiusFraction = m_polarRadius * gridPosition; QVector3D gridLineScaler(radiusFraction * float(qSin(polarGridHalfAngle)), gridLineWidth, gridLineWidth); - translateVector.setZ(gridPosition * m_graphAspectRatio); + translateVector.setZ(gridPosition * m_polarRadius); for (int j = 0; j < polarGridRoundness; j++) { QMatrix4x4 modelMatrix; QMatrix4x4 itModelMatrix; @@ -1275,7 +1274,7 @@ void Abstract3DRenderer::drawAngularGrid(ShaderHelper *shader, float yFloorLineP const QMatrix4x4 &projectionViewMatrix, const QMatrix4x4 &depthMatrix) { - float halfRatio((m_graphAspectRatio + (labelMargin / 2.0f)) / 2.0f); + float halfRatio((m_polarRadius + (labelMargin / 2.0f)) / 2.0f); QVector3D gridLineScaler(gridLineWidth, gridLineWidth, halfRatio); int gridLineCount = m_axisCacheX.gridLineCount(); const QVector &gridPositions = m_axisCacheX.formatter()->gridPositions(); @@ -1337,10 +1336,10 @@ float Abstract3DRenderer::calculatePolarBackgroundMargin() float actualLabelWidth = actualLabelHeight / labelSize.height() * labelSize.width(); float labelPosition = labelPositions.at(label); qreal angle = labelPosition * M_PI * 2.0; - float x = qAbs((m_graphAspectRatio + labelMargin) * float(qSin(angle))) - + actualLabelWidth - m_graphAspectRatio + labelMargin; - float z = qAbs(-(m_graphAspectRatio + labelMargin) * float(qCos(angle))) - + actualLabelHeight - m_graphAspectRatio + labelMargin; + float x = qAbs((m_polarRadius + labelMargin) * float(qSin(angle))) + + actualLabelWidth - m_polarRadius + labelMargin; + float z = qAbs(-(m_polarRadius + labelMargin) * float(qCos(angle))) + + actualLabelHeight - m_polarRadius + labelMargin; float neededMargin = qMax(x, z); maxNeededMargin = qMax(maxNeededMargin, neededMargin); } diff --git a/src/datavisualization/engine/abstract3drenderer_p.h b/src/datavisualization/engine/abstract3drenderer_p.h index f7fa748b..40c7db0a 100644 --- a/src/datavisualization/engine/abstract3drenderer_p.h +++ b/src/datavisualization/engine/abstract3drenderer_p.h @@ -260,6 +260,7 @@ protected: float m_graphHorizontalAspectRatio; bool m_polarGraph; float m_radialLabelOffset; + float m_polarRadius; QQuaternion m_xRightAngleRotation; QQuaternion m_yRightAngleRotation; diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp index 56219339..76b955e8 100644 --- a/src/datavisualization/engine/scatter3drenderer.cpp +++ b/src/datavisualization/engine/scatter3drenderer.cpp @@ -57,8 +57,8 @@ Scatter3DRenderer::Scatter3DRenderer(Scatter3DController *controller) m_selectionDepthBuffer(0), m_shadowQualityToShader(100.0f), m_shadowQualityMultiplier(3), - m_heightNormalizer(1.0f), m_scaleX(0.0f), + m_scaleY(0.0f), m_scaleZ(0.0f), m_scaleXWithBackground(0.0f), m_scaleYWithBackground(0.0f), @@ -75,9 +75,6 @@ Scatter3DRenderer::Scatter3DRenderer(Scatter3DController *controller) m_haveUniformColorMeshSeries(false), m_haveGradientMeshSeries(false) { - m_axisCacheY.setScale(2.0f); - m_axisCacheY.setTranslate(-1.0f); - initializeOpenGLFunctions(); initializeOpenGL(); } @@ -707,6 +704,9 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) dotShader->bind(); } + float rangeGradientYScaler = 0.5f / m_scaleY; + float rangeGradientYScalerForPoints = rangeGradientYScaler * 100.0f; + foreach (SeriesRenderCache *baseCache, m_renderCacheList) { if (baseCache->isVisible()) { ScatterSeriesRenderCache *cache = @@ -808,7 +808,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) if (rangeGradientPoints) { // Drawing points with range gradient // Get color from gradient based on items y position converted to percent - int position = int(item.translation().y() * 50.0f) + 50; + int position = int(item.translation().y() * rangeGradientYScalerForPoints) + + 50; dotColor = Utils::vectorFromColor( cache->gradientImage().pixel(0, position)); } else { @@ -825,13 +826,12 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) else gradientTexture = cache->singleHighlightGradientTexture(); lightStrength = m_cachedTheme->highlightLightStrength(); - // Insert data to ScatterRenderItem - // We don't have ownership, so don't delete the previous one + // Save the reference to the item to be used in label drawing selectedItem = &item; dotSelectionFound = true; // Save selected item size (adjusted with font size) for selection label // positioning - selectedItemSize = itemSize + (m_cachedTheme->font().pointSizeF() / 500.0f); + selectedItemSize = itemSize + m_drawer->scaledFontSize() - 0.05f; } if (!drawingPoints) { @@ -846,7 +846,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) dotShader->setUniformValue(dotShader->color(), dotColor); } else if (colorStyle == Q3DTheme::ColorStyleRangeGradient) { dotShader->setUniformValue(dotShader->gradientMin(), - (item.translation().y() + 1.0f) / 2.0f); + (item.translation().y() + m_scaleY) + * rangeGradientYScaler); } #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QAbstract3DGraph::ShadowQualityNone) { @@ -925,12 +926,12 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) else gradientTexture = cache->singleHighlightGradientTexture(); GLfloat lightStrength = m_cachedTheme->highlightLightStrength(); - // Save the reference to the item to be used on label drawing + // Save the reference to the item to be used in label drawing selectedItem = &item; dotSelectionFound = true; // Save selected item size (adjusted with font size) for selection label // positioning - selectedItemSize = itemSize + (m_cachedTheme->font().pointSizeF() / 500.0f); + selectedItemSize = itemSize + m_drawer->scaledFontSize() - 0.05f; if (!drawingPoints) { // Set shader bindings @@ -944,7 +945,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) dotShader->setUniformValue(dotShader->color(), dotColor); } else if (colorStyle == Q3DTheme::ColorStyleRangeGradient) { dotShader->setUniformValue(dotShader->gradientMin(), - (item.translation().y() + 1.0f) / 2.0f); + (item.translation().y() + m_scaleY) + * rangeGradientYScaler); } if (!drawingPoints) { @@ -1575,7 +1577,7 @@ void Scatter3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa if (m_polarGraph) { float direction = m_zFlipped ? -1.0f : 1.0f; labelTrans.setZ((m_axisCacheZ.formatter()->labelPositions().at(label) - * -m_graphAspectRatio + * -m_polarRadius + m_drawer->scaledFontSize() + gridLineWidth) * direction); } else { labelTrans.setZ(m_axisCacheZ.labelPosition(label)); @@ -1596,7 +1598,7 @@ void Scatter3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa } if (!drawSelection && m_axisCacheZ.isTitleVisible()) { if (m_polarGraph) { - float titleZ = -m_graphAspectRatio / 2.0f; + float titleZ = -m_polarRadius / 2.0f; if (m_zFlipped) titleZ = -titleZ; labelTrans.setZ(titleZ); @@ -1730,8 +1732,8 @@ void Scatter3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa continue; float labelPosition = labelPositions.at(label); qreal angle = labelPosition * M_PI * 2.0; - labelTrans.setX((m_graphAspectRatio + labelMargin) * float(qSin(angle))); - labelTrans.setZ(-(m_graphAspectRatio + labelMargin) * float(qCos(angle))); + labelTrans.setX((m_polarRadius + labelMargin) * float(qSin(angle))); + labelTrans.setZ(-(m_polarRadius + labelMargin) * float(qCos(angle))); // Alignment depends on label angular position, as well as flips Qt::AlignmentFlag vAlignment = Qt::AlignCenter; Qt::AlignmentFlag hAlignment = Qt::AlignCenter; @@ -1776,7 +1778,7 @@ void Scatter3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa totalRotation *= m_zRightAngleRotationNeg; if (m_yFlippedForGrid) totalRotation *= QQuaternion::fromAxisAndAngle(0.0f, 0.0f, 1.0f, -180.0f); - labelTrans.setZ(-m_graphAspectRatio); + labelTrans.setZ(-m_polarRadius); radial = true; } drawAxisTitleX(labelRotation, labelTrans, totalRotation, m_dummyRenderItem, @@ -2022,8 +2024,6 @@ void Scatter3DRenderer::calculateSceneScalingFactors() m_hBackgroundMargin = qMax(m_hBackgroundMargin, polarMargin); } - m_heightNormalizer = GLfloat(m_axisCacheY.max() - m_axisCacheY.min()) / 2.0f; - float horizontalAspectRatio; if (m_polarGraph) horizontalAspectRatio = 1.0f; @@ -2039,19 +2039,31 @@ void Scatter3DRenderer::calculateSceneScalingFactors() areaSize.setWidth(horizontalAspectRatio); } + float horizontalMaxDimension; + if (m_graphAspectRatio > 2.0f) { + horizontalMaxDimension = 2.0f; + m_scaleY = 2.0f / m_graphAspectRatio; + } else { + horizontalMaxDimension = m_graphAspectRatio; + m_scaleY = 1.0f; + } + if (m_polarGraph) + m_polarRadius = horizontalMaxDimension; + float scaleFactor = qMax(areaSize.width(), areaSize.height()); - m_scaleX = m_graphAspectRatio * areaSize.width() / scaleFactor; - m_scaleZ = m_graphAspectRatio * areaSize.height() / scaleFactor; + m_scaleX = horizontalMaxDimension * areaSize.width() / scaleFactor; + m_scaleZ = horizontalMaxDimension * areaSize.height() / scaleFactor; m_scaleXWithBackground = m_scaleX + m_hBackgroundMargin; + m_scaleYWithBackground = m_scaleY + m_vBackgroundMargin; m_scaleZWithBackground = m_scaleZ + m_hBackgroundMargin; - m_scaleYWithBackground = m_vBackgroundMargin + 1.0f; - float factorScaler = 2.0f * m_graphAspectRatio / scaleFactor; - m_axisCacheX.setScale(factorScaler * areaSize.width()); - m_axisCacheZ.setScale(-factorScaler * areaSize.height()); - m_axisCacheX.setTranslate(-m_axisCacheX.scale() / 2.0f); - m_axisCacheZ.setTranslate(-m_axisCacheZ.scale() / 2.0f); + m_axisCacheX.setScale(m_scaleX * 2.0f); + m_axisCacheY.setScale(m_scaleY * 2.0f); + m_axisCacheZ.setScale(m_scaleZ * 2.0f); + m_axisCacheX.setTranslate(-m_scaleX); + m_axisCacheY.setTranslate(-m_scaleY); + m_axisCacheZ.setTranslate(-m_scaleZ); } void Scatter3DRenderer::initShaders(const QString &vertexShader, const QString &fragmentShader) @@ -2237,7 +2249,7 @@ QVector3D Scatter3DRenderer::convertPositionToTranslation(const QVector3D &posit yTrans = m_axisCacheY.positionAt(position.y()); } else { xTrans = position.x() * m_scaleX; - yTrans = position.y(); + yTrans = position.y() * m_scaleY; zTrans = position.z() * m_scaleZ; } return QVector3D(xTrans, yTrans, zTrans); diff --git a/src/datavisualization/engine/scatter3drenderer_p.h b/src/datavisualization/engine/scatter3drenderer_p.h index 645a2a8e..9baad16a 100644 --- a/src/datavisualization/engine/scatter3drenderer_p.h +++ b/src/datavisualization/engine/scatter3drenderer_p.h @@ -67,8 +67,8 @@ private: GLuint m_selectionDepthBuffer; GLfloat m_shadowQualityToShader; GLint m_shadowQualityMultiplier; - float m_heightNormalizer; float m_scaleX; + float m_scaleY; float m_scaleZ; float m_scaleXWithBackground; float m_scaleYWithBackground; diff --git a/src/datavisualization/engine/shaders/surface.frag b/src/datavisualization/engine/shaders/surface.frag index f17dd73e..238e5fed 100644 --- a/src/datavisualization/engine/shaders/surface.frag +++ b/src/datavisualization/engine/shaders/surface.frag @@ -11,9 +11,11 @@ uniform highp vec3 lightPosition_wrld; uniform highp float lightStrength; uniform highp float ambientStrength; uniform highp vec4 lightColor; +uniform highp float gradMin; +uniform highp float gradHeight; void main() { - highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.0) / 2.0); + highp vec2 gradientUV = vec2(0.0, gradMin + coords_mdl.y * gradHeight); highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; highp vec3 materialAmbientColor = lightColor.rgb * ambientStrength * materialDiffuseColor; highp vec3 materialSpecularColor = lightColor.rgb; diff --git a/src/datavisualization/engine/shaders/surfaceFlat.frag b/src/datavisualization/engine/shaders/surfaceFlat.frag index 748fb3dd..1a0bbdeb 100644 --- a/src/datavisualization/engine/shaders/surfaceFlat.frag +++ b/src/datavisualization/engine/shaders/surfaceFlat.frag @@ -13,9 +13,11 @@ uniform highp vec3 lightPosition_wrld; uniform highp float lightStrength; uniform highp float ambientStrength; uniform highp vec4 lightColor; +uniform highp float gradMin; +uniform highp float gradHeight; void main() { - highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.0) / 2.0); + highp vec2 gradientUV = vec2(0.0, gradMin + coords_mdl.y * gradHeight); highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; highp vec3 materialAmbientColor = lightColor.rgb * ambientStrength * materialDiffuseColor; highp vec3 materialSpecularColor = lightColor.rgb; diff --git a/src/datavisualization/engine/shaders/surfaceShadowFlat.frag b/src/datavisualization/engine/shaders/surfaceShadowFlat.frag index 0613a40c..4b0dfae0 100644 --- a/src/datavisualization/engine/shaders/surfaceShadowFlat.frag +++ b/src/datavisualization/engine/shaders/surfaceShadowFlat.frag @@ -7,15 +7,17 @@ varying highp vec3 position_wrld; flat varying highp vec3 normal_cmr; varying highp vec3 eyeDirection_cmr; varying highp vec3 lightDirection_cmr; +varying highp vec4 shadowCoord; uniform highp sampler2DShadow shadowMap; uniform sampler2D textureSampler; -varying highp vec4 shadowCoord; uniform highp vec3 lightPosition_wrld; uniform highp float lightStrength; uniform highp float ambientStrength; uniform highp float shadowQuality; uniform highp vec4 lightColor; +uniform highp float gradMin; +uniform highp float gradHeight; highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), vec2(0.94558609, -0.76890725), @@ -35,7 +37,7 @@ highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), vec2(0.14383161, -0.14100790)); void main() { - highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.0) / 2.0); + highp vec2 gradientUV = vec2(0.0, gradMin + coords_mdl.y * gradHeight); highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; highp vec3 materialAmbientColor = lightColor.rgb * ambientStrength * materialDiffuseColor; highp vec3 materialSpecularColor = lightColor.rgb; diff --git a/src/datavisualization/engine/shaders/surfaceShadowNoTex.frag b/src/datavisualization/engine/shaders/surfaceShadowNoTex.frag index 1acf8f69..d6195227 100644 --- a/src/datavisualization/engine/shaders/surfaceShadowNoTex.frag +++ b/src/datavisualization/engine/shaders/surfaceShadowNoTex.frag @@ -5,15 +5,17 @@ varying highp vec3 position_wrld; varying highp vec3 normal_cmr; varying highp vec3 eyeDirection_cmr; varying highp vec3 lightDirection_cmr; +varying highp vec4 shadowCoord; uniform highp sampler2DShadow shadowMap; uniform sampler2D textureSampler; -varying highp vec4 shadowCoord; uniform highp vec3 lightPosition_wrld; uniform highp float lightStrength; uniform highp float ambientStrength; uniform highp float shadowQuality; uniform highp vec4 lightColor; +uniform highp float gradMin; +uniform highp float gradHeight; highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), vec2(0.94558609, -0.76890725), @@ -33,7 +35,7 @@ highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), vec2(0.14383161, -0.14100790)); void main() { - highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.0) / 2.0); + highp vec2 gradientUV = vec2(0.0, gradMin + coords_mdl.y * gradHeight); highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; highp vec3 materialAmbientColor = lightColor.rgb * ambientStrength * materialDiffuseColor; highp vec3 materialSpecularColor = lightColor.rgb; diff --git a/src/datavisualization/engine/shaders/surface_ES2.frag b/src/datavisualization/engine/shaders/surface_ES2.frag index 58d13834..1d1bdc3e 100644 --- a/src/datavisualization/engine/shaders/surface_ES2.frag +++ b/src/datavisualization/engine/shaders/surface_ES2.frag @@ -10,9 +10,11 @@ uniform sampler2D textureSampler; uniform highp float lightStrength; uniform highp float ambientStrength; uniform highp vec4 lightColor; +uniform highp float gradMin; +uniform highp float gradHeight; void main() { - highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.0) / 2.0); + highp vec2 gradientUV = vec2(0.0, gradMin + coords_mdl.y * gradHeight); highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; highp vec3 materialAmbientColor = lightColor.rgb * ambientStrength * materialDiffuseColor; highp vec3 materialSpecularColor = lightColor.rgb; diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp index c1a23493..f5f05498 100644 --- a/src/datavisualization/engine/surface3drenderer.cpp +++ b/src/datavisualization/engine/surface3drenderer.cpp @@ -50,6 +50,7 @@ Surface3DRenderer::Surface3DRenderer(Surface3DController *controller) m_labelShader(0), m_heightNormalizer(0.0f), m_scaleX(0.0f), + m_scaleY(0.0f), m_scaleZ(0.0f), m_scaleXWithBackground(0.0f), m_scaleYWithBackground(0.0f), @@ -70,9 +71,6 @@ Surface3DRenderer::Surface3DRenderer(Surface3DController *controller) m_selectionTexturesDirty(false), m_noShadowTexture(0) { - m_axisCacheY.setScale(2.0f); - m_axisCacheY.setTranslate(-1.0f); - // Check if flat feature is supported ShaderHelper tester(this, QStringLiteral(":/shaders/vertexSurfaceFlat"), QStringLiteral(":/shaders/fragmentSurfaceFlat")); @@ -834,7 +832,7 @@ void Surface3DRenderer::drawSlicedScene() glCullFace(GL_BACK); // Grid lines - if (m_cachedTheme->isGridEnabled() && m_heightNormalizer) { + if (m_cachedTheme->isGridEnabled()) { #if !(defined QT_OPENGL_ES_2) ShaderHelper *lineShader = m_backgroundShader; #else @@ -1257,7 +1255,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) // Draw the surface if (!m_renderCacheList.isEmpty()) { - // For surface we can see climpses from underneath + // For surface we can see glimpses from underneath glDisable(GL_CULL_FACE); bool drawGrid = false; @@ -1303,10 +1301,24 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) shader->setUniformValue(shader->lightColor(), lightColor); GLuint gradientTexture; - if (cache->colorStyle() == Q3DTheme::ColorStyleUniform) + if (cache->colorStyle() == Q3DTheme::ColorStyleUniform) { gradientTexture = cache->baseUniformTexture(); - else + shader->setUniformValue(shader->gradientMin(), 0.0f); + shader->setUniformValue(shader->gradientHeight(), 0.0f); + } else { gradientTexture = cache->baseGradientTexture(); + if (cache->colorStyle() == Q3DTheme::ColorStyleObjectGradient) { + float objMin = cache->surfaceObject()->minYValue(); + float objMax = cache->surfaceObject()->maxYValue(); + float objRange = objMax - objMin; + shader->setUniformValue(shader->gradientMin(), -(objMin / objRange)); + shader->setUniformValue(shader->gradientHeight(), 1.0f / objRange); + } else { + shader->setUniformValue(shader->gradientMin(), 0.5f); + shader->setUniformValue(shader->gradientHeight(), + 1.0f / (m_scaleY * 2.0f)); + } + } #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QAbstract3DGraph::ShadowQualityNone) { @@ -1433,7 +1445,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) QVector3D gridLineScaleZ(gridLineWidth, gridLineWidth, m_scaleZWithBackground); QVector3D gridLineScaleY(gridLineWidth, m_scaleYWithBackground, gridLineWidth); - if (m_cachedTheme->isGridEnabled() && m_heightNormalizer) { + if (m_cachedTheme->isGridEnabled()) { #if !(defined QT_OPENGL_ES_2) ShaderHelper *lineShader = m_backgroundShader; #else @@ -1947,7 +1959,7 @@ void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa if (m_polarGraph) { float direction = m_zFlipped ? -1.0f : 1.0f; labelTrans.setZ((m_axisCacheZ.formatter()->labelPositions().at(label) - * -m_graphAspectRatio + * -m_polarRadius + m_drawer->scaledFontSize() + gridLineWidth) * direction); } else { labelTrans.setZ(m_axisCacheZ.labelPosition(label)); @@ -1968,7 +1980,7 @@ void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa } if (!drawSelection && m_axisCacheZ.isTitleVisible()) { if (m_polarGraph) { - float titleZ = -m_graphAspectRatio / 2.0f; + float titleZ = -m_polarRadius / 2.0f; if (m_zFlipped) titleZ = -titleZ; labelTrans.setZ(titleZ); @@ -2106,8 +2118,8 @@ void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa continue; float labelPosition = labelPositions.at(label); qreal angle = labelPosition * M_PI * 2.0; - labelTrans.setX((m_graphAspectRatio + labelMargin) * float(qSin(angle))); - labelTrans.setZ(-(m_graphAspectRatio + labelMargin) * float(qCos(angle))); + labelTrans.setX((m_polarRadius + labelMargin) * float(qSin(angle))); + labelTrans.setZ(-(m_polarRadius + labelMargin) * float(qCos(angle))); // Alignment depends on label angular position, as well as flips Qt::AlignmentFlag vAlignment = Qt::AlignCenter; Qt::AlignmentFlag hAlignment = Qt::AlignCenter; @@ -2152,7 +2164,7 @@ void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa totalRotation *= m_zRightAngleRotationNeg; if (m_yFlippedForGrid) totalRotation *= QQuaternion::fromAxisAndAngle(0.0f, 0.0f, 1.0f, -180.0f); - labelTrans.setZ(-m_graphAspectRatio); + labelTrans.setZ(-m_polarRadius); radial = true; } drawAxisTitleX(labelRotation, labelTrans, totalRotation, m_dummyRenderItem, @@ -2415,19 +2427,31 @@ void Surface3DRenderer::calculateSceneScalingFactors() areaSize.setWidth(horizontalAspectRatio); } + float horizontalMaxDimension; + if (m_graphAspectRatio > 2.0f) { + horizontalMaxDimension = 2.0f; + m_scaleY = 2.0f / m_graphAspectRatio; + } else { + horizontalMaxDimension = m_graphAspectRatio; + m_scaleY = 1.0f; + } + if (m_polarGraph) + m_polarRadius = horizontalMaxDimension; + float scaleFactor = qMax(areaSize.width(), areaSize.height()); - m_scaleX = m_graphAspectRatio * areaSize.width() / scaleFactor; - m_scaleZ = m_graphAspectRatio * areaSize.height() / scaleFactor; + m_scaleX = horizontalMaxDimension * areaSize.width() / scaleFactor; + m_scaleZ = horizontalMaxDimension * areaSize.height() / scaleFactor; m_scaleXWithBackground = m_scaleX + m_hBackgroundMargin; + m_scaleYWithBackground = m_scaleY + m_vBackgroundMargin; m_scaleZWithBackground = m_scaleZ + m_hBackgroundMargin; - m_scaleYWithBackground = m_vBackgroundMargin + 1.0f; - float factorScaler = 2.0f * m_graphAspectRatio / scaleFactor; - m_axisCacheX.setScale(factorScaler * areaSize.width()); - m_axisCacheZ.setScale(-factorScaler * areaSize.height()); - m_axisCacheX.setTranslate(-m_axisCacheX.scale() / 2.0f); - m_axisCacheZ.setTranslate(-m_axisCacheZ.scale() / 2.0f); + m_axisCacheX.setScale(m_scaleX * 2.0f); + m_axisCacheY.setScale(m_scaleY * 2.0f); + m_axisCacheZ.setScale(m_scaleZ * 2.0f); + m_axisCacheX.setTranslate(-m_scaleX); + m_axisCacheY.setTranslate(-m_scaleY); + m_axisCacheZ.setTranslate(-m_scaleZ); } void Surface3DRenderer::checkFlatSupport(SurfaceSeriesRenderCache *cache) @@ -2848,7 +2872,7 @@ QVector3D Surface3DRenderer::convertPositionToTranslation(const QVector3D &posit yTrans = m_axisCacheY.positionAt(position.y()); } else { xTrans = position.x() * m_scaleX; - yTrans = position.y(); + yTrans = position.y() * m_scaleY; zTrans = position.z() * m_scaleZ; } return QVector3D(xTrans, yTrans, zTrans); diff --git a/src/datavisualization/engine/surface3drenderer_p.h b/src/datavisualization/engine/surface3drenderer_p.h index 7a547042..cb9c49c3 100644 --- a/src/datavisualization/engine/surface3drenderer_p.h +++ b/src/datavisualization/engine/surface3drenderer_p.h @@ -58,6 +58,7 @@ private: ShaderHelper *m_labelShader; float m_heightNormalizer; float m_scaleX; + float m_scaleY; float m_scaleZ; float m_scaleXWithBackground; float m_scaleYWithBackground; -- cgit v1.2.3