WMImageSpaceLIC-Transformation-fragment.glsl 4.76 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
//---------------------------------------------------------------------------
//
// 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

27 28
#include "WGEColormapping-fragment.glsl"

29 30 31 32 33
#include "WGEShadingTools.glsl"
#include "WGETextureTools.glsl"
#include "WGETransformationTools.glsl"
#include "WGEUtils.glsl"

34
//#include "WGEColorMaps.glsl"
35

36 37 38 39 40 41
#include "WMImageSpaceLIC-Transformation-varyings.glsl"

/**
 * The texture unit sampler
 */
uniform sampler3D u_texture0Sampler;
42

43 44 45 46 47
/**
 * The texture unit sampler for the 3D noise texture
 */
uniform sampler3D u_texture1Sampler;

48 49 50
/**
 * Scaling factor to unscale the texture
 */
51
uniform float u_texture0Scale = 1.0;
52 53 54 55

/**
 * Smallest possible value in the texture
 */
56
uniform float u_texture0Min = 0.0;
57

58 59 60
/**
 * Size of input texture in pixels
 */
61
uniform int u_texture0SizeX = 255;
62 63 64 65

/**
 * Size of input texture in pixels
 */
66
uniform int u_texture0SizeY = 255;
67 68 69 70

/**
 * Size of input texture in pixels
 */
71
uniform int u_texture0SizeZ = 255;
72

73 74 75 76 77
/**
 * Transforms each vector on each pixel to image space.
 */
void main()
{
78
    vec3 vecProjected;    // contains the final vector at each fragment
79

80 81
    // if we have a 3D noise texture, use it.
#ifdef NOISE3D_ENABLED
82
    float noise3D = texture3D( u_texture1Sampler, gl_TexCoord[0].xyz * v_noiseScaleFactor.xyz ).r;
83 84 85 86
#else
    float noise3D = 1.0;
#endif

87
#ifdef VECTORDATA
88 89
    // get the current vector at this position
    vec3 vec = texture3DUnscaled( u_texture0Sampler, gl_TexCoord[0].xyz, u_texture0Min, u_texture0Scale ).rgb;
90
    vec *= sign( vec.x );
91 92

    // zero length vectors are uninteresting. discard them
93
    if( isZero( length( vec ), 0.01 ) )
94 95 96 97
    {
        discard;
    }

98
    // project the vectors to image space as the input vector is in the tangent space
99
    vecProjected = projectVector( vec ).xyz;
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
100

101 102 103
#endif
#ifdef SCALARDATA

104 105
    // do central differences to get the vector
    // project the vectors to image space
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
106

107 108 109
    float sx = 1.0 / u_texture0SizeX;
    float sy = 1.0 / u_texture0SizeY;
    float sz = 1.0 / u_texture0SizeZ;
110 111 112 113 114 115 116 117 118
    float valueXP = texture3DUnscaled( u_texture0Sampler, gl_TexCoord[0].xyz + vec3( sx, 0.0, 0.0 ), 0.0, 1.0 ).r;
    float valueXM = texture3DUnscaled( u_texture0Sampler, gl_TexCoord[0].xyz - vec3( sx, 0.0, 0.0 ), 0.0, 1.0 ).r;
    float valueYP = texture3DUnscaled( u_texture0Sampler, gl_TexCoord[0].xyz + vec3( 0.0, sy, 0.0 ), 0.0, 1.0 ).r;
    float valueYM = texture3DUnscaled( u_texture0Sampler, gl_TexCoord[0].xyz - vec3( 0.0, sy, 0.0 ), 0.0, 1.0 ).r;
    float valueZP = texture3DUnscaled( u_texture0Sampler, gl_TexCoord[0].xyz + vec3( 0.0, 0.0, sz ), 0.0, 1.0 ).r;
    float valueZM = texture3DUnscaled( u_texture0Sampler, gl_TexCoord[0].xyz - vec3( 0.0, 0.0, sz ), 0.0, 1.0 ).r;

    vec3 vec = vec3( valueXP - valueXM, valueYP - valueYM, valueZP - valueZM );
    vec *= sign( vec.x );
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
119

120
    // zero length vectors are uninteresting. discard them
121
    vecProjected = projectVector( vec ).xyz;
122
    if( isZero( length( vec ), 0.01 ) )
123 124 125 126
    {
        discard;
    }

127
#endif
128

129
    // calculate lighting for the surface
130
    float light = blinnPhongIlluminationIntensity( normalize( v_normal ) );
131

132
    // MPI PAper Hack: {
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
133 134 135
    // vec4 cmap = colormapping();
    // gl_FragData[1] = vec4( vec3( cmap.r ), 1.0 );
    //
136
    // if( cmap.r < 0.15 )
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
137
    //     discard;
138
    // if( isZero( cmap.r - 0.2, 0.1 ) )
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
139
    //     gl_FragData[1] = vec4( 0.25, 0.0, 0.0, 1.0 );
140
    // if( isZero( cmap.r - 0.3, 0.1 ) )
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
141
    //     gl_FragData[1] = vec4( 0.5, 0.0, 0.0, 1.0 );
142
    // if( isZero( cmap.r - 1.0, 0.15 ) )
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
143
    //     gl_FragData[1] = vec4( 1.0, 0.0, 0.0, 1.0 );
144
    // }
145
    gl_FragData[1] = colormapping();
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
146

147 148 149
    // is the vector very orthogonal to the surface? We scale our advection according to this.
    float dotS = abs( dot( v_normal, vec.xyz ) );
    vec2 dotScaled = ( 1.0 - dotS ) * scaleMaxToOne( vecProjected ).xy;
150

151
    gl_FragData[0] = vec4( vec2( 0.5 ) + ( 0.5  * dotScaled ), light, noise3D );
152 153
}