From 7ef676c7cbe5e3a960a66150794be3a862642073 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 19 Aug 2014 14:15:52 +0300 Subject: Make volume transparency uniform regardless of viewing angle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: If3acbb161b99f67d81f7af9c05ae8bcfe154e052 Reviewed-by: Tomi Korpipää --- src/datavisualization/engine/shaders/texture3d.frag | 11 +++++++++-- src/datavisualization/engine/shaders/texture3dslice.frag | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src/datavisualization/engine/shaders') 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 -- cgit v1.2.3