From 8d01dc0ecaa0745c23b31b6c62eb46c6dad22356 Mon Sep 17 00:00:00 2001 From: Mika Salmela Date: Thu, 7 Nov 2013 15:20:22 +0200 Subject: Shadow support for surface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTRD-2266 Change-Id: I99fd7a6eda570df3d114ab10a1b07c22736cc86c Reviewed-by: Tomi Korpipää --- src/datavisualization/engine/bars3drenderer.cpp | 6 +- src/datavisualization/engine/engine.qrc | 5 +- src/datavisualization/engine/scatter3drenderer.cpp | 6 +- src/datavisualization/engine/shaders/surface.frag | 2 +- src/datavisualization/engine/shaders/surface.vert | 25 ------ .../engine/shaders/surfaceShadowFlat.frag | 70 ++++++++++++++++ .../engine/shaders/surfaceShadowFlat.vert | 37 +++++++++ .../engine/shaders/surfaceShadowNoTex.frag | 68 +++++++++++++++ .../engine/shaders/surface_ES2.frag | 2 +- src/datavisualization/engine/surface3drenderer.cpp | 96 +++++++++++++--------- src/datavisualization/engine/surface3drenderer_p.h | 1 + src/datavisualization/engine/theme.cpp | 9 +- src/datavisualization/utils/texturehelper.cpp | 11 ++- src/datavisualization/utils/texturehelper_p.h | 3 +- tests/surfacetest/main.cpp | 28 ++++--- 15 files changed, 279 insertions(+), 90 deletions(-) delete mode 100644 src/datavisualization/engine/shaders/surface.vert create mode 100644 src/datavisualization/engine/shaders/surfaceShadowFlat.frag create mode 100644 src/datavisualization/engine/shaders/surfaceShadowFlat.vert create mode 100644 src/datavisualization/engine/shaders/surfaceShadowNoTex.frag diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp index 51d48dca..affe35b9 100644 --- a/src/datavisualization/engine/bars3drenderer.cpp +++ b/src/datavisualization/engine/bars3drenderer.cpp @@ -2038,9 +2038,9 @@ void Bars3DRenderer::updateDepthBuffer() return; if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { - m_depthTexture = m_textureHelper->createDepthTexture(m_mainViewPort.size(), - m_depthFrameBuffer, - m_shadowQualityMultiplier); + m_depthTexture = m_textureHelper->createDepthTextureFrameBuffer(m_mainViewPort.size(), + m_depthFrameBuffer, + m_shadowQualityMultiplier); if (!m_depthTexture) lowerShadowQuality(); } diff --git a/src/datavisualization/engine/engine.qrc b/src/datavisualization/engine/engine.qrc index 14fb1bc6..7b1fb76b 100644 --- a/src/datavisualization/engine/engine.qrc +++ b/src/datavisualization/engine/engine.qrc @@ -50,13 +50,14 @@ shaders/default_ES2.vert shaders/texture_ES2.frag shaders/surface.frag - shaders/surface.vert shaders/surfaceGrid.frag shaders/surfaceGrid.vert shaders/surfaceFlat.vert shaders/surfaceFlat.frag shaders/surface_ES2.frag shaders/point_ES2.vert + shaders/surfaceShadowNoTex.frag + shaders/surfaceShadowFlat.frag + shaders/surfaceShadowFlat.vert - diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp index 02c5d51a..0bddb982 100644 --- a/src/datavisualization/engine/scatter3drenderer.cpp +++ b/src/datavisualization/engine/scatter3drenderer.cpp @@ -1594,9 +1594,9 @@ void Scatter3DRenderer::updateDepthBuffer() return; if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { - m_depthTexture = m_textureHelper->createDepthTexture(m_mainViewPort.size(), - m_depthFrameBuffer, - m_shadowQualityMultiplier); + m_depthTexture = m_textureHelper->createDepthTextureFrameBuffer(m_mainViewPort.size(), + m_depthFrameBuffer, + m_shadowQualityMultiplier); if (!m_depthTexture) lowerShadowQuality(); } diff --git a/src/datavisualization/engine/shaders/surface.frag b/src/datavisualization/engine/shaders/surface.frag index 4b1357b1..ee709cfa 100644 --- a/src/datavisualization/engine/shaders/surface.frag +++ b/src/datavisualization/engine/shaders/surface.frag @@ -1,6 +1,6 @@ #version 120 -varying highp vec3 coords_mdl; +varying highp vec2 coords_mdl; varying highp vec3 position_wrld; varying highp vec3 normal_cmr; varying highp vec3 eyeDirection_cmr; diff --git a/src/datavisualization/engine/shaders/surface.vert b/src/datavisualization/engine/shaders/surface.vert deleted file mode 100644 index 28152abc..00000000 --- a/src/datavisualization/engine/shaders/surface.vert +++ /dev/null @@ -1,25 +0,0 @@ -attribute highp vec3 vertexPosition_mdl; -attribute highp vec3 vertexNormal_mdl; - -uniform highp mat4 MVP; -uniform highp mat4 V; -uniform highp mat4 M; -uniform highp mat4 itM; -uniform highp vec3 lightPosition_wrld; - -varying highp vec3 position_wrld; -varying highp vec3 normal_cmr; -varying highp vec3 eyeDirection_cmr; -varying highp vec3 lightDirection_cmr; -varying highp vec3 coords_mdl; - -void main() { - gl_Position = MVP * vec4(vertexPosition_mdl, 1.0); - coords_mdl = vertexPosition_mdl; - position_wrld = (M * vec4(vertexPosition_mdl, 1.0)).xyz; - vec3 vertexPosition_cmr = (V * M * vec4(vertexPosition_mdl, 1.0)).xyz; - eyeDirection_cmr = vec3(0.0, 0.0, 0.0) - vertexPosition_cmr; - vec3 lightPosition_cmr = (V * vec4(lightPosition_wrld, 1.0)).xyz; - lightDirection_cmr = lightPosition_cmr + eyeDirection_cmr; - normal_cmr = (V * itM * vec4(vertexNormal_mdl, 0.0)).xyz; -} diff --git a/src/datavisualization/engine/shaders/surfaceShadowFlat.frag b/src/datavisualization/engine/shaders/surfaceShadowFlat.frag new file mode 100644 index 00000000..a426b01e --- /dev/null +++ b/src/datavisualization/engine/shaders/surfaceShadowFlat.frag @@ -0,0 +1,70 @@ +#version 120 + +#extension GL_EXT_gpu_shader4 : require + +varying highp vec3 coords_mdl; +varying highp vec3 position_wrld; +flat varying highp vec3 normal_cmr; +varying highp vec3 eyeDirection_cmr; +varying highp vec3 lightDirection_cmr; + +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; + +highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), + vec2(0.94558609, -0.76890725), + vec2(-0.094184101, -0.92938870), + vec2(0.34495938, 0.29387760), + vec2(-0.91588581, 0.45771432), + vec2(-0.81544232, -0.87912464), + vec2(-0.38277543, 0.27676845), + vec2(0.97484398, 0.75648379), + vec2(0.44323325, -0.97511554), + vec2(0.53742981, -0.47373420), + vec2(-0.26496911, -0.41893023), + vec2(0.79197514, 0.19090188), + vec2(-0.24188840, 0.99706507), + vec2(-0.81409955, 0.91437590), + vec2(0.19984126, 0.78641367), + vec2(0.14383161, -0.14100790)); + +void main() { + highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.001) / 2.0); // 1000 pixel texture, we need a margin for 1/1000 rounding error + highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; + highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; + highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); + + highp vec3 n = normalize(normal_cmr); + highp vec3 l = normalize(lightDirection_cmr); + highp float cosTheta = clamp(dot(n, l), 0.0, 1.0); + + highp vec3 E = normalize(eyeDirection_cmr); + highp vec3 R = reflect(-l, n); + highp float cosAlpha = clamp(dot(E, R), 0.0, 1.0); + + highp float bias = 0.005 * tan(acos(cosTheta)); + bias = clamp(bias, 0.0, 0.01); + + vec4 shadCoords = shadowCoord; + shadCoords.z -= bias; + + highp float visibility = 0.6; + for (int i = 0; i < 15; i++) { + vec4 shadCoordsPD = shadCoords; + shadCoordsPD.x += cos(poissonDisk[i].x) / shadowQuality; + shadCoordsPD.y += sin(poissonDisk[i].y) / shadowQuality; + visibility += 0.025 * shadow2DProj(shadowMap, shadCoordsPD).r; + } + + gl_FragColor.rgb = + visibility * (materialAmbientColor + + materialDiffuseColor * lightStrength * cosTheta + + materialSpecularColor * lightStrength * pow(cosAlpha, 10)); + gl_FragColor.a = 1.0; +} + diff --git a/src/datavisualization/engine/shaders/surfaceShadowFlat.vert b/src/datavisualization/engine/shaders/surfaceShadowFlat.vert new file mode 100644 index 00000000..0a6e967f --- /dev/null +++ b/src/datavisualization/engine/shaders/surfaceShadowFlat.vert @@ -0,0 +1,37 @@ +#version 120 + +#extension GL_EXT_gpu_shader4 : require + +attribute highp vec3 vertexPosition_mdl; +attribute highp vec3 vertexNormal_mdl; + +uniform highp mat4 MVP; +uniform highp mat4 V; +uniform highp mat4 M; +uniform highp mat4 itM; +uniform highp mat4 depthMVP; +uniform highp vec3 lightPosition_wrld; + +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; +varying highp vec3 coords_mdl; + +const highp mat4 bias = mat4(0.5, 0.0, 0.0, 0.0, + 0.0, 0.5, 0.0, 0.0, + 0.0, 0.0, 0.5, 0.0, + 0.5, 0.5, 0.5, 1.0); + +void main() { + gl_Position = MVP * vec4(vertexPosition_mdl, 1.0); + coords_mdl = vertexPosition_mdl; + shadowCoord = bias * depthMVP * vec4(vertexPosition_mdl, 1.0); + position_wrld = (M * vec4(vertexPosition_mdl, 1.0)).xyz; + vec3 vertexPosition_cmr = (V * M * vec4(vertexPosition_mdl, 1.0)).xyz; + eyeDirection_cmr = vec3(0.0, 0.0, 0.0) - vertexPosition_cmr; + vec3 lightPosition_cmr = (V * vec4(lightPosition_wrld, 1.0)).xyz; + lightDirection_cmr = lightPosition_cmr + eyeDirection_cmr; + normal_cmr = (V * itM * vec4(vertexNormal_mdl, 0.0)).xyz; +} diff --git a/src/datavisualization/engine/shaders/surfaceShadowNoTex.frag b/src/datavisualization/engine/shaders/surfaceShadowNoTex.frag new file mode 100644 index 00000000..18d0c77a --- /dev/null +++ b/src/datavisualization/engine/shaders/surfaceShadowNoTex.frag @@ -0,0 +1,68 @@ +#version 120 + +varying highp vec2 coords_mdl; +varying highp vec3 position_wrld; +varying highp vec3 normal_cmr; +varying highp vec3 eyeDirection_cmr; +varying highp vec3 lightDirection_cmr; + +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; + +highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), + vec2(0.94558609, -0.76890725), + vec2(-0.094184101, -0.92938870), + vec2(0.34495938, 0.29387760), + vec2(-0.91588581, 0.45771432), + vec2(-0.81544232, -0.87912464), + vec2(-0.38277543, 0.27676845), + vec2(0.97484398, 0.75648379), + vec2(0.44323325, -0.97511554), + vec2(0.53742981, -0.47373420), + vec2(-0.26496911, -0.41893023), + vec2(0.79197514, 0.19090188), + vec2(-0.24188840, 0.99706507), + vec2(-0.81409955, 0.91437590), + vec2(0.19984126, 0.78641367), + vec2(0.14383161, -0.14100790)); + +void main() { + highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.001) / 2.0); // 1000 pixel texture, we need a margin for 1/1000 rounding error + highp vec3 materialDiffuseColor = texture2D(textureSampler, gradientUV).xyz; + highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; + highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); + + highp vec3 n = normalize(normal_cmr); + highp vec3 l = normalize(lightDirection_cmr); + highp float cosTheta = clamp(dot(n, l), 0.0, 1.0); + + highp vec3 E = normalize(eyeDirection_cmr); + highp vec3 R = reflect(-l, n); + highp float cosAlpha = clamp(dot(E, R), 0.0, 1.0); + + highp float bias = 0.005 * tan(acos(cosTheta)); + bias = clamp(bias, 0.0, 0.01); + + vec4 shadCoords = shadowCoord; + shadCoords.z -= bias; + + highp float visibility = 0.6; + for (int i = 0; i < 15; i++) { + vec4 shadCoordsPD = shadCoords; + shadCoordsPD.x += cos(poissonDisk[i].x) / shadowQuality; + shadCoordsPD.y += sin(poissonDisk[i].y) / shadowQuality; + visibility += 0.025 * shadow2DProj(shadowMap, shadCoordsPD).r; + } + + gl_FragColor.rgb = + visibility * (materialAmbientColor + + materialDiffuseColor * lightStrength * cosTheta + + materialSpecularColor * lightStrength * pow(cosAlpha, 10)); + gl_FragColor.a = 1.0; +} + diff --git a/src/datavisualization/engine/shaders/surface_ES2.frag b/src/datavisualization/engine/shaders/surface_ES2.frag index 7f40ba4d..24acd5ca 100644 --- a/src/datavisualization/engine/shaders/surface_ES2.frag +++ b/src/datavisualization/engine/shaders/surface_ES2.frag @@ -1,5 +1,5 @@ varying highp vec2 UV; -varying highp vec3 coords_mdl; +varying highp vec2 coords_mdl; varying highp vec3 position_wrld; varying highp vec3 normal_cmr; varying highp vec3 eyeDirection_cmr; diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp index 148d311f..c537ff3a 100644 --- a/src/datavisualization/engine/surface3drenderer.cpp +++ b/src/datavisualization/engine/surface3drenderer.cpp @@ -124,9 +124,6 @@ Surface3DRenderer::Surface3DRenderer(Surface3DController *controller) " Requires at least GLSL version 1.2 with GL_EXT_gpu_shader4 extension."; } - // Shadows are disabled for Q3DSurface in Tech Preview - updateShadowQuality(QDataVis::ShadowQualityNone); - initializeOpenGLFunctions(); initializeOpenGL(); } @@ -138,6 +135,7 @@ Surface3DRenderer::~Surface3DRenderer() m_textureHelper->glDeleteFramebuffers(1, &m_selectionFrameBuffer); m_textureHelper->deleteTexture(&m_depthTexture); + m_textureHelper->deleteTexture(&m_depthModelTexture); m_textureHelper->deleteTexture(&m_gradientTexture); m_textureHelper->deleteTexture(&m_selectionTexture); m_textureHelper->deleteTexture(&m_selectionResultTexture); @@ -172,10 +170,7 @@ void Surface3DRenderer::initializeOpenGL() Abstract3DRenderer::initializeOpenGL(); // Initialize shaders - handleShadowQualityChange(); - initSurfaceShaders(); - initLabelShaders(QStringLiteral(":/shaders/vertexLabel"), QStringLiteral(":/shaders/fragmentLabel")); @@ -799,6 +794,8 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) // Render scene into a depth texture for using with shadow mapping // Enable drawing to depth framebuffer glBindFramebuffer(GL_FRAMEBUFFER, m_depthFrameBuffer); + // Attach texture to depth attachment + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthTexture, 0); glClear(GL_DEPTH_BUFFER_BIT); // Bind depth shader @@ -831,7 +828,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) #endif depthProjectionViewMatrix = depthProjectionMatrix * depthViewMatrix; - glCullFace(GL_FRONT); + glDisable(GL_CULL_FACE); QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; @@ -853,7 +850,17 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_surfaceObj->elementBuf()); // Draw the triangles - glDrawElements(GL_TRIANGLES, m_surfaceObj->indexCount(), GL_UNSIGNED_SHORT, + glDrawElements(GL_TRIANGLES, m_surfaceObj->indexCount(), m_surfaceObj->indicesType(), + (void *)0); + + glEnable(GL_CULL_FACE); + glCullFace(GL_FRONT); + + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthModelTexture, 0); + glClear(GL_DEPTH_BUFFER_BIT); + + // Draw the triangles + glDrawElements(GL_TRIANGLES, m_surfaceObj->indexCount(), m_surfaceObj->indicesType(), (void *)0); // Free buffers @@ -873,6 +880,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) m_mainViewPort.width(), m_mainViewPort.height()); // Reset culling to normal + glEnable(GL_CULL_FACE); glCullFace(GL_BACK); #if 0 // Use this if you want to see what is being drawn to the framebuffer @@ -988,7 +996,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) m_surfaceShader->setUniformValue(m_surfaceShader->lightS(), adjustedLightStrength); // Draw the object - m_drawer->drawObject(m_surfaceShader, m_surfaceObj, m_gradientTexture, m_depthTexture); + m_drawer->drawObject(m_surfaceShader, m_surfaceObj, m_gradientTexture, m_depthModelTexture); } else #endif { @@ -1061,7 +1069,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) m_cachedTheme.m_ambientStrength * 2.0f); #if !defined(QT_OPENGL_ES_2) - if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { + if (m_cachedShadowQuality > QDataVis::ShadowQualityNone && m_cachedSurfaceOn) { // Set shadow shader bindings QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; m_backgroundShader->setUniformValue(m_backgroundShader->shadowQ(), @@ -1585,7 +1593,6 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) glDisable(GL_POLYGON_OFFSET_FILL); glDisable(GL_TEXTURE_2D); - glDisable(GL_BLEND); // Release label shader @@ -1925,8 +1932,8 @@ void Surface3DRenderer::loadMeshFile() void Surface3DRenderer::updateShadowQuality(QDataVis::ShadowQuality quality) { - qWarning() << "Shadows have been disabled for Q3DSurface in technology preview"; - m_cachedShadowQuality = QDataVis::ShadowQualityNone; //quality; + m_cachedShadowQuality = quality; + switch (quality) { case QDataVis::ShadowQualityLow: m_shadowQualityToShader = 33.3f; @@ -1958,6 +1965,8 @@ void Surface3DRenderer::updateShadowQuality(QDataVis::ShadowQuality quality) break; } + handleShadowQualityChange(); + #if !defined(QT_OPENGL_ES_2) updateDepthBuffer(); #endif @@ -2016,6 +2025,33 @@ void Surface3DRenderer::initShaders(const QString &vertexShader, const QString & delete m_shader; m_shader = new ShaderHelper(this, vertexShader, fragmentShader); m_shader->initialize(); + + // draw the shader for the surface according to smooth status, shadow and uniform color + if (m_surfaceShader) + delete m_surfaceShader; +#if !defined(QT_OPENGL_ES_2) + if (m_cachedSmoothSurface) { + if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { + m_surfaceShader = new ShaderHelper(this, QStringLiteral(":/shaders/vertexShadow"), + QStringLiteral(":/shaders/fragmentSurfaceShadowNoTex")); + } else { + m_surfaceShader = new ShaderHelper(this, QStringLiteral(":/shaders/vertex"), + QStringLiteral(":/shaders/fragmentSurface")); + } + } else { + if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { + m_surfaceShader = new ShaderHelper(this, QStringLiteral(":/shaders/vertexSurfaceShadowFlat"), + QStringLiteral(":/shaders/fragmentSurfaceShadowFlat")); + } else { + m_surfaceShader = new ShaderHelper(this, QStringLiteral(":/shaders/vertexSurfaceFlat"), + QStringLiteral(":/shaders/fragmentSurfaceFlat")); + } + } +#else + m_surfaceShader = new ShaderHelper(this, QStringLiteral(":/shaders/vertex"), + QStringLiteral(":/shaders/fragmentSurfaceES2")); +#endif + m_surfaceShader->initialize(); } void Surface3DRenderer::initBackgroundShaders(const QString &vertexShader, @@ -2038,30 +2074,15 @@ void Surface3DRenderer::initSelectionShaders() void Surface3DRenderer::initSurfaceShaders() { - if (m_surfaceShader) - delete m_surfaceShader; - -#if !defined(QT_OPENGL_ES_2) - if (m_cachedSmoothSurface) { - m_surfaceShader = new ShaderHelper(this, QStringLiteral(":/shaders/vertexSurface"), - QStringLiteral(":/shaders/fragmentSurface")); - } else { - m_surfaceShader = new ShaderHelper(this, QStringLiteral(":/shaders/vertexSurfaceFlat"), - QStringLiteral(":/shaders/fragmentSurfaceFlat")); - } -#else - m_surfaceShader = new ShaderHelper(this, QStringLiteral(":/shaders/vertexSurface"), - QStringLiteral(":/shaders/fragmentSurfaceES2")); -#endif - m_surfaceShader->initialize(); - + // Gridline shader if (m_surfaceGridShader) delete m_surfaceGridShader; - m_surfaceGridShader = new ShaderHelper(this, QStringLiteral(":/shaders/vertexSurfaceGrid"), QStringLiteral(":/shaders/fragmentSurfaceGrid")); - m_surfaceGridShader->initialize(); + + // Triggers surface shader selection by shadow setting + handleShadowQualityChange(); } void Surface3DRenderer::initLabelShaders(const QString &vertexShader, const QString &fragmentShader) @@ -2075,7 +2096,6 @@ void Surface3DRenderer::initLabelShaders(const QString &vertexShader, const QStr #if !defined(QT_OPENGL_ES_2) void Surface3DRenderer::initDepthShader() { - // TODO: Implement a depth shader for surface after technology preview if (m_depthShader) delete m_depthShader; m_depthShader = new ShaderHelper(this, QStringLiteral(":/shaders/vertexDepth"), @@ -2094,10 +2114,12 @@ void Surface3DRenderer::updateDepthBuffer() return; if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { - m_depthTexture = m_textureHelper->createDepthTexture(m_mainViewPort.size(), - m_depthFrameBuffer, - m_shadowQualityMultiplier); - if (!m_depthTexture) + m_depthTexture = m_textureHelper->createDepthTextureFrameBuffer(m_mainViewPort.size(), + m_depthFrameBuffer, + m_shadowQualityMultiplier); + m_depthModelTexture = m_textureHelper->createDepthTexture(m_mainViewPort.size(), + m_shadowQualityMultiplier); + if (!m_depthTexture || !m_depthModelTexture) lowerShadowQuality(); } } diff --git a/src/datavisualization/engine/surface3drenderer_p.h b/src/datavisualization/engine/surface3drenderer_p.h index 875e79c6..0cff19cd 100644 --- a/src/datavisualization/engine/surface3drenderer_p.h +++ b/src/datavisualization/engine/surface3drenderer_p.h @@ -101,6 +101,7 @@ private: SurfaceObject *m_surfaceObj; SurfaceObject *m_sliceSurfaceObj; GLuint m_depthTexture; + GLuint m_depthModelTexture; GLuint m_depthFrameBuffer; GLuint m_selectionFrameBuffer; GLuint m_selectionDepthBuffer; diff --git a/src/datavisualization/engine/theme.cpp b/src/datavisualization/engine/theme.cpp index 78a61637..5c67071c 100644 --- a/src/datavisualization/engine/theme.cpp +++ b/src/datavisualization/engine/theme.cpp @@ -207,12 +207,15 @@ void Theme::useTheme(QDataVis::Theme theme) default: break; } + if (m_uniformColor) { m_surfaceGradient.setColorAt(0.0, m_baseColor); } else { - m_surfaceGradient.setColorAt(0.0, QColor(m_baseColor.redF() * 0.7, - m_baseColor.greenF() * 0.7, - m_baseColor.blueF() * 0.7)); + QColor color; + color.setRedF(m_baseColor.redF() * 0.7f); + color.setGreenF(m_baseColor.greenF() * 0.7f); + color.setBlueF(m_baseColor.blueF() * 0.7f); + m_surfaceGradient.setColorAt(0.0, color); } m_surfaceGradient.setColorAt(1.0, m_baseColor); } diff --git a/src/datavisualization/utils/texturehelper.cpp b/src/datavisualization/utils/texturehelper.cpp index fd5061f2..cb18fcc2 100644 --- a/src/datavisualization/utils/texturehelper.cpp +++ b/src/datavisualization/utils/texturehelper.cpp @@ -168,7 +168,7 @@ GLuint TextureHelper::createGradientTexture(const QLinearGradient &gradient) } #if !defined(QT_OPENGL_ES_2) -GLuint TextureHelper::createDepthTexture(const QSize &size, GLuint &frameBuffer, GLuint textureSize) +GLuint TextureHelper::createDepthTexture(const QSize &size, GLuint textureSize) { GLuint depthtextureid; @@ -185,6 +185,15 @@ GLuint TextureHelper::createDepthTexture(const QSize &size, GLuint &frameBuffer, size.height() * textureSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); glBindTexture(GL_TEXTURE_2D, 0); + return depthtextureid; +} +#endif + +#if !defined(QT_OPENGL_ES_2) +GLuint TextureHelper::createDepthTextureFrameBuffer(const QSize &size, GLuint &frameBuffer, GLuint textureSize) +{ + GLuint depthtextureid = createDepthTexture(size, textureSize); + // Create frame buffer if (!frameBuffer) glGenFramebuffers(1, &frameBuffer); diff --git a/src/datavisualization/utils/texturehelper_p.h b/src/datavisualization/utils/texturehelper_p.h index 97bd9e3d..84570a13 100644 --- a/src/datavisualization/utils/texturehelper_p.h +++ b/src/datavisualization/utils/texturehelper_p.h @@ -50,8 +50,9 @@ class TextureHelper : protected QOpenGLFunctions GLuint createSelectionTexture(const QSize &size, GLuint &frameBuffer, GLuint &depthBuffer); GLuint createGradientTexture(const QLinearGradient &gradient); #if !defined(QT_OPENGL_ES_2) + GLuint createDepthTexture(const QSize &size, GLuint textureSize); // Returns depth texture and inserts generated framebuffer to parameter - GLuint createDepthTexture(const QSize &size, GLuint &frameBuffer, GLuint textureSize = 1); + GLuint createDepthTextureFrameBuffer(const QSize &size, GLuint &frameBuffer, GLuint textureSize); #endif void deleteTexture(const GLuint *texture); diff --git a/tests/surfacetest/main.cpp b/tests/surfacetest/main.cpp index 8ed84a4f..fc33a4cf 100644 --- a/tests/surfacetest/main.cpp +++ b/tests/surfacetest/main.cpp @@ -161,15 +161,16 @@ int main(int argc, char *argv[]) themeList->addItem(QStringLiteral("Isabelle")); themeList->setCurrentIndex(initialTheme); -// QComboBox *shadowQuality = new QComboBox(widget); -// shadowQuality->addItem(QStringLiteral("None")); -// shadowQuality->addItem(QStringLiteral("Low")); -// shadowQuality->addItem(QStringLiteral("Medium")); -// shadowQuality->addItem(QStringLiteral("High")); -// shadowQuality->addItem(QStringLiteral("Low Soft")); -// shadowQuality->addItem(QStringLiteral("Medium Soft")); -// shadowQuality->addItem(QStringLiteral("High Soft")); -// shadowQuality->setCurrentIndex(3); + QComboBox *shadowQuality = new QComboBox(widget); + shadowQuality->addItem(QStringLiteral("None")); + shadowQuality->addItem(QStringLiteral("Low")); + shadowQuality->addItem(QStringLiteral("Medium")); + shadowQuality->addItem(QStringLiteral("High")); + shadowQuality->addItem(QStringLiteral("Low Soft")); + shadowQuality->addItem(QStringLiteral("Medium Soft")); + shadowQuality->addItem(QStringLiteral("High Soft")); + shadowQuality->setCurrentIndex(3); + QComboBox *selectionMode = new QComboBox(widget); selectionMode->addItem(QStringLiteral("None"), int(QDataVis::SelectionNone)); @@ -229,8 +230,8 @@ int main(int argc, char *argv[]) vLayout->addWidget(labelButton); vLayout->addWidget(new QLabel(QStringLiteral("Change theme"))); vLayout->addWidget(themeList); -// vLayout->addWidget(new QLabel(QStringLiteral("Adjust shadow quality"))); -// vLayout->addWidget(shadowQuality); + vLayout->addWidget(new QLabel(QStringLiteral("Adjust shadow quality"))); + vLayout->addWidget(shadowQuality); vLayout->addWidget(new QLabel(QStringLiteral("Selection Mode"))); vLayout->addWidget(selectionMode); vLayout->addWidget(selectButton); @@ -276,8 +277,8 @@ int main(int argc, char *argv[]) modifier, &GraphModifier::changeStyle); QObject::connect(themeList, SIGNAL(currentIndexChanged(int)), modifier, SLOT(changeTheme(int))); -// QObject::connect(shadowQuality, SIGNAL(currentIndexChanged(int)), -// modifier, SLOT(changeShadowQuality(int))); + QObject::connect(shadowQuality, SIGNAL(currentIndexChanged(int)), + modifier, SLOT(changeShadowQuality(int))); QObject::connect(selectionMode, SIGNAL(currentIndexChanged(int)), modifier, SLOT(changeSelectionMode(int))); QObject::connect(selectButton, &QPushButton::clicked, @@ -294,6 +295,7 @@ int main(int argc, char *argv[]) modifier->toggleGridSliderLock(gridSlidersLockCB->checkState()); modifier->setSelectionInfoLabel(selectionInfoLabel); sqrtSinCB->setChecked(true); + shadowQuality->setCurrentIndex(3); return app.exec(); } -- cgit v1.2.3