summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/engine/shaders/texture3d.vert
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2014-09-09 11:30:15 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2014-09-10 12:30:54 +0300
commitddb9be979d93b7e17f1067dc6056de54d9828b29 (patch)
treedf612c56e4a804481297ae55b29f0ee379c5f8ab /src/datavisualization/engine/shaders/texture3d.vert
parentbb30ea555c71604de9a2bc5096fa35c9532b26bd (diff)
Limit volume to axis ranges
The volume object that would go partially outside axis ranges is scale and repositioned so that it only renders the portion that is inside the axis ranges. Change-Id: I792494e437998ba6276f58fab645767276c1476d Reviewed-by: Mika Salmela <mika.salmela@digia.com>
Diffstat (limited to 'src/datavisualization/engine/shaders/texture3d.vert')
-rw-r--r--src/datavisualization/engine/shaders/texture3d.vert26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/datavisualization/engine/shaders/texture3d.vert b/src/datavisualization/engine/shaders/texture3d.vert
index cad1ce06..ef3f1b25 100644
--- a/src/datavisualization/engine/shaders/texture3d.vert
+++ b/src/datavisualization/engine/shaders/texture3d.vert
@@ -1,12 +1,36 @@
uniform highp mat4 MVP;
+uniform highp vec3 minBounds;
+uniform highp vec3 maxBounds;
+uniform highp vec3 cameraPositionRelativeToModel;
attribute highp vec3 vertexPosition_mdl;
attribute highp vec2 vertexUV;
attribute highp vec3 vertexNormal_mdl;
varying highp vec3 pos;
+varying highp vec3 rayDir;
void main() {
gl_Position = MVP * vec4(vertexPosition_mdl, 1.0);
- pos = vertexPosition_mdl;
+
+ highp vec3 minBoundsNorm = minBounds;
+ highp vec3 maxBoundsNorm = maxBounds;
+
+ // Y and Z are flipped in bounds to be directly usable in texture calculations,
+ // so flip them back to normal for position calculations
+ minBoundsNorm.yz = -minBoundsNorm.yz;
+ maxBoundsNorm.yz = -maxBoundsNorm.yz;
+
+ minBoundsNorm = 0.5 * (minBoundsNorm + 1.0);
+ maxBoundsNorm = 0.5 * (maxBoundsNorm + 1.0);
+
+ pos = vertexPosition_mdl
+ + ((1.0 - vertexPosition_mdl) * minBoundsNorm)
+ - ((1.0 + vertexPosition_mdl) * (1.0 - maxBoundsNorm));
+
+ rayDir = -(cameraPositionRelativeToModel - pos);
+
+ // Flip Y and Z so QImage bits work directly for texture and first image is in the front
+ rayDir.yz = -rayDir.yz;
+ pos.yz = -pos.yz;
}