summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/engine/shaders/texture3dslice.frag
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2014-08-25 13:16:04 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2014-08-25 15:01:10 +0300
commit5a51d06ec8f0210f51e65abfde9f868ab7bfa8ef (patch)
tree2319880f2d66e5610d9d1040d886f52cada82ad8 /src/datavisualization/engine/shaders/texture3dslice.frag
parentf9bb71fd11cce59d74e78202a1117c8abb3a2e44 (diff)
Add alpha multiplier to QCustom3DVolume api
Change-Id: I856c4166513f6d6f7b73fd52bc46d52ab1b8fdff Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com> Reviewed-by: Mika Salmela <mika.salmela@digia.com>
Diffstat (limited to 'src/datavisualization/engine/shaders/texture3dslice.frag')
-rw-r--r--src/datavisualization/engine/shaders/texture3dslice.frag54
1 files changed, 38 insertions, 16 deletions
diff --git a/src/datavisualization/engine/shaders/texture3dslice.frag b/src/datavisualization/engine/shaders/texture3dslice.frag
index 8870b26d..3d4c9030 100644
--- a/src/datavisualization/engine/shaders/texture3dslice.frag
+++ b/src/datavisualization/engine/shaders/texture3dslice.frag
@@ -7,6 +7,8 @@ uniform highp vec3 cameraPositionRelativeToModel;
uniform highp vec3 volumeSliceIndices;
uniform highp vec4 colorIndex[256];
uniform highp int color8Bit;
+uniform highp float alphaMultiplier;
+uniform highp int preserveOpacity;
const highp vec3 xPlaneNormal = vec3(1.0, 0, 0);
const highp vec3 yPlaneNormal = vec3(0, 1.0, 0);
@@ -76,47 +78,67 @@ void main() {
}
highp vec4 destColor = vec4(0.0, 0.0, 0.0, 0.0);
+ highp vec4 curColor = vec4(0.0, 0.0, 0.0, 0.0);
highp float totalAlpha = 0.0;
highp vec3 curRgb = vec3(0, 0, 0);
+ highp float curAlpha = 0.0;
// Convert intersection to texture coords
if (firstD <= tFar) {
highp vec3 firstTex = rayStart + rayDir * firstD;
firstTex = 0.5 * (firstTex + 1.0);
- highp vec4 firstColor = texture3D(textureSampler, firstTex);
+ curColor = texture3D(textureSampler, firstTex);
if (color8Bit != 0)
- firstColor = colorIndex[int(firstColor.r * 255.0)];
+ curColor = colorIndex[int(curColor.r * 255.0)];
- if (firstColor.a > alphaThreshold) {
- destColor.rgb = firstColor.rgb * firstColor.a;
- totalAlpha = firstColor.a;
+ if (curColor.a > alphaThreshold) {
+ curAlpha = curColor.a;
+ if (curColor.a == 1.0 && preserveOpacity != 0)
+ curAlpha = 1.0;
+ else
+ curAlpha = clamp(curColor.a * alphaMultiplier, 0.0, 1.0);
+ destColor.rgb = curColor.rgb * curAlpha;
+ totalAlpha = curAlpha;
}
if (secondD <= tFar && totalAlpha < 1.0) {
highp vec3 secondTex = rayStart + rayDir * secondD;
secondTex = 0.5 * (secondTex + 1.0);
- highp vec4 secondColor = texture3D(textureSampler, secondTex);
+ curColor = texture3D(textureSampler, secondTex);
if (color8Bit != 0)
- secondColor = colorIndex[int(secondColor.r * 255.0)];
- if (secondColor.a > alphaThreshold) {
- curRgb = secondColor.rgb * secondColor.a * (1.0 - totalAlpha);
+ curColor = colorIndex[int(curColor.r * 255.0)];
+ if (curColor.a > alphaThreshold) {
+ if (curColor.a == 1.0 && preserveOpacity != 0)
+ curAlpha = 1.0;
+ else
+ curAlpha = clamp(curColor.a * alphaMultiplier, 0.0, 1.0);
+ curRgb = curColor.rgb * curAlpha * (1.0 - totalAlpha);
destColor.rgb += curRgb;
- totalAlpha += secondColor.a;
+ totalAlpha += curAlpha;
}
if (thirdD <= tFar && totalAlpha < 1.0) {
highp vec3 thirdTex = rayStart + rayDir * thirdD;
thirdTex = 0.5 * (thirdTex + 1.0);
- highp vec4 thirdColor = texture3D(textureSampler, thirdTex);
- if (color8Bit != 0)
- thirdColor = colorIndex[int(thirdColor.r * 255.0)];
- if (thirdColor.a > alphaThreshold) {
- curRgb = thirdColor.rgb * thirdColor.a * (1.0 - totalAlpha);
+ curColor = texture3D(textureSampler, thirdTex);
+ if (curColor.a > alphaThreshold) {
+ if (color8Bit != 0)
+ curColor = colorIndex[int(curColor.r * 255.0)];
+ if (curColor.a == 1.0 && preserveOpacity != 0)
+ curAlpha = 1.0;
+ else
+ curAlpha = clamp(curColor.a * alphaMultiplier, 0.0, 1.0);
+ curRgb = curColor.rgb * curAlpha * (1.0 - totalAlpha);
destColor.rgb += curRgb;
- totalAlpha += thirdColor.a;
+ totalAlpha += curAlpha;
}
}
}
}
+
+ // Brighten up the final color if there is some transparency left
+ if (totalAlpha > alphaThreshold && totalAlpha < 1.0)
+ destColor *= 1.0 / totalAlpha;
+
destColor.a = totalAlpha;
gl_FragColor = clamp(destColor, 0.0, 1.0);
}