From 02cea907917a09f66e60dd5005f53780086df7e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Korpip=C3=A4=C3=A4?= Date: Tue, 24 Sep 2013 12:59:38 +0300 Subject: Zero-color gradient fix for surface Task-number: QTRD-2329 Change-Id: I616e2e97ac67ddd9fbdf2d0715f5841b3df46561 Change-Id: I616e2e97ac67ddd9fbdf2d0715f5841b3df46561 Reviewed-by: Mika Salmela --- src/datavisualization/data/qheightmapsurfacedataproxy.cpp | 4 ++-- src/datavisualization/engine/shaders/surface.frag | 5 +---- src/datavisualization/engine/shaders/surface.vert | 3 --- src/datavisualization/engine/shaders/surfaceFlat.frag | 4 +--- src/datavisualization/engine/shaders/surfaceFlat.vert | 3 --- src/datavisualization/engine/surface3drenderer.cpp | 4 ++-- 6 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/datavisualization/data/qheightmapsurfacedataproxy.cpp b/src/datavisualization/data/qheightmapsurfacedataproxy.cpp index f40fa395..25e2a4db 100644 --- a/src/datavisualization/data/qheightmapsurfacedataproxy.cpp +++ b/src/datavisualization/data/qheightmapsurfacedataproxy.cpp @@ -213,7 +213,7 @@ void QHeightMapSurfaceDataProxyPrivate::handlePendingResolve() for (int i = imageHeight; i > 0; i--, bitCount -= widthBits) { QSurfaceDataRow *newRow = new QSurfaceDataRow(imageWidth); for (int j = 0; j < imageWidth; j++) - (*newRow)[j] = qreal(bits[bitCount + (j * 4)]) + 0.1; // Add 0.1 to raise it above ground to avoid glimmering at 0 height + (*newRow)[j] = qreal(bits[bitCount + (j * 4)]); *dataArray << newRow; } } else { @@ -225,7 +225,7 @@ void QHeightMapSurfaceDataProxyPrivate::handlePendingResolve() height = (qreal(bits[bitCount + nextpixel]) + qreal(bits[1 + bitCount + nextpixel]) + qreal(bits[2 + bitCount + nextpixel])); - (*newRow)[j] = (height / 3.0) + 0.1; // Add 0.1 to raise it above ground to avoid glimmering at 0 height + (*newRow)[j] = (height / 3.0); } *dataArray << newRow; } diff --git a/src/datavisualization/engine/shaders/surface.frag b/src/datavisualization/engine/shaders/surface.frag index 9fe7f45b..4b1357b1 100644 --- a/src/datavisualization/engine/shaders/surface.frag +++ b/src/datavisualization/engine/shaders/surface.frag @@ -1,6 +1,5 @@ #version 120 -varying highp vec2 UV; varying highp vec3 coords_mdl; varying highp vec3 position_wrld; varying highp vec3 normal_cmr; @@ -13,7 +12,7 @@ uniform highp float lightStrength; uniform highp float ambientStrength; void main() { - highp vec2 gradientUV = vec2(0.5, (coords_mdl.y + 1.0) / 2.0); + 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); @@ -28,12 +27,10 @@ void main() { highp vec3 R = reflect(-l, n); highp float cosAlpha = clamp(dot(E, R), 0.0, 1.0); -// gl_FragColor.rgb = materialDiffuseColor; gl_FragColor.rgb = materialAmbientColor + materialDiffuseColor * lightStrength * pow(cosTheta, 2) / distance + materialSpecularColor * lightStrength * pow(cosAlpha, 10) / distance; gl_FragColor.a = 1.0; -// gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); } diff --git a/src/datavisualization/engine/shaders/surface.vert b/src/datavisualization/engine/shaders/surface.vert index a44d413b..28152abc 100644 --- a/src/datavisualization/engine/shaders/surface.vert +++ b/src/datavisualization/engine/shaders/surface.vert @@ -1,5 +1,4 @@ attribute highp vec3 vertexPosition_mdl; -attribute highp vec2 vertexUV; attribute highp vec3 vertexNormal_mdl; uniform highp mat4 MVP; @@ -8,7 +7,6 @@ uniform highp mat4 M; uniform highp mat4 itM; uniform highp vec3 lightPosition_wrld; -varying highp vec2 UV; varying highp vec3 position_wrld; varying highp vec3 normal_cmr; varying highp vec3 eyeDirection_cmr; @@ -24,5 +22,4 @@ void main() { 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; - UV = vertexUV; } diff --git a/src/datavisualization/engine/shaders/surfaceFlat.frag b/src/datavisualization/engine/shaders/surfaceFlat.frag index eb398582..a8a3dbb1 100644 --- a/src/datavisualization/engine/shaders/surfaceFlat.frag +++ b/src/datavisualization/engine/shaders/surfaceFlat.frag @@ -1,6 +1,5 @@ #version 150 -varying highp vec2 UV; varying highp vec3 coords_mdl; varying highp vec3 position_wrld; flat in highp vec3 normal_cmr; @@ -13,7 +12,7 @@ uniform highp float lightStrength; uniform highp float ambientStrength; void main() { - highp vec2 gradientUV = vec2(0.5, (coords_mdl.y + 1.0) / 2.0); + 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); @@ -28,7 +27,6 @@ void main() { highp vec3 R = reflect(-l, n); highp float cosAlpha = clamp(dot(E, R), 0.0, 1.0); -// gl_FragColor.rgb = materialDiffuseColor; gl_FragColor.rgb = materialAmbientColor + materialDiffuseColor * lightStrength * pow(cosTheta, 2) / distance + diff --git a/src/datavisualization/engine/shaders/surfaceFlat.vert b/src/datavisualization/engine/shaders/surfaceFlat.vert index 24c9b9a3..7e248d02 100644 --- a/src/datavisualization/engine/shaders/surfaceFlat.vert +++ b/src/datavisualization/engine/shaders/surfaceFlat.vert @@ -1,7 +1,6 @@ #version 150 attribute highp vec3 vertexPosition_mdl; -attribute highp vec2 vertexUV; attribute highp vec3 vertexNormal_mdl; uniform highp mat4 MVP; @@ -10,7 +9,6 @@ uniform highp mat4 M; uniform highp mat4 itM; uniform highp vec3 lightPosition_wrld; -varying highp vec2 UV; varying highp vec3 position_wrld; flat out highp vec3 normal_cmr; varying highp vec3 eyeDirection_cmr; @@ -26,5 +24,4 @@ void main() { 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; - UV = vertexUV; } diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp index 6d4a06fd..34ecd951 100644 --- a/src/datavisualization/engine/surface3drenderer.cpp +++ b/src/datavisualization/engine/surface3drenderer.cpp @@ -1221,11 +1221,11 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) void Surface3DRenderer::updateSurfaceGradient(const QLinearGradient &gradient) { - QImage image(QSize(4, 1000), QImage::Format_RGB32); + QImage image(QSize(1, 1000), QImage::Format_RGB32); QPainter pmp(&image); pmp.setBrush(QBrush(gradient)); pmp.setPen(Qt::NoPen); - pmp.drawRect(0, 0, 4, 1000); + pmp.drawRect(0, 0, 1, 1000); if (m_gradientTexture) { m_textureHelper->deleteTexture(&m_gradientTexture); -- cgit v1.2.3