1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
23
//---------------------------------------------------------------------------
27
#include "WGETextureTools.glsl"
30
* These two uniforms are needed to transform the vectors out of their texture
31
* back to their original form as they are stored in RBGA (for example allowing
32
* only values between 0..1 for components but no negative ones).
34
uniform float u_vectorsMin; uniform float u_vectorsScale;
37
* The matrix describes the transformation of gl_Vertex to OpenWalnut Scene Space
39
uniform mat4 u_WorldTransform;
42
* Vector dataset as texture.
44
uniform sampler3D u_vectorsSampler;
47
* Probabilistic tract as texture.
49
uniform sampler3D u_probTractSampler;
52
* Number of voxels in X direction.
54
uniform int u_probTractSizeX;
57
* Number of voxels in Y direction.
59
uniform int u_probTractSizeY;
62
* Number of voxels in Z direction.
64
uniform int u_probTractSizeZ;
66
// For correct transformation into texture space we also need the size of each voxel.
68
* Voxel size in X direction.
70
uniform float u_pixelSizeX;
73
* Voxel size in Y direction.
75
uniform float u_pixelSizeY;
78
* Voxel size in Z direction.
80
uniform float u_pixelSizeZ;
82
// vectors spanning the plane of the quad
87
* First focal point, which is one of the endings of the projected diffusion direction.
89
varying vec3 focalPoint1;
92
* Second focal point, which is one of the endings of the projected diffusion direction.
94
varying vec3 focalPoint2;
96
// Scaled focal points, as otherwise the the stipple endings may not fit inside quad.
98
* Fixed factor for scaling.
100
uniform float scale = 0.8;
103
* First focal point, scaled.
105
varying vec3 scaledFocalPoint1;
108
* Second focal poin, scaled.
110
varying vec3 scaledFocalPoint2;
113
* Maximum connectivity score withing the probabilistic tract dataset. This is
114
* needed for scaling the connectivities between 0.0 and 1.0.
116
uniform float u_maxConnectivityScore;
119
* Scaled connectivity score; now between 0.0...1.0.
121
varying float probability;
124
* Probabilities below this threshold are ignored and discarded.
126
uniform float u_threshold;
129
* Middle point of the quad in texture coordinates, needed for scaling the
130
* projection of the principal diffusion direction to fit inside quad.
132
uniform vec3 middlePoint_tex = vec3( 0.5, 0.5, 0.0 );
135
* Vertex Main. Simply transforms the geometry. The work is done per fragment.
139
gl_TexCoord[0] = gl_MultiTexCoord0; // for distinguishing the verties of the quad
140
gl_TexCoord[1] = gl_MultiTexCoord1; // for coordinate system within fragment shader (enable unit quad coordinates)
142
// compute texture coordinates from worldspace coordinates for texture access
143
vec3 texturePosition = ( u_WorldTransform * gl_Vertex ).xyz;
144
texturePosition.x /= u_pixelSizeX * u_probTractSizeX;
145
texturePosition.y /= u_pixelSizeY * u_probTractSizeY;
146
texturePosition.z /= u_pixelSizeZ * u_probTractSizeZ;
148
// get connectivity score from probTract and with maximum value scale it between 0.0..1.0. from now on we call it probability
149
probability = texture3D( u_probTractSampler, texturePosition ).r / float( u_maxConnectivityScore );
151
// span quad incase of regions with high probablility
152
if( probability > u_threshold ) // rgb are the same
154
// transform position, the 4th component must be explicitly set, as otherwise they would have been scaled
155
gl_Position = gl_ModelViewProjectionMatrix * ( vec4( gl_TexCoord[0].xyz + gl_Vertex.xyz, 1.0 ) );
159
gl_Position = ftransform(); // discard those vertices
162
// get principal diffusion direction
163
vec3 diffusionDirection = abs( texture3DUnscaled( u_vectorsSampler, texturePosition, u_vectorsMin, u_vectorsScale ).xyz );
164
diffusionDirection = normalize( diffusionDirection );
166
// project into plane (given by two vectors aVec and bVec)
167
vec3 normal = normalize( cross( u_aVec, u_bVec ) );
168
vec3 projectedDirection = diffusionDirection - dot( diffusionDirection, normal ) * normal;
170
vec3 projectedDirectionTextCoords = 0.5 * vec3( dot( normalize( u_aVec ), projectedDirection ),
171
dot( normalize( u_bVec ), projectedDirection ),
173
scaledFocalPoint1 = middlePoint_tex + scale * projectedDirectionTextCoords;
174
scaledFocalPoint2 = middlePoint_tex - scale * projectedDirectionTextCoords;
175
// but scale directions to fit 1x1 unit square, these 0.8 are just arbitrary choosen
176
focalPoint1 = middlePoint_tex + projectedDirectionTextCoords;
177
focalPoint2 = middlePoint_tex - projectedDirectionTextCoords;