diff --git a/src/graphs3d/engine/shaders/bars.frag b/src/graphs3d/engine/shaders/bars.frag index ab050c3d..004c97fc 100644 --- a/src/graphs3d/engine/shaders/bars.frag +++ b/src/graphs3d/engine/shaders/bars.frag @@ -20,7 +20,7 @@ void MAIN() if (valueColoring) gradientUV = vec2(heightValue, 0); else - gradientUV = vec2((VAR_WORLD_POSITION.y + 1.0) / 2.0, 0.0); + gradientUV = vec2(((VAR_WORLD_POSITION.y + rootScale) / 2.0) / rootScale, 0.0); color = texture(custex, gradientUV); break; } diff --git a/src/graphs3d/engine/shaders/barsinstancing.frag b/src/graphs3d/engine/shaders/barsinstancing.frag index 48fce537..ea4ebe9c 100644 --- a/src/graphs3d/engine/shaders/barsinstancing.frag +++ b/src/graphs3d/engine/shaders/barsinstancing.frag @@ -28,7 +28,7 @@ void MAIN() if (valueColoring) gradientUV = vec2(heightValue, 0); else - gradientUV = vec2((VAR_WORLD_POSITION.y + 1.0) / 2.0, 0.0); + gradientUV = vec2(((VAR_WORLD_POSITION.y + rootScale) / 2.0) / rootScale, 0.0); color = texture(custex, gradientUV).xyz; alpha = texture(custex, gradientUV).w; break; diff --git a/src/graphs3d/engine/shaders/scatter.frag b/src/graphs3d/engine/shaders/scatter.frag index 288e3f5f..75a2c7dc 100644 --- a/src/graphs3d/engine/shaders/scatter.frag +++ b/src/graphs3d/engine/shaders/scatter.frag @@ -23,7 +23,7 @@ void MAIN() color = texture(custex, gradientUV); break; case 2: // Range gradient - vec2 gradientUV = vec2((VAR_WORLD_POSITION.y + 1.0) / 2.0, 0.0); + vec2 gradientUV = vec2(((VAR_WORLD_POSITION.y + rootScale) / 2.0) / rootScale, 0.0); color = texture(custex, gradientUV); break; } diff --git a/src/graphs3d/engine/shaders/scatterinstancing.frag b/src/graphs3d/engine/shaders/scatterinstancing.frag index 9fbaa290..0b94892e 100644 --- a/src/graphs3d/engine/shaders/scatterinstancing.frag +++ b/src/graphs3d/engine/shaders/scatterinstancing.frag @@ -24,7 +24,7 @@ void MAIN() color = texture(custex, gradientUV); break; case 2: // Range gradient - vec2 gradientUV = vec2((VAR_WORLD_POSITION.y + 1.0) / 2.0, 0.0); + vec2 gradientUV = vec2(((VAR_WORLD_POSITION.y + rootScale) / 2.0) / rootScale, 0.0); color = texture(custex, gradientUV); if (!usePoint) color = vColor; diff --git a/src/graphs3d/engine/shaders/surface.frag b/src/graphs3d/engine/shaders/surface.frag index e944b472..18b94b9a 100644 --- a/src/graphs3d/engine/shaders/surface.frag +++ b/src/graphs3d/engine/shaders/surface.frag @@ -6,7 +6,7 @@ VARYING vec2 UV; void MAIN() { - if (any(greaterThan(UV, vec2(1.01))) || abs(VAR_WORLD_POSITION.y) > graphHeight) + if (any(greaterThan(UV, vec2(1.01))) || abs(pos.y) > graphHeight) discard; vec4 color; vec2 gradientUV; @@ -16,7 +16,7 @@ void MAIN() color = texture(custex, gradientUV); break; case 1: //Range gradient - gradientUV = vec2((VAR_WORLD_POSITION.y + 1.0) / 2.0, 0.0); + gradientUV = vec2(((VAR_WORLD_POSITION.y + rootScale) / 2.0) / rootScale, 0.0); color = texture(custex, gradientUV); break; case 2: // Uniform color diff --git a/src/graphs3d/engine/shaders/surfaceGrid.frag b/src/graphs3d/engine/shaders/surfaceGrid.frag index bb9a31d4..c98656d6 100644 --- a/src/graphs3d/engine/shaders/surfaceGrid.frag +++ b/src/graphs3d/engine/shaders/surfaceGrid.frag @@ -1,7 +1,8 @@ vec4 color; +VARYING vec3 pos; void MAIN() { - if (abs(VAR_WORLD_POSITION.y) > graphHeight) + if (abs(pos.y) > graphHeight) discard; color = gridColor; } diff --git a/src/graphs3d/engine/shaders/surfaceGrid.vert b/src/graphs3d/engine/shaders/surfaceGrid.vert index 03ce4fa2..9bf04fdd 100644 --- a/src/graphs3d/engine/shaders/surfaceGrid.vert +++ b/src/graphs3d/engine/shaders/surfaceGrid.vert @@ -1,6 +1,8 @@ +VARYING vec3 pos; void MAIN() { vec2 UV = UV0 * (vertices / range); VERTEX = texture(height, UV).rgb; + pos = VERTEX; POSITION = MODELVIEWPROJECTION_MATRIX * vec4(VERTEX, 1.0); } diff --git a/src/graphs3d/qml/qquickgraphsbars.cpp b/src/graphs3d/qml/qquickgraphsbars.cpp index 0fbc21e6..a3267f5b 100644 --- a/src/graphs3d/qml/qquickgraphsbars.cpp +++ b/src/graphs3d/qml/qquickgraphsbars.cpp @@ -1796,6 +1796,7 @@ void QQuickGraphsBars::updateBarVisuals(QBar3DSeries *series) QQmlListReference materialsRef(barList.at(i)->model, "materials"); auto customMaterial = qobject_cast(materialsRef.at(0)); customMaterial->setProperty("valueColoring", series->isValueColoringEnabled()); + customMaterial->setProperty("rootScale", rootNode()->scale().y()); } } } @@ -1861,6 +1862,7 @@ void QQuickGraphsBars::updateMaterialProperties(QQuick3DModel *item, customMaterial->setProperty("isHighlight", isHighlight || isMultiHighlight); } customMaterial->setProperty("specularBrightness", lightStrength() * 0.05); + customMaterial->setProperty("rootScale", rootNode()->scale().y()); } void QQuickGraphsBars::removeBarModels() diff --git a/src/graphs3d/qml/qquickgraphsitem.cpp b/src/graphs3d/qml/qquickgraphsitem.cpp index 81c0d4ad..c0b627bc 100644 --- a/src/graphs3d/qml/qquickgraphsitem.cpp +++ b/src/graphs3d/qml/qquickgraphsitem.cpp @@ -1796,6 +1796,8 @@ void QQuickGraphsItem::componentComplete() { QQuick3DViewport::componentComplete(); + rootNode()->setScale(QVector3D(100,100,100)); + auto url = QUrl(QStringLiteral("defaultMeshes/backgroundMesh")); m_background = new QQuick3DModel(); m_backgroundScale = new QQuick3DNode(); @@ -4234,9 +4236,10 @@ void QQuickGraphsItem::updateItemLabel(QVector3D position) { if (m_labelPosition != position) m_labelPosition = position; - QVector3D pos2d = mapFrom3DScene(m_labelPosition); + + QVector3D pos2d = mapFrom3DScene(m_labelPosition * rootNode()->scale().z()); int pointSize = theme()->labelFont().pointSize(); - float scale = m_labelScale.x() * ((-10.0f * pointSize) + 650.0f) / pos2d.z(); + float scale = m_labelScale.x() * ((-10.0f * pointSize) + 650.0f) / (pos2d.z() / rootNode()->scale().z()); scale = scale < 0 ? -scale : scale; if (m_sliceView && m_sliceView->isVisible()) m_itemLabel->setScale(scale * .2f); @@ -4986,7 +4989,7 @@ void QQuickGraphsItem::updateCamera() const float scale = qMin(width(), height() * 1.6f); const float magnificationScaleFactor = 1.0f / 640.0f; - const float magnification = scale * magnificationScaleFactor; + const float magnification = scale * magnificationScaleFactor / rootNode()->scale().x(); auto useOrtho = isOrthoProjection(); if (useOrtho) { @@ -6746,10 +6749,10 @@ void QQuickGraphsItem::setUpCamera() // By default we could get away with a value of 10 or 15, but as camera zoom is implemented // by moving it, we have to take into account the maximum zoom out level. The other // option would be to adjust far clip whenever zoom level changes. - const float farclip = 700.f; + const float farclip = 7000.f; m_pCamera = new QQuick3DPerspectiveCamera(rootNode()); - m_pCamera->setClipNear(0.001f); + m_pCamera->setClipNear(0.1f); m_pCamera->setClipFar(farclip); m_pCamera->setFieldOfView(45.0f); m_pCamera->setPosition(QVector3D(.0f, .0f, 5.f)); @@ -6790,7 +6793,6 @@ void QQuickGraphsItem::setUpLight() *QQuick3DObjectPrivate::get(rootNode())->sceneManager); light->setParent(camera()); light->setParentItem(camera()); - light->setShadowBias(0.1f); light->setSoftShadowQuality(QQuick3DAbstractLight::QSSGSoftShadowQuality::Hard); m_light = light; } diff --git a/src/graphs3d/qml/qquickgraphsscatter.cpp b/src/graphs3d/qml/qquickgraphsscatter.cpp index a3cd8989..74543394 100644 --- a/src/graphs3d/qml/qquickgraphsscatter.cpp +++ b/src/graphs3d/qml/qquickgraphsscatter.cpp @@ -616,6 +616,7 @@ void QQuickGraphsScatter::updateItemMaterial(QQuick3DModel *item, material->setProperty("colorStyle", 2); material->setProperty("usePoint", usePoint); + material->setProperty("rootScale", rootNode()->scale().y()); } void QQuickGraphsScatter::updateInstancedMaterialProperties(ScatterModel *graphModel, @@ -659,6 +660,7 @@ void QQuickGraphsScatter::updateMaterialProperties(QQuick3DModel *item, QQmlListReference materialsRef(item, "materials"); auto customMaterial = static_cast(materialsRef.at(0)); customMaterial->setProperty("transparency", transparency); + customMaterial->setProperty("rootScale", rootNode()->scale().y()); int style = customMaterial->property("colorStyle").value(); if (style == 0) { diff --git a/src/graphs3d/qml/qquickgraphssurface.cpp b/src/graphs3d/qml/qquickgraphssurface.cpp index 801a92fc..6183df62 100644 --- a/src/graphs3d/qml/qquickgraphssurface.cpp +++ b/src/graphs3d/qml/qquickgraphssurface.cpp @@ -1776,6 +1776,7 @@ void QQuickGraphsSurface::updateMaterial(SurfaceModel *model) texInput->texture()->setSource(QUrl()); } } + material->setProperty("rootScale", rootNode()->scale().y()); material->setProperty("hasTransparency", hasTransparency); material->update(); } diff --git a/src/graphs3d/qml/resources/BarsMaterial.qml b/src/graphs3d/qml/resources/BarsMaterial.qml index 353d7eb0..d08c4f11 100644 --- a/src/graphs3d/qml/resources/BarsMaterial.qml +++ b/src/graphs3d/qml/resources/BarsMaterial.qml @@ -13,6 +13,7 @@ CustomMaterial { property bool valueColoring property real heightValue + property real rootScale property real specularBrightness: 0.25 readonly property real shininess: (1.0 - specularBrightness) * 100 diff --git a/src/graphs3d/qml/resources/BarsMaterialInstancing.qml b/src/graphs3d/qml/resources/BarsMaterialInstancing.qml index 533c0ea4..4424009e 100644 --- a/src/graphs3d/qml/resources/BarsMaterialInstancing.qml +++ b/src/graphs3d/qml/resources/BarsMaterialInstancing.qml @@ -11,6 +11,7 @@ CustomMaterial { property bool isHighlight property bool instancing property bool transparency: false + property real rootScale property bool valueColoring diff --git a/src/graphs3d/qml/resources/ScatterMaterial.qml b/src/graphs3d/qml/resources/ScatterMaterial.qml index b9ef0751..53873249 100644 --- a/src/graphs3d/qml/resources/ScatterMaterial.qml +++ b/src/graphs3d/qml/resources/ScatterMaterial.qml @@ -11,6 +11,7 @@ CustomMaterial { property color uColor property bool usePoint property bool transparency: false + property real rootScale property real specularBrightness: 0.25 readonly property real shininess: (1.0 - specularBrightness) * 100 diff --git a/src/graphs3d/qml/resources/ScatterMaterialInstancing.qml b/src/graphs3d/qml/resources/ScatterMaterialInstancing.qml index 0d7110d6..9db1674d 100644 --- a/src/graphs3d/qml/resources/ScatterMaterialInstancing.qml +++ b/src/graphs3d/qml/resources/ScatterMaterialInstancing.qml @@ -11,6 +11,7 @@ CustomMaterial { property color uColor property bool usePoint property bool transparency: false + property real rootScale property real specularBrightness: 0.25 readonly property real shininess: (1.0 - specularBrightness) * 100 diff --git a/src/graphs3d/qml/resources/SurfaceMaterial.qml b/src/graphs3d/qml/resources/SurfaceMaterial.qml index a5cd532c..c054298e 100644 --- a/src/graphs3d/qml/resources/SurfaceMaterial.qml +++ b/src/graphs3d/qml/resources/SurfaceMaterial.qml @@ -15,6 +15,7 @@ CustomMaterial { property vector2d uvOffset property vector2d size property vector2d vertCount + property real rootScale property real gradientMin property real gradientHeight