~ubuntu-branches/ubuntu/raring/openwalnut/raring

« back to all changes in this revision

Viewing changes to src/modules/fiberStipples/shaders/WFiberStipples-vertex.glsl

  • Committer: Package Import Robot
  • Author(s): Sebastian Eichelbaum
  • Date: 2012-12-12 11:26:32 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20121212112632-xhiuwkxuz5h0idkh
Tags: 1.3.1+hg5849-1
* Minor changes compared to 1.3.0 but included several bug fixes.
* See http://www.openwalnut.org/versions/4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//---------------------------------------------------------------------------
 
2
//
 
3
// Project: OpenWalnut ( http://www.openwalnut.org )
 
4
//
 
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
 
6
// For more information see http://www.openwalnut.org/copying
 
7
//
 
8
// This file is part of OpenWalnut.
 
9
//
 
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.
 
14
//
 
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.
 
19
//
 
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/>.
 
22
//
 
23
//---------------------------------------------------------------------------
 
24
 
 
25
#version 120
 
26
 
 
27
#include "WGETextureTools.glsl"
 
28
 
 
29
/**
 
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).
 
33
 */
 
34
uniform float u_vectorsMin; uniform float u_vectorsScale;
 
35
 
 
36
/**
 
37
 * The matrix describes the transformation of gl_Vertex to OpenWalnut Scene Space
 
38
 */
 
39
uniform mat4 u_WorldTransform;
 
40
 
 
41
/**
 
42
 * Vector dataset as texture.
 
43
 */
 
44
uniform sampler3D u_vectorsSampler;
 
45
 
 
46
/**
 
47
 * Probabilistic tract as texture.
 
48
 */
 
49
uniform sampler3D u_probTractSampler;
 
50
 
 
51
/**
 
52
 * Number of voxels in X direction.
 
53
 */
 
54
uniform int u_probTractSizeX;
 
55
 
 
56
/**
 
57
 * Number of voxels in Y direction.
 
58
 */
 
59
uniform int u_probTractSizeY;
 
60
 
 
61
/**
 
62
 * Number of voxels in Z direction.
 
63
 */
 
64
uniform int u_probTractSizeZ;
 
65
 
 
66
// For correct transformation into texture space we also need the size of each voxel.
 
67
/**
 
68
 * Voxel size in X direction.
 
69
 */
 
70
uniform float u_pixelSizeX;
 
71
 
 
72
/**
 
73
 * Voxel size in Y direction.
 
74
 */
 
75
uniform float u_pixelSizeY;
 
76
 
 
77
/**
 
78
 * Voxel size in Z direction.
 
79
 */
 
80
uniform float u_pixelSizeZ;
 
81
 
 
82
// vectors spanning the plane of the quad
 
83
uniform vec3 u_aVec;
 
84
uniform vec3 u_bVec;
 
85
 
 
86
/**
 
87
 * First focal point, which is one of the endings of the projected diffusion direction.
 
88
 */
 
89
varying vec3 focalPoint1;
 
90
 
 
91
/**
 
92
 * Second focal point, which is one of the endings of the projected diffusion direction.
 
93
 */
 
94
varying vec3 focalPoint2;
 
95
 
 
96
// Scaled focal points, as otherwise the the stipple endings may not fit inside quad.
 
97
/**
 
98
 * Fixed factor for scaling.
 
99
 */
 
100
uniform float scale = 0.8;
 
101
 
 
102
/**
 
103
 * First focal point, scaled.
 
104
 */
 
105
varying vec3 scaledFocalPoint1;
 
106
 
 
107
/**
 
108
 * Second focal poin, scaled.
 
109
 */
 
110
varying vec3 scaledFocalPoint2;
 
111
 
 
112
/**
 
113
 * Maximum connectivity score withing the probabilistic tract dataset. This is
 
114
 * needed for scaling the connectivities between 0.0 and 1.0.
 
115
 */
 
116
uniform float u_maxConnectivityScore;
 
117
 
 
118
/**
 
119
 * Scaled connectivity score; now between 0.0...1.0.
 
120
 */
 
121
varying float probability;
 
122
 
 
123
/**
 
124
 * Probabilities below this threshold are ignored and discarded.
 
125
 */
 
126
uniform float u_threshold;
 
127
 
 
128
/**
 
129
 * Middle point of the quad in texture coordinates, needed for scaling the
 
130
 * projection of the principal diffusion direction to fit inside quad.
 
131
 */
 
132
uniform vec3 middlePoint_tex = vec3( 0.5, 0.5, 0.0 );
 
133
 
 
134
/**
 
135
 * Vertex Main. Simply transforms the geometry. The work is done per fragment.
 
136
 */
 
137
void main()
 
138
{
 
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)
 
141
 
 
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;
 
147
 
 
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 );
 
150
 
 
151
    // span quad incase of regions with high probablility
 
152
    if( probability > u_threshold ) // rgb are the same
 
153
    {
 
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 ) );
 
156
    }
 
157
    else
 
158
    {
 
159
         gl_Position = ftransform(); // discard those vertices
 
160
    }
 
161
 
 
162
    // get principal diffusion direction
 
163
    vec3 diffusionDirection = abs( texture3DUnscaled( u_vectorsSampler, texturePosition, u_vectorsMin, u_vectorsScale ).xyz );
 
164
    diffusionDirection = normalize( diffusionDirection );
 
165
 
 
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;
 
169
 
 
170
    vec3 projectedDirectionTextCoords = 0.5 * vec3( dot( normalize( u_aVec ), projectedDirection ),
 
171
                                                    dot( normalize( u_bVec ), projectedDirection ),
 
172
                                                    0.0 );
 
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;
 
178
}