WMNavigationSlices-fragment.glsl 2.46 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 25 26 27 28
//---------------------------------------------------------------------------
//
// 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/>.
//
//---------------------------------------------------------------------------

#version 120

#include "WGEColormapping-fragment.glsl"

29 30 31 32 33 34 35 36 37
// this color is used if currently picking the slice
const vec4 pickColor = vec4( 0.25, 0.0, 0.75, 1.0 );

// if this is 1, the slice is currently in pick mode
uniform float u_picked;

// animation time. Used for pick-animation
uniform int u_timer;

38 39 40
// if true, no transparency should be used.
uniform bool u_noTransparency;

41 42 43 44 45
/**
 * Applies colormapping.
 */
void main()
{
46
    // get the colormap
47
    vec4 cmap = colormapping();
48 49 50 51 52

    // this creates a sinuidal blending in [0,1] with one complete 2pi cycle per second
    // NOTE: the 100.0 depends on the timer tick. We have a timer that counts one per a hundreth of a second.
    float pickColorIntensity = 0.5 * ( 1.0 + sin( 3.0 * 3.1472 * float( u_timer ) / 100.0 ) );
    // as we use this for blending, we want it to swing in [0.5-0.75]
53 54 55 56 57
    pickColorIntensity = ( pickColorIntensity * 0.25 ) + 0.5;

    // remove transparency?
    float removeTransparency = clamp( u_picked + float( u_noTransparency ), 0.0, 1.0 );
    cmap.a = ( ( 1.0 - removeTransparency ) * cmap.a ) + removeTransparency;
58 59

    // mix colormapping and pick color
60 61 62 63 64 65
    vec4 finalColor = mix( pickColor, cmap,
                           ( 1.0 - u_picked ) + ( u_picked * pickColorIntensity ) // mix intensity. This is influenced by the pick-state.
                         );

    // set as fragColor and remove transparency if needed.
    gl_FragColor = vec4( finalColor.rgba );
66 67
}