1//VTK::System::Dec
2
3//=========================================================================
4//
5//  Program:   Visualization Toolkit
6//  Module:    vtkLineIntegralConvolution2D_LIC0.glsl
7//
8//  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
9//  All rights reserved.
10//  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
11//
12//     This software is distributed WITHOUT ANY WARRANTY; without even
13//     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14//     PURPOSE.  See the above copyright notice for more information.
15//
16//=========================================================================
17
18/**
19This shader initializes the convolution for the LIC computation.
20*/
21
22// the output of this shader
23//VTK::Output::Dec
24
25uniform sampler2D texMaskVectors;
26uniform sampler2D texNoise;
27uniform sampler2D texLIC;
28
29uniform int   uStepNo;         // in step 0 initialize lic and seeds, else just seeds
30uniform int   uPassNo;         // in pass 1 hpf of pass 0 is convolved.
31uniform float uMaskThreshold;  // if |V| < uMaskThreshold render transparent
32uniform vec2  uNoiseBoundsPt1; // tc of upper right pt of noise texture
33
34in vec2 tcoordVC;
35
36// convert from vector coordinate space to noise coordinate space.
37// the noise texture is tiled across the *whole* domain
38vec2 VectorTCToNoiseTC(vec2 vectc)
39{
40  return vectc/uNoiseBoundsPt1;
41}
42
43// get the texture coordidnate to lookup noise value. this
44// depends on the pass number.
45vec2 getNoiseTC(vec2 vectc)
46{
47  // in pass 1 : convert from vector tc to noise tc
48  // in pass 2 : use vector tc
49  if (uPassNo == 0)
50    {
51    return VectorTCToNoiseTC(vectc);
52    }
53  else
54    {
55    return vectc;
56    }
57}
58
59// look up noise value at the given location. The location
60// is supplied in vector texture coordinates, hence the
61// need to convert to noise texture coordinates.
62float getNoise(vec2 vectc)
63{
64  return texture2D(texNoise, getNoiseTC(vectc)).r;
65}
66
67void main(void)
68{
69  vec2 vectc = tcoordVC.st;
70
71  // lic => (convolution, mask, 0, step count)
72  if (uStepNo == 0)
73    {
74    float maskCriteria = length(texture2D(texMaskVectors, vectc).xyz);
75    float maskFlag;
76    if (maskCriteria <= uMaskThreshold)
77      {
78      maskFlag = 1.0;
79      }
80    else
81      {
82      maskFlag = 0.0;
83      }
84    float noise = getNoise(vectc);
85    gl_FragData[0] = vec4(noise, maskFlag, 0.0, 1.0);
86    }
87  else
88    {
89    gl_FragData[0] = texture2D(texLIC, vectc);
90    }
91
92  // initial seed
93  gl_FragData[1] = vec4(vectc, 0.0, 1.0);
94}
95