vtkLineIntegralConvolution2D_EE.glsl 2.19 KB
Newer Older
1 2
//VTK::System::Dec

Ken Martin's avatar
Ken Martin committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
//=========================================================================
//
//  Program:   Visualization Toolkit
//  Module:    vtkLineIntegralConvolution2D_fs2.glsl
//
//  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
//  All rights reserved.
//  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
//
//     This software is distributed WITHOUT ANY WARRANTY; without even
//     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
//     PURPOSE.  See the above copyright notice for more information.
//
//=========================================================================

// high-pass filter stage employed by vtkLineIntegralConvolution2D
// between LIC pass 1 and LIC pass 2. filtered LIC pass 1, becomes
// noise for pass2.

22 23 24
// the output of this shader
//VTK::Output::Dec

Ken Martin's avatar
Ken Martin committed
25 26 27 28
uniform sampler2D texLIC; // most recent lic pass
uniform float     uDx;    // fragment size
uniform float     uDy;    // fragment size

29
in vec2 tcoordVC;
Ken Martin's avatar
Ken Martin committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

// kernel for simple laplace edge enhancement.
// p=Laplace(p)+p
float K[9] = float[9](
  -1.0, -1.0, -1.0,
  -1.0,  9.0, -1.0,
  -1.0, -1.0, -1.0
  );

// tex coord neighbor offsets
vec2 fragDx[9] = vec2[9](
  vec2(-uDx, uDy), vec2(0.0, uDy), vec2(uDx, uDy),
  vec2(-uDx, 0.0), vec2(0.0, 0.0), vec2(uDx, 0.0),
  vec2(-uDx,-uDy), vec2(0.0,-uDy), vec2(uDx,-uDy)
  );

// determine if the fragment was masked
bool Masked(float val) { return val != 0.0; }

void main(void)
{
  vec2 lictc = tcoordVC.st;

  // compute the convolution but don't use convovled values if
  // any masked fragments on the stencil. Fragments outside
luz.paz's avatar
luz.paz committed
55
  // the valid domain are masked during initialization, and
Ken Martin's avatar
Ken Martin committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69
  // texture wrap parameters are clamp to border with border
  // color that contains masked flag
  float conv = 0.0;
  bool dontUse = false;
  for (int i=0; i<9; ++i)
    {
    vec2 tc = lictc + fragDx[i];
    vec4 lic = texture2D(texLIC, tc);
    dontUse = dontUse || Masked(lic.g);
    conv = conv + K[i] * lic.r;
    }

  if (dontUse)
    {
70
    gl_FragData[0] = vec4(texture2D(texLIC, lictc).rg, 0.0, 1.0);
Ken Martin's avatar
Ken Martin committed
71 72 73 74
    }
  else
    {
    conv = clamp(conv, 0.0, 1.0);
75
    gl_FragData[0] = vec4(conv,texture2D(texLIC, lictc).g, 0.0, 1.0);
Ken Martin's avatar
Ken Martin committed
76 77 78
    }

}