summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2014-08-19 14:15:52 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2014-08-20 07:53:06 +0300
commit7ef676c7cbe5e3a960a66150794be3a862642073 (patch)
tree4c72e7f6ee7e6a39079ed97077485491e1ccd292
parent7b61b89e4e6a91e7984cd69180468640fe3f9dc8 (diff)
Make volume transparency uniform regardless of viewing angle
Change-Id: If3acbb161b99f67d81f7af9c05ae8bcfe154e052 Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
-rw-r--r--examples/datavisualization/volumetric/volumetric.cpp2
-rw-r--r--src/datavisualization/engine/shaders/texture3d.frag11
-rw-r--r--src/datavisualization/engine/shaders/texture3dslice.frag3
3 files changed, 12 insertions, 4 deletions
diff --git a/examples/datavisualization/volumetric/volumetric.cpp b/examples/datavisualization/volumetric/volumetric.cpp
index ab68e64e..b4ea769c 100644
--- a/examples/datavisualization/volumetric/volumetric.cpp
+++ b/examples/datavisualization/volumetric/volumetric.cpp
@@ -85,7 +85,7 @@ VolumetricModifier::VolumetricModifier(Q3DScatter *scatter)
if (i < cutOffColorIndex)
m_colorTable1[i] = qRgba(0, 0, 0, 0);
else if (i < 60)
- m_colorTable1[i] = qRgba((i * 2) + 120, 0, 0, 50);
+ m_colorTable1[i] = qRgba((i * 2) + 120, 0, 0, 20);
else if (i < 120)
m_colorTable1[i] = qRgba(0, ((i - 60) * 2) + 120, 0, 255);
else if (i < 180)
diff --git a/src/datavisualization/engine/shaders/texture3d.frag b/src/datavisualization/engine/shaders/texture3d.frag
index b9d87fcc..e56506ff 100644
--- a/src/datavisualization/engine/shaders/texture3d.frag
+++ b/src/datavisualization/engine/shaders/texture3d.frag
@@ -9,7 +9,7 @@ uniform highp int color8Bit;
uniform highp vec3 textureDimensions;
uniform highp int sampleCount; // This is the maximum sample count
-const float alphaThreshold = 0.001;
+const highp float alphaThreshold = 0.0001;
void main() {
// Raytrace into volume, need to sample pixels along the eye ray until we hit opacity 1
@@ -51,6 +51,10 @@ void main() {
// Offset a fraction of a step so we are not exactly on a texel boundary.
highp vec3 curPos = rayStart - (0.5 * step);
+ // Adjust alpha multiplier according to the step size to get uniform alpha effect
+ // regardless of the ray angle.
+ highp float alphaMultiplier = stepSize / (1.0 / sampleCount);
+
highp float totalDist = 0.0;
highp float totalAlpha = 0.0;
highp vec4 destColor = vec4(0, 0, 0, 0);
@@ -63,7 +67,10 @@ void main() {
if (color8Bit != 0)
curColor = colorIndex[int(curColor.r * 255.0)];
- curAlpha = curColor.a;
+ if (curColor.a == 1.0)
+ curAlpha = 1.0;
+ else
+ curAlpha = clamp(curColor.a * alphaMultiplier, 0.0, 1.0);
if (curAlpha > alphaThreshold) {
curRgb = curColor.rgb * curAlpha * (1.0 - totalAlpha);
destColor.rgb += curRgb;
diff --git a/src/datavisualization/engine/shaders/texture3dslice.frag b/src/datavisualization/engine/shaders/texture3dslice.frag
index 641b32a5..e095bc5f 100644
--- a/src/datavisualization/engine/shaders/texture3dslice.frag
+++ b/src/datavisualization/engine/shaders/texture3dslice.frag
@@ -12,7 +12,8 @@ const highp vec3 xPlaneNormal = vec3(1.0, 0, 0);
const highp vec3 yPlaneNormal = vec3(0, 1.0, 0);
const highp vec3 zPlaneNormal = vec3(0, 0, 1.0);
-const float alphaThreshold = 0.001;
+const highp float alphaThreshold = 0.0001;
+
void main() {
// Raytrace into volume, need to sample pixels along the eye ray until we hit opacity 1