diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2014-08-19 14:15:52 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2014-08-20 07:53:06 +0300 |
commit | 7ef676c7cbe5e3a960a66150794be3a862642073 (patch) | |
tree | 4c72e7f6ee7e6a39079ed97077485491e1ccd292 /src/datavisualization/engine/shaders | |
parent | 7b61b89e4e6a91e7984cd69180468640fe3f9dc8 (diff) |
Make volume transparency uniform regardless of viewing angle
Change-Id: If3acbb161b99f67d81f7af9c05ae8bcfe154e052
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/engine/shaders')
-rw-r--r-- | src/datavisualization/engine/shaders/texture3d.frag | 11 | ||||
-rw-r--r-- | src/datavisualization/engine/shaders/texture3dslice.frag | 3 |
2 files changed, 11 insertions, 3 deletions
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 |