WMNavSlices-fragment.glsl 4.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

25
varying vec4 VaryingTexCoord0;
26 27 28 29 30 31 32
varying vec4 VaryingTexCoord1;
varying vec4 VaryingTexCoord2;
varying vec4 VaryingTexCoord3;
varying vec4 VaryingTexCoord4;
varying vec4 VaryingTexCoord5;
varying vec4 VaryingTexCoord6;
varying vec4 VaryingTexCoord7;
33

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
uniform sampler3D tex0;
uniform sampler3D tex1;
uniform sampler3D tex2;
uniform sampler3D tex3;
uniform sampler3D tex4;
uniform sampler3D tex5;
uniform sampler3D tex6;
uniform sampler3D tex7;

uniform float threshold0;
uniform float threshold1;
uniform float threshold2;
uniform float threshold3;
uniform float threshold4;
uniform float threshold5;
uniform float threshold6;
uniform float threshold7;
51

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
uniform int type0;
uniform int type1;
uniform int type2;
uniform int type3;
uniform int type4;
uniform int type5;
uniform int type6;
uniform int type7;

uniform float alpha0;
uniform float alpha1;
uniform float alpha2;
uniform float alpha3;
uniform float alpha4;
uniform float alpha5;
uniform float alpha6;
uniform float alpha7;

70 71 72 73 74 75 76 77 78
uniform int useCmap0;
uniform int useCmap1;
uniform int useCmap2;
uniform int useCmap3;
uniform int useCmap4;
uniform int useCmap5;
uniform int useCmap6;
uniform int useCmap7;

79
uniform bool highlighted;
80
uniform bool showComplete;
81

82

83
#include "WGEColorMaps.glsl"
84 85


86
void lookupTex( inout vec4 col, in int type, in sampler3D tex, in float threshold, in vec3 v, in float alpha, in int cmap )
87
{
88
    vec3 col1 = vec3( 0.0 );
89

90
    col1 = clamp( texture3D( tex, v ).rgb, 0.0, 1.0 );
91

92
    if( ( col1.r + col1.g + col1.b ) / 3.0  - threshold <= 0.0 ) return;
93

94
    if( cmap != 0 )
95
    {
96 97
        if(threshold < 1.0)
        {
98 99
            col1.r = ( col1.r - threshold ) / ( 1.0 - threshold );
            if( ( col1.r + col1.g + col1.b ) / 3.0  - threshold <= 0.0 ) return;
100
        }
101

102
        colorMap( col1, col1.r, cmap );
103 104
    }

105
    col.rgb = mix( col.rgb, col1.rgb, alpha );
106 107
}

108 109
void main()
{
110
    vec4 col = vec4( 0.0, 0.0, 0.0, 1.0 );
111

112 113 114 115 116 117 118 119
    if ( type7 > 0 ) lookupTex( col, type7, tex7, threshold7, VaryingTexCoord7.xyz, alpha7, useCmap7 );
    if ( type6 > 0 ) lookupTex( col, type6, tex6, threshold6, VaryingTexCoord6.xyz, alpha6, useCmap6 );
    if ( type5 > 0 ) lookupTex( col, type5, tex5, threshold5, VaryingTexCoord5.xyz, alpha5, useCmap5 );
    if ( type4 > 0 ) lookupTex( col, type4, tex4, threshold4, VaryingTexCoord4.xyz, alpha4, useCmap4 );
    if ( type3 > 0 ) lookupTex( col, type3, tex3, threshold3, VaryingTexCoord3.xyz, alpha3, useCmap3 );
    if ( type2 > 0 ) lookupTex( col, type2, tex2, threshold2, VaryingTexCoord2.xyz, alpha2, useCmap2 );
    if ( type1 > 0 ) lookupTex( col, type1, tex1, threshold1, VaryingTexCoord1.xyz, alpha1, useCmap1 );
    if ( type0 > 0 ) lookupTex( col, type0, tex0, threshold0, VaryingTexCoord0.xyz, alpha0, useCmap0 );
120

121
    col = clamp( col, 0.0, 1.0 );
122 123

    if ( ( col.r + col.g + col.b ) < 0.01 )
124
    {
125
        if( highlighted && !showComplete )
126
        {
127
            // higlight picked slice in the areas where ther are zero (very small) values
128
            col = vec4( .7, .7, 1, 1 );
129
        }
130 131
        else
        {
132
            if ( !showComplete )
133
            discard;
134 135
        }
    }
136 137

    gl_FragColor = col;
138
}