From 51deca1429e1097be3108a5dc28a4897944fed1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Korpip=C3=A4=C3=A4?= Date: Mon, 20 Jan 2014 09:43:57 +0200 Subject: References to alpha and TP removed + implemented the rest of lightColor Task-number: QTRD-2405 Change-Id: I38402b45cc4a567a79d07b23983567551d06b4fe Reviewed-by: Miikka Heikkinen --- src/datavisualization/engine/bars3drenderer.cpp | 17 ++++++++++-- src/datavisualization/engine/scatter3drenderer.cpp | 19 +++++++++++--- src/datavisualization/engine/selectionpointer.cpp | 5 +++- src/datavisualization/engine/shaders/colorOnY.frag | 5 ++-- .../engine/shaders/colorOnY_ES2.frag | 5 ++-- src/datavisualization/engine/shaders/default.frag | 5 ++-- .../engine/shaders/default_ES2.frag | 5 ++-- src/datavisualization/engine/shaders/shadow.frag | 5 ++-- .../engine/shaders/shadowNoTex.frag | 5 ++-- .../engine/shaders/shadowNoTexColorOnY.frag | 5 ++-- src/datavisualization/engine/shaders/surface.frag | 5 ++-- .../engine/shaders/surfaceFlat.frag | 5 ++-- .../engine/shaders/surfaceShadowFlat.frag | 5 ++-- .../engine/shaders/surfaceShadowNoTex.frag | 5 ++-- .../engine/shaders/surface_ES2.frag | 5 ++-- src/datavisualization/engine/surface3drenderer.cpp | 30 +++++++++++++++++----- 16 files changed, 93 insertions(+), 38 deletions(-) (limited to 'src/datavisualization/engine') diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp index 133ecea2..e7fcf57e 100644 --- a/src/datavisualization/engine/bars3drenderer.cpp +++ b/src/datavisualization/engine/bars3drenderer.cpp @@ -275,6 +275,7 @@ void Bars3DRenderer::drawSlicedScene() { GLfloat barPosX = 0; QVector3D lightPos; + QVector3D lightColor = Utils::vectorFromColor(m_cachedTheme->lightColor()); // Specify viewport glViewport(m_secondarySubViewport.x(), @@ -330,6 +331,7 @@ void Bars3DRenderer::drawSlicedScene() lineShader->setUniformValue(lineShader->ambientS(), m_cachedTheme->ambientLightStrength() * 2.3f); lineShader->setUniformValue(lineShader->lightS(), 0.0f); + lineShader->setUniformValue(lineShader->lightColor(), lightColor); if (rowMode) scaleFactor = (1.1f * m_rowWidth) / m_scaleFactor; @@ -441,6 +443,7 @@ void Bars3DRenderer::drawSlicedScene() m_barShader->setUniformValue(m_barShader->lightS(), 0.15f); m_barShader->setUniformValue(m_barShader->ambientS(), m_cachedTheme->ambientLightStrength() * 2.3f); + m_barShader->setUniformValue(m_barShader->lightColor(), lightColor); m_barGradientShader->bind(); m_barGradientShader->setUniformValue(m_barGradientShader->lightP(), lightPos); m_barGradientShader->setUniformValue(m_barGradientShader->view(), viewMatrix); @@ -448,6 +451,7 @@ void Bars3DRenderer::drawSlicedScene() m_barGradientShader->setUniformValue(m_barGradientShader->ambientS(), m_cachedTheme->ambientLightStrength() * 2.3f); m_barGradientShader->setUniformValue(m_barGradientShader->gradientMin(), 0.0f); + m_barGradientShader->setUniformValue(m_barGradientShader->lightColor(), lightColor); // Default to uniform shader ShaderHelper *barShader = m_barShader; @@ -711,6 +715,8 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) GLfloat colPos = 0; GLfloat rowPos = 0; + QVector3D lightColor = Utils::vectorFromColor(m_cachedTheme->lightColor()); + int seriesCount = m_visibleSeriesList.size(); const Q3DCamera *activeCamera = m_cachedScene->activeCamera(); @@ -722,7 +728,8 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) // Set up projection matrix QMatrix4x4 projectionMatrix; - GLfloat viewPortRatio = (GLfloat)m_primarySubViewport.width() / (GLfloat)m_primarySubViewport.height(); + GLfloat viewPortRatio = (GLfloat)m_primarySubViewport.width() + / (GLfloat)m_primarySubViewport.height(); projectionMatrix.perspective(45.0f, viewPortRatio, 0.1f, 100.0f); // Get the view matrix @@ -1026,6 +1033,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) m_barGradientShader->setUniformValue(m_barGradientShader->ambientS(), m_cachedTheme->ambientLightStrength()); m_barGradientShader->setUniformValue(m_barGradientShader->gradientMin(), 0.0f); + m_barGradientShader->setUniformValue(m_barGradientShader->lightColor(), lightColor); } if (haveUniformColorSeries) { @@ -1034,6 +1042,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) m_barShader->setUniformValue(m_barShader->view(), viewMatrix); m_barShader->setUniformValue(m_barShader->ambientS(), m_cachedTheme->ambientLightStrength()); + m_barShader->setUniformValue(m_barShader->lightColor(), lightColor); barShader = m_barShader; } else { barShader = m_barGradientShader; @@ -1264,6 +1273,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) barShader->setUniformValue(barShader->shadowQ(), m_shadowQualityToShader); barShader->setUniformValue(barShader->depth(), depthMVPMatrix); barShader->setUniformValue(barShader->lightS(), shadowLightStrength); + barShader->setUniformValue(barShader->lightColor(), lightColor); // Draw the object m_drawer->drawObject(barShader, barObj, gradientTexture, m_depthTexture); @@ -1326,6 +1336,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) m_backgroundShader->setUniformValue(m_backgroundShader->color(), backgroundColor); m_backgroundShader->setUniformValue(m_backgroundShader->ambientS(), m_cachedTheme->ambientLightStrength() * 2.0f); + m_backgroundShader->setUniformValue(m_backgroundShader->lightColor(), lightColor); #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QAbstract3DGraph::ShadowQualityNone) { @@ -1408,6 +1419,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) lineShader->setUniformValue(lineShader->view(), viewMatrix); lineShader->setUniformValue(lineShader->color(), barColor); lineShader->setUniformValue(lineShader->ambientS(), m_cachedTheme->ambientLightStrength()); + lineShader->setUniformValue(lineShader->lightColor(), lightColor); #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QAbstract3DGraph::ShadowQualityNone) { // Set shadowed shader bindings @@ -1821,7 +1833,8 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) labelText.replace(valueLabelTag, valueLabelText); } - labelText.replace(seriesNameTag, m_visibleSeriesList[m_visualSelectedBarSeriesIndex].name()); + labelText.replace(seriesNameTag, + m_visibleSeriesList[m_visualSelectedBarSeriesIndex].name()); selectedBar->setSelectionLabel(labelText); m_selectionLabelDirty = false; diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp index ce9560c8..22910756 100644 --- a/src/datavisualization/engine/scatter3drenderer.cpp +++ b/src/datavisualization/engine/scatter3drenderer.cpp @@ -258,6 +258,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) const Q3DCamera *activeCamera = m_cachedScene->activeCamera(); + QVector3D lightColor = Utils::vectorFromColor(m_cachedTheme->lightColor()); + // Specify viewport glViewport(m_primarySubViewport.x(), m_primarySubViewport.y(), @@ -266,7 +268,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) // Set up projection matrix QMatrix4x4 projectionMatrix; - GLfloat viewPortRatio = (GLfloat)m_primarySubViewport.width() / (GLfloat)m_primarySubViewport.height(); + GLfloat viewPortRatio = (GLfloat)m_primarySubViewport.width() + / (GLfloat)m_primarySubViewport.height(); projectionMatrix.perspective(45.0f, viewPortRatio, 0.1f, 100.0f); // Calculate view matrix @@ -608,6 +611,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) m_dotGradientShader->setUniformValue(m_dotGradientShader->view(), viewMatrix); m_dotGradientShader->setUniformValue(m_dotGradientShader->ambientS(), m_cachedTheme->ambientLightStrength()); + m_dotGradientShader->setUniformValue(m_dotGradientShader->lightColor(), lightColor); } if (haveUniformColorMeshSeries) { m_dotShader->bind(); @@ -615,6 +619,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) m_dotShader->setUniformValue(m_dotShader->view(), viewMatrix); m_dotShader->setUniformValue(m_dotShader->ambientS(), m_cachedTheme->ambientLightStrength()); + m_dotShader->setUniformValue(m_dotShader->lightColor(), lightColor); dotShader = m_dotShader; } else { dotShader = m_dotGradientShader; @@ -829,6 +834,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) m_backgroundShader->setUniformValue(m_backgroundShader->color(), backgroundColor); m_backgroundShader->setUniformValue(m_backgroundShader->ambientS(), m_cachedTheme->ambientLightStrength() * 2.0f); + m_backgroundShader->setUniformValue(m_backgroundShader->lightColor(), lightColor); #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QAbstract3DGraph::ShadowQualityNone) { @@ -878,6 +884,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) lineShader->setUniformValue(lineShader->view(), viewMatrix); lineShader->setUniformValue(lineShader->color(), lineColor); lineShader->setUniformValue(lineShader->ambientS(), m_cachedTheme->ambientLightStrength()); + lineShader->setUniformValue(lineShader->lightColor(), lightColor); #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QAbstract3DGraph::ShadowQualityNone) { // Set shadowed shader bindings @@ -888,7 +895,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) #endif { // Set shadowless shader bindings - lineShader->setUniformValue(lineShader->lightS(), m_cachedTheme->lightStrength() / 2.5f); + lineShader->setUniformValue(lineShader->lightS(), + m_cachedTheme->lightStrength() / 2.5f); } QQuaternion lineYRotation = QQuaternion(); @@ -1692,7 +1700,8 @@ void Scatter3DRenderer::initShaders(const QString &vertexShader, const QString & m_dotShader->initialize(); } -void Scatter3DRenderer::initGradientShaders(const QString &vertexShader, const QString &fragmentShader) +void Scatter3DRenderer::initGradientShaders(const QString &vertexShader, + const QString &fragmentShader) { if (m_dotGradientShader) delete m_dotGradientShader; @@ -1789,7 +1798,9 @@ QVector3D Scatter3DRenderer::indexToSelectionColor(GLint index) return QVector3D(dotIdxRed, dotIdxGreen, dotIdxBlue); } -void Scatter3DRenderer::selectionColorToSeriesAndIndex(const QVector3D &color, int &index, QAbstract3DSeries *&series) +void Scatter3DRenderer::selectionColorToSeriesAndIndex(const QVector3D &color, + int &index, + QAbstract3DSeries *&series) { if (color != selectionSkipColor) { index = int(color.x()) diff --git a/src/datavisualization/engine/selectionpointer.cpp b/src/datavisualization/engine/selectionpointer.cpp index 7a47c43f..9cc13224 100644 --- a/src/datavisualization/engine/selectionpointer.cpp +++ b/src/datavisualization/engine/selectionpointer.cpp @@ -134,8 +134,11 @@ void SelectionPointer::render(GLuint defaultFboHandle) m_pointShader->setUniformValue(m_pointShader->nModel(), itModelMatrix.inverted().transposed()); m_pointShader->setUniformValue(m_pointShader->color(), m_highlightColor); m_pointShader->setUniformValue(m_pointShader->MVP(), MVPMatrix); - m_pointShader->setUniformValue(m_pointShader->ambientS(), m_cachedTheme->ambientLightStrength()); + m_pointShader->setUniformValue(m_pointShader->ambientS(), + m_cachedTheme->ambientLightStrength()); m_pointShader->setUniformValue(m_pointShader->lightS(), m_cachedTheme->lightStrength() * 2.0f); + m_pointShader->setUniformValue(m_pointShader->lightColor(), + Utils::vectorFromColor(m_cachedTheme->lightColor())); m_drawer->drawObject(m_pointShader, m_pointObj); diff --git a/src/datavisualization/engine/shaders/colorOnY.frag b/src/datavisualization/engine/shaders/colorOnY.frag index caea959b..8c610cd7 100644 --- a/src/datavisualization/engine/shaders/colorOnY.frag +++ b/src/datavisualization/engine/shaders/colorOnY.frag @@ -6,6 +6,7 @@ uniform highp float ambientStrength; uniform sampler2D textureSampler; uniform highp float gradMin; uniform highp float gradHeight; +uniform highp vec3 lightColor; varying highp vec3 position_wrld; varying highp vec3 normal_cmr; @@ -16,8 +17,8 @@ varying highp vec2 coords_mdl; void main() { highp vec2 gradientUV = vec2(0.0, gradMin + ((coords_mdl.y + 1.0) * gradHeight)); 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 materialAmbientColor = lightColor * ambientStrength * materialDiffuseColor; + highp vec3 materialSpecularColor = lightColor; highp float distance = length(lightPosition_wrld - position_wrld); highp vec3 n = normalize(normal_cmr); diff --git a/src/datavisualization/engine/shaders/colorOnY_ES2.frag b/src/datavisualization/engine/shaders/colorOnY_ES2.frag index bb6e28c7..5b553562 100644 --- a/src/datavisualization/engine/shaders/colorOnY_ES2.frag +++ b/src/datavisualization/engine/shaders/colorOnY_ES2.frag @@ -4,6 +4,7 @@ uniform highp float ambientStrength; uniform sampler2D textureSampler; uniform highp float gradMin; uniform highp float gradHeight; +uniform highp vec3 lightColor; varying highp vec3 position_wrld; varying highp vec3 normal_cmr; @@ -14,8 +15,8 @@ varying highp vec2 coords_mdl; void main() { highp vec2 gradientUV = vec2(0.0, gradMin + ((coords_mdl.y + 1.0) * gradHeight)); 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 materialAmbientColor = lightColor * ambientStrength * materialDiffuseColor; + highp vec3 materialSpecularColor = lightColor; highp float distance = length(lightPosition_wrld - position_wrld); highp vec3 n = normalize(normal_cmr); diff --git a/src/datavisualization/engine/shaders/default.frag b/src/datavisualization/engine/shaders/default.frag index fba1ce4a..ca6fefb9 100644 --- a/src/datavisualization/engine/shaders/default.frag +++ b/src/datavisualization/engine/shaders/default.frag @@ -11,11 +11,12 @@ uniform highp vec3 lightPosition_wrld; uniform highp vec3 color_mdl; uniform highp float lightStrength; uniform highp float ambientStrength; +uniform highp vec3 lightColor; void main() { highp vec3 materialDiffuseColor = color_mdl.rgb; - highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; - highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); + highp vec3 materialAmbientColor = lightColor * ambientStrength * materialDiffuseColor; + highp vec3 materialSpecularColor = lightColor; highp float distance = length(lightPosition_wrld - position_wrld); diff --git a/src/datavisualization/engine/shaders/default_ES2.frag b/src/datavisualization/engine/shaders/default_ES2.frag index 7d6214b2..bc5c18b6 100644 --- a/src/datavisualization/engine/shaders/default_ES2.frag +++ b/src/datavisualization/engine/shaders/default_ES2.frag @@ -9,11 +9,12 @@ uniform highp vec3 lightPosition_wrld; uniform highp vec3 color_mdl; uniform highp float lightStrength; uniform highp float ambientStrength; +uniform highp vec3 lightColor; void main() { highp vec3 materialDiffuseColor = color_mdl.rgb; - highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; - highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); + highp vec3 materialAmbientColor = lightColor * ambientStrength * materialDiffuseColor; + highp vec3 materialSpecularColor = lightColor; highp float distance = length(lightPosition_wrld - position_wrld); diff --git a/src/datavisualization/engine/shaders/shadow.frag b/src/datavisualization/engine/shaders/shadow.frag index 5309b5bb..6d212c08 100644 --- a/src/datavisualization/engine/shaders/shadow.frag +++ b/src/datavisualization/engine/shaders/shadow.frag @@ -5,6 +5,7 @@ uniform highp float ambientStrength; uniform highp float shadowQuality; uniform highp sampler2D textureSampler; uniform highp sampler2DShadow shadowMap; +uniform highp vec3 lightColor; varying highp vec4 shadowCoord; varying highp vec2 UV; @@ -38,8 +39,8 @@ highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), void main() { highp vec3 materialDiffuseColor = texture2D(textureSampler, UV).rgb; - highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; - highp vec3 materialSpecularColor = vec3(0.2, 0.2, 0.2); + highp vec3 materialAmbientColor = lightColor * ambientStrength * materialDiffuseColor; + highp vec3 materialSpecularColor = lightColor * 0.2; highp vec3 n = normalize(normal_cmr); highp vec3 l = normalize(lightDirection_cmr); diff --git a/src/datavisualization/engine/shaders/shadowNoTex.frag b/src/datavisualization/engine/shaders/shadowNoTex.frag index 0252ba49..12e86cb3 100644 --- a/src/datavisualization/engine/shaders/shadowNoTex.frag +++ b/src/datavisualization/engine/shaders/shadowNoTex.frag @@ -5,6 +5,7 @@ uniform highp float ambientStrength; uniform highp float shadowQuality; uniform highp vec3 color_mdl; uniform highp sampler2DShadow shadowMap; +uniform highp vec3 lightColor; varying highp vec4 shadowCoord; varying highp vec3 position_wrld; @@ -54,8 +55,8 @@ highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), void main() { highp vec3 materialDiffuseColor = color_mdl.rgb; - highp vec3 materialAmbientColor = vec3(ambientStrength, ambientStrength, ambientStrength) * materialDiffuseColor; - highp vec3 materialSpecularColor = vec3(1.0, 1.0, 1.0); + highp vec3 materialAmbientColor = lightColor * ambientStrength * materialDiffuseColor; + highp vec3 materialSpecularColor = lightColor; highp vec3 n = normalize(normal_cmr); highp vec3 l = normalize(lightDirection_cmr); diff --git a/src/datavisualization/engine/shaders/shadowNoTexColorOnY.frag b/src/datavisualization/engine/shaders/shadowNoTexColorOnY.frag index 9882cd92..5da1afc1 100644 --- a/src/datavisualization/engine/shaders/shadowNoTexColorOnY.frag +++ b/src/datavisualization/engine/shaders/shadowNoTexColorOnY.frag @@ -7,6 +7,7 @@ uniform highp sampler2DShadow shadowMap; uniform sampler2D textureSampler; uniform highp float gradMin; uniform highp float gradHeight; +uniform highp vec3 lightColor; varying highp vec4 shadowCoord; varying highp vec3 position_wrld; @@ -41,8 +42,8 @@ highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), void main() { highp vec2 gradientUV = vec2(0.0, gradMin + ((coords_mdl.y + 1.0) * gradHeight)); 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 materialAmbientColor = lightColor * ambientStrength * materialDiffuseColor; + highp vec3 materialSpecularColor = lightColor; highp vec3 n = normalize(normal_cmr); highp vec3 l = normalize(lightDirection_cmr); diff --git a/src/datavisualization/engine/shaders/surface.frag b/src/datavisualization/engine/shaders/surface.frag index 576cc51f..b5205d2d 100644 --- a/src/datavisualization/engine/shaders/surface.frag +++ b/src/datavisualization/engine/shaders/surface.frag @@ -10,12 +10,13 @@ uniform sampler2D textureSampler; uniform highp vec3 lightPosition_wrld; uniform highp float lightStrength; uniform highp float ambientStrength; +uniform highp vec3 lightColor; void main() { highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.0) / 2.0); 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 materialAmbientColor = lightColor * ambientStrength * materialDiffuseColor; + highp vec3 materialSpecularColor = lightColor; highp float distance = length(lightPosition_wrld - position_wrld); diff --git a/src/datavisualization/engine/shaders/surfaceFlat.frag b/src/datavisualization/engine/shaders/surfaceFlat.frag index fd42a289..7eaa917f 100644 --- a/src/datavisualization/engine/shaders/surfaceFlat.frag +++ b/src/datavisualization/engine/shaders/surfaceFlat.frag @@ -12,12 +12,13 @@ uniform sampler2D textureSampler; uniform highp vec3 lightPosition_wrld; uniform highp float lightStrength; uniform highp float ambientStrength; +uniform highp vec3 lightColor; void main() { highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.0) / 2.0); 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 materialAmbientColor = lightColor * ambientStrength * materialDiffuseColor; + highp vec3 materialSpecularColor = lightColor; highp float distance = length(lightPosition_wrld - position_wrld); diff --git a/src/datavisualization/engine/shaders/surfaceShadowFlat.frag b/src/datavisualization/engine/shaders/surfaceShadowFlat.frag index 6341136e..b2f2af74 100644 --- a/src/datavisualization/engine/shaders/surfaceShadowFlat.frag +++ b/src/datavisualization/engine/shaders/surfaceShadowFlat.frag @@ -15,6 +15,7 @@ uniform highp vec3 lightPosition_wrld; uniform highp float lightStrength; uniform highp float ambientStrength; uniform highp float shadowQuality; +uniform highp vec3 lightColor; highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), vec2(0.94558609, -0.76890725), @@ -36,8 +37,8 @@ highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), void main() { highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.0) / 2.0); 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 materialAmbientColor = lightColor * ambientStrength * materialDiffuseColor; + highp vec3 materialSpecularColor = lightColor; highp vec3 n = normalize(normal_cmr); highp vec3 l = normalize(lightDirection_cmr); diff --git a/src/datavisualization/engine/shaders/surfaceShadowNoTex.frag b/src/datavisualization/engine/shaders/surfaceShadowNoTex.frag index 755be3f1..004208bf 100644 --- a/src/datavisualization/engine/shaders/surfaceShadowNoTex.frag +++ b/src/datavisualization/engine/shaders/surfaceShadowNoTex.frag @@ -13,6 +13,7 @@ uniform highp vec3 lightPosition_wrld; uniform highp float lightStrength; uniform highp float ambientStrength; uniform highp float shadowQuality; +uniform highp vec3 lightColor; highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), vec2(0.94558609, -0.76890725), @@ -34,8 +35,8 @@ highp vec2 poissonDisk[16] = vec2[16](vec2(-0.94201624, -0.39906216), void main() { highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.0) / 2.0); 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 materialAmbientColor = lightColor * ambientStrength * materialDiffuseColor; + highp vec3 materialSpecularColor = lightColor; highp vec3 n = normalize(normal_cmr); highp vec3 l = normalize(lightDirection_cmr); diff --git a/src/datavisualization/engine/shaders/surface_ES2.frag b/src/datavisualization/engine/shaders/surface_ES2.frag index c7e75594..0e17cacd 100644 --- a/src/datavisualization/engine/shaders/surface_ES2.frag +++ b/src/datavisualization/engine/shaders/surface_ES2.frag @@ -9,12 +9,13 @@ uniform sampler2D textureSampler; uniform highp vec3 lightPosition_wrld; uniform highp float lightStrength; uniform highp float ambientStrength; +uniform highp vec3 lightColor; void main() { highp vec2 gradientUV = vec2(0.0, (coords_mdl.y + 1.0) / 2.0); 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 materialAmbientColor = lightColor * ambientStrength * materialDiffuseColor; + highp vec3 materialSpecularColor = lightColor; highp float distance = length(lightPosition_wrld - position_wrld); diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp index 45eb3391..b65cea83 100644 --- a/src/datavisualization/engine/surface3drenderer.cpp +++ b/src/datavisualization/engine/surface3drenderer.cpp @@ -567,6 +567,8 @@ void Surface3DRenderer::drawSlicedScene() { QVector3D lightPos; + QVector3D lightColor = Utils::vectorFromColor(m_cachedTheme->lightColor()); + // Specify viewport glViewport(m_secondarySubViewport.x(), m_secondarySubViewport.y(), @@ -642,6 +644,7 @@ void Surface3DRenderer::drawSlicedScene() surfaceShader->setUniformValue(surfaceShader->lightS(), 0.15f); surfaceShader->setUniformValue(surfaceShader->ambientS(), m_cachedTheme->ambientLightStrength() * 2.3f); + surfaceShader->setUniformValue(surfaceShader->lightColor(), lightColor); m_drawer->drawObject(surfaceShader, m_sliceSurfaceObj, baseGradientTexture); } @@ -674,6 +677,7 @@ void Surface3DRenderer::drawSlicedScene() lineShader->setUniformValue(lineShader->color(), lineColor); lineShader->setUniformValue(lineShader->ambientS(), m_cachedTheme->ambientLightStrength() * 2.3f); lineShader->setUniformValue(lineShader->lightS(), 0.0f); + lineShader->setUniformValue(lineShader->lightColor(), lightColor); // Horizontal lines if (m_axisCacheY.segmentCount() > 0) { @@ -832,6 +836,8 @@ void Surface3DRenderer::drawSlicedScene() void Surface3DRenderer::drawScene(GLuint defaultFboHandle) { GLfloat backgroundRotation = 0; + QVector3D lightColor = Utils::vectorFromColor(m_cachedTheme->lightColor()); + glViewport(m_primarySubViewport.x(), m_primarySubViewport.y(), m_primarySubViewport.width(), @@ -881,13 +887,15 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) // Draw depth buffer #if !defined(QT_OPENGL_ES_2) GLfloat adjustedLightStrength = m_cachedTheme->lightStrength() / 10.0f; - if (m_cachedShadowQuality > QAbstract3DGraph::ShadowQualityNone && m_surfaceObj && m_cachedSurfaceVisible) { + if (m_cachedShadowQuality > QAbstract3DGraph::ShadowQualityNone && m_surfaceObj + && m_cachedSurfaceVisible) { // 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); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, + m_depthTexture, 0); glClear(GL_DEPTH_BUFFER_BIT); // Bind depth shader @@ -948,7 +956,8 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthModelTexture, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, + m_depthModelTexture, 0); glClear(GL_DEPTH_BUFFER_BIT); // Draw the triangles @@ -1083,6 +1092,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) m_surfaceShader->setUniformValue(m_surfaceShader->MVP(), MVPMatrix); m_surfaceShader->setUniformValue(m_surfaceShader->ambientS(), m_cachedTheme->ambientLightStrength()); + m_surfaceShader->setUniformValue(m_surfaceShader->lightColor(), lightColor); // TODO: Do properly when multiseries support implemented QTRD-2657 GLuint gradientTexture; @@ -1095,12 +1105,14 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) if (m_cachedShadowQuality > QAbstract3DGraph::ShadowQualityNone) { // Set shadow shader bindings QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; - m_surfaceShader->setUniformValue(m_surfaceShader->shadowQ(), m_shadowQualityToShader); + m_surfaceShader->setUniformValue(m_surfaceShader->shadowQ(), + m_shadowQualityToShader); m_surfaceShader->setUniformValue(m_surfaceShader->depth(), depthMVPMatrix); m_surfaceShader->setUniformValue(m_surfaceShader->lightS(), adjustedLightStrength); // Draw the object - m_drawer->drawObject(m_surfaceShader, m_surfaceObj, gradientTexture, m_depthModelTexture); + m_drawer->drawObject(m_surfaceShader, m_surfaceObj, gradientTexture, + m_depthModelTexture); } else #endif { @@ -1167,6 +1179,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) m_backgroundShader->setUniformValue(m_backgroundShader->color(), backgroundColor); m_backgroundShader->setUniformValue(m_backgroundShader->ambientS(), m_cachedTheme->ambientLightStrength() * 2.0f); + m_backgroundShader->setUniformValue(m_backgroundShader->lightColor(), lightColor); #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QAbstract3DGraph::ShadowQualityNone) { @@ -1209,6 +1222,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) lineShader->setUniformValue(lineShader->view(), viewMatrix); lineShader->setUniformValue(lineShader->color(), lineColor); lineShader->setUniformValue(lineShader->ambientS(), m_cachedTheme->ambientLightStrength()); + lineShader->setUniformValue(lineShader->lightColor(), lightColor); #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QAbstract3DGraph::ShadowQualityNone) { // Set shadowed shader bindings @@ -1219,7 +1233,8 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) #endif { // Set shadowless shader bindings - lineShader->setUniformValue(lineShader->lightS(), m_cachedTheme->lightStrength() / 2.5f); + lineShader->setUniformValue(lineShader->lightS(), + m_cachedTheme->lightStrength() / 2.5f); } QQuaternion lineYRotation = QQuaternion(); @@ -2173,7 +2188,8 @@ void Surface3DRenderer::updateDepthBuffer() m_depthTexture = m_textureHelper->createDepthTextureFrameBuffer(m_primarySubViewport.size(), m_depthFrameBuffer, m_shadowQualityMultiplier); - m_textureHelper->fillDepthTexture(m_depthTexture, m_primarySubViewport.size(), m_shadowQualityMultiplier, 1.0f); + m_textureHelper->fillDepthTexture(m_depthTexture, m_primarySubViewport.size(), + m_shadowQualityMultiplier, 1.0f); m_depthModelTexture = m_textureHelper->createDepthTexture(m_primarySubViewport.size(), m_shadowQualityMultiplier); if (!m_depthTexture || !m_depthModelTexture) -- cgit v1.2.3