[vtkusers] vtkShadowMapPass and ATI

Paulo Henrique Junqueira Amorim paulojamorim at gmail.com
Thu Apr 14 19:59:22 EDT 2011


Hi,

I'm running the code below in the Ubuntu 10.10 and ATI Radeon HD 3200 video
card.

But does shadow display (Other PC with NVidia is displayed).

The VTK version is from git version 94fe54a6eb6f6a05ada35305f183a073197be743
(Apr. 13)

Regards


*Code:*

from vtk import *

iren = vtkRenderWindowInteractor()

renWin = vtkRenderWindow()
renWin.SetMultiSamples(0)

renWin.SetAlphaBitPlanes(1)
iren.SetRenderWindow(renWin)

renderer = vtkRenderer()
renWin.AddRenderer(renderer)




cameraP = vtkCameraPass()

opaque = vtkOpaquePass()

peeling=vtkDepthPeelingPass()
peeling.SetMaximumNumberOfPeels(200)
peeling.SetOcclusionRatio(0.1)

translucent=vtkTranslucentPass()
peeling.SetTranslucentPass(translucent)

volume=vtkVolumetricPass()
overlay=vtkOverlayPass()
lights=vtkLightsPass()
opaqueSequence=vtkSequencePass()

passes2=vtkRenderPassCollection()
passes2.AddItem(lights)
passes2.AddItem(opaque)

opaqueSequence.SetPasses(passes2)
opaqueCameraPass=vtkCameraPass()
opaqueCameraPass.SetDelegatePass(opaqueSequence)

shadowsBaker=vtkShadowMapBakerPass()
shadowsBaker.SetOpaquePass(opaqueCameraPass)
shadowsBaker.SetResolution(1024)

#To cancel self-shadowing.
shadowsBaker.SetPolygonOffsetFactor(3.1)
shadowsBaker.SetPolygonOffsetUnits(10.0)

shadows=vtkShadowMapPass()
shadows.SetShadowMapBakerPass(shadowsBaker)
shadows.SetOpaquePass(opaqueSequence)

seq=vtkSequencePass()
passes=vtkRenderPassCollection()
passes.AddItem(shadowsBaker)
passes.AddItem(shadows)
passes.AddItem(lights)
passes.AddItem(peeling)
passes.AddItem(volume)
passes.AddItem(overlay)

seq.SetPasses(passes)
cameraP.SetDelegatePass(seq)
renderer.SetPass(cameraP)


stl = vtkSTLReader()
stl.SetFileName('head.stl')
stl.Update()

stlNormals=vtkPolyDataNormals()
stlNormals.SetInputConnection(stl.GetOutputPort())
stlNormals.SetComputePointNormals(0)
stlNormals.SetComputeCellNormals(1)
stlNormals.SetComputePointNormals(0)
stlNormals.Update()

stlMapper=vtkPolyDataMapper()
stlMapper.SetInputConnection(stlNormals.GetOutputPort())
#boxNormals.Delete()
#boxSource.Delete()
stlMapper.SetScalarVisibility(0)

stlActor=vtkActor()

stlKeyProperties=vtkInformation()
stlKeyProperties.Set(vtkShadowMapBakerPass.OCCLUDER(),0) #// dummy val.
stlKeyProperties.Set(vtkShadowMapBakerPass.RECEIVER(),0) #// dummy val.
stlActor.SetPropertyKeys(stlKeyProperties)
stlActor.SetMapper(stlMapper)
stlActor.SetVisibility(1)
stlActor.SetPosition(-2.0,2.0,0.0)
stlActor.GetProperty().SetColor(0.66,0.66,0.66)


#
-------------------------------------------------------------------------------


sphereSource=vtkSphereSource()
sphereSource.SetRadius(1)
sphereSource.SetThetaResolution(32)
sphereSource.SetPhiResolution(32)

sphereMapper=vtkPolyDataMapper()
sphereMapper.SetInputConnection(sphereSource.GetOutputPort())
sphereMapper.SetScalarVisibility(0)

sphereActor=vtkActor()

sphereKeyProperties=vtkInformation()
sphereKeyProperties.Set(vtkShadowMapBakerPass.OCCLUDER(),0) #// dummy val.
sphereKeyProperties.Set(vtkShadowMapBakerPass.RECEIVER(),0) #// dummy val.
sphereActor.SetPropertyKeys(sphereKeyProperties)

sphereActor.SetMapper(sphereMapper)

sphereActor.SetVisibility(1)
b_stl = stlActor.GetBounds()
sphereActor.SetPosition((b_stl[0] + b_stl[1])/2, (b_stl[2] + b_stl[3])/2,
b_stl[5] + 50)
sphereActor.GetProperty().SetColor(1.0,1.0,0.0)

renderer.AddActor(stlActor)
renderer.ResetCamera()

renderer.AddActor(sphereActor)

#lighting the sphere
l2=vtkLight()

s_pos = sphereActor.GetPosition()
l2.SetPosition(s_pos[0], s_pos[1], s_pos[2] + 100)
l2.SetFocalPoint(sphereActor.GetPosition())
l2.SetColor(0.5,0.5,0.5)
l2.SetPositional(1)

renderer.AddLight(l2)
l2.SetSwitch(1)

renderer.SetBackground(0.66,0.66,0.66)


renderer.SetGradientBackground(True)
renWin.SetSize(1000,1000)
renWin.Render()

camera=renderer.GetActiveCamera()
camera.Azimuth(40.0)
camera.Elevation(10.0)

camera.SetPosition(s_pos[0] + 50, s_pos[1], s_pos[2] + 100)

renderer.Render()
renWin.Render()
iren.Start()


*Error log:*

ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line
497
vtkShaderProgram2 (0x36bf250):  a shader failed to compile. Its log is:
Vertex shader failed to compile with the following errors:
ERROR: 0:19: error(#105) #version must occur before any other statement in
the program
ERROR: error(#273) 1 compilation errors.  No code generated

. Its source code is:
#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1
//
============================================================================
//
//  Program:   Visualization Toolkit
//  Module:    vtkShadowMapPassShader_vs.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.
//
//
============================================================================

// Vertex shader used by the shadow mapping render pass.

#version 110

// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by
adding
// a line at the beginning like:
// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing
// lights.


void propFuncVS();

// defined in vtkLighting_s.glsl

void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,
                                gl_MaterialParameters m,
                                vec3 surfacePosEyeCoords,
                                vec3 n,
                                bool twoSided,
                                inout vec4 cpri,
                                inout vec4 csec);

void initBlackColors(out vec4 cpri,
                     out vec4 csec);


// input are
// uniform gl_TextureMatrix[VTK_LIGHTING_NUMBER_OF_LIGHTS];

varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];
varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];

void main(void)
{
  vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;
  vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;
  vec3 n=gl_NormalMatrix*gl_Normal;
  n=normalize(n);

  int i=0;
  while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
    {
    vec4 cpri;
    vec4 csec;
    initBlackColors(cpri,csec); // because ambient in previous pass.


lightSeparateSpecularColor(gl_LightSource[i],gl_FrontMaterial,eyeCoords,n,
                               false,cpri,csec);
//    frontColors[i]=vec4(0.5,0.5,0.5,1.0); // cpri+csec;

//    frontColors[i]=gl_FrontMaterial.diffuse*gl_LightSource[i].diffuse;

    frontColors[i]=cpri; //+csec;

    // we could have everything in just gl_TextureMatrix[i] but this would
    // require to add code vtkOpenGLActor. Also the value of the uniform
    // gl_TextureMatrix[i] would have to be changed on each actor.
    // gl_TextureMatrix[i] would be:
    // scale_bias*projection_light[i]*view_light[i]*model
    // and we would have just texCoord=gl_TextureMatrix[i]*gl_Vertex;
    //
    // gl_TextureMatrix[i] is actually:
    // scale_bias*projection_light[i]*view_light[i]*view_camera_inv

    vec4 texCoord=gl_TextureMatrix[i]*heyeCoords;
    shadowCoord[i]=texCoord/texCoord.w;
    ++i;
    }

  // we have to use the fixed-pipeline transform to avoid mismatching with
  // other passes.
  gl_Position=ftransform();

  // propFuncVS(); // opportunity for the prop to execute its vertex shader.



  // we don't initialize gl_FrontColor because we have an array of colors
  // in frontColors[].
}




ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line
497
vtkShaderProgram2 (0x36bf250):  a shader failed to compile. Its log is:
Vertex shader failed to compile with the following errors:
ERROR: 0:20: error(#105) #version must occur before any other statement in
the program
ERROR: error(#273) 1 compilation errors.  No code generated

. Its source code is:
#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1
//
============================================================================
//
//  Program:   Visualization Toolkit
//  Module:    vtkLighting_s.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.
//
//
============================================================================

// This file defines some lighting functions.
// They can be used either in a vertex or fragment shader.

#version 110

// Example in vertex shader:
// Reminder: two-sided/one-sided is controlled by GL_VERTEX_PROGRAM_TWO_SIDE
//
// vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;
// vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;
// vec3 n=gl_Normalmatrix*gl_Normal;
// n=normalize(n);
//
separateSpecularColor(gl_FrontMaterial,eyeCoords,n,gl_FrontColor,gl_FrontSecondaryColor);
 // If two-sided.
//
separateSpecularColor(gl_BackMaterial,eyeCoords,n,gl_BackColor,gl_BackSecondaryColor);

 // Typical:
// gl_FrontColor=singleColor(gl_FrontMaterial,eyeCoords,n);

// VTK_LIGHTING_NUMBER_OF_LIGHTS has to be defined (by shader source string
// concatenation) to be the number of lights on, contiguous from 0 to
// VTK_LIGHTING_NUMBER_OF_LIGHTS-1
// it has to be less than gl_MaxLights (typically 8)

// Per light computation
// (it means the scene ambient term is missing).
// lightSource is usually as gl_LightSource[i]
void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,
                                gl_MaterialParameters m,
                                vec3 surfacePosEyeCoords,
                                vec3 n,
                                bool twoSided,
                                inout vec4 cpri,
                                inout vec4 csec)
{
  vec3 ldir;
  vec3 h;
  float att;
  float spot;
  float shininessFactor;
  vec3 wReverseRayDir=surfacePosEyeCoords;

  if(lightSource.position.w!=0.0)
    {
    // ldir=light direction
    vec3 lightPos=lightSource.position.xyz/lightSource.position.w;
    ldir=lightPos-surfacePosEyeCoords;
    float sqrDistance=dot(ldir,ldir);
    ldir=normalize(ldir);
    h=normalize(ldir+normalize(wReverseRayDir));

att=1.0/(lightSource.constantAttenuation+lightSource.linearAttenuation*sqrt(sqrDistance)+lightSource.quadraticAttenuation*sqrDistance);
    // USED
    }
  else
    {
    att=1.0;
    ldir=lightSource.position.xyz;
    ldir=normalize(ldir);
    h=normalize(ldir+wReverseRayDir);
    }

  if(att>0.0)
    {
    // USED
    if(lightSource.spotCutoff==180.0)
      {
      spot=1.0;
      // NOT USED
      }
    else
      {
      // USED

      float coef=-dot(ldir,normalize(lightSource.spotDirection));
      if(coef>=lightSource.spotCosCutoff)
        {
        spot=pow(coef,lightSource.spotExponent);
        // USED
        }
      else
        {
        spot=0.0;
        // NOT USED
        }
      }
    if(spot>0.0)
      {
      // USED

      // LIT operation...
      float nDotL=dot(n,ldir);
      float nDotH=dot(n,h);

      // separate nDotL and nDotH for two-sided shading, otherwise we
      // get black spots.

      if(nDotL<0.0) // two-sided shading
        {
//        nDotL=-nDotL; // mostly NOT USED
        nDotL=0.0;
        }

      if(nDotH<0.0) // two-sided shading
        {
//        nDotH=-nDotH; // mostly USED, except on the back face of the
plane.
        nDotH=0.0;
        }

      // ambient term for this light
      vec4 cpril=m.ambient*lightSource.ambient;// acm*adi

//      cpri=cpril;
//      return;

      // diffuse term for this light
      if(nDotL>0.0)
        {
        // USED
        cpril+=m.diffuse*lightSource.diffuse*nDotL; // dcm*dcli
        }


      // specular term for this light
      shininessFactor=pow(nDotH,m.shininess); // srm

      cpri+=att*spot*cpril;

      // scm*scli
      csec+=att*spot*
        m.specular*lightSource.specular*shininessFactor;

      }
    }
}

// Ignore Scene ambient. Useful in multipass, if the ambient was already
// taken into account in a previous pass.
void initBlackColors(out vec4 cpri,
                     out vec4 csec)
{
  cpri=vec4(0.0,0.0,0.0,1.0);
  csec=vec4(0.0,0.0,0.0,1.0);
}

void initColorsWithAmbient(gl_MaterialParameters m,
                           out vec4 cpri,
                           out vec4 csec)
{
  cpri=m.emission+m.ambient*gl_LightModel.ambient; // ecm+acm*acs
  csec=vec4(0.0,0.0,0.0,1.0);
}

#ifdef VTK_LIGHTING_NUMBER_OF_LIGHTS

// This is convenience method to use in shader but you better do
// this computation on the CPU and send the result as a uniform.

// True if any enabled light is a positional one.
bool needSurfacePositionInEyeCoordinates()
{
 int i=0;
 bool result=false;
 while(!result && i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
  {
   result=gl_LightSource[i].position.w!=0.0;
   ++i;
  }
 return result;
}

// Lighting computation based on a material m,
// a position on the surface expressed in eye coordinate (typically a vertex
//  position in a vertex shader, something interpolated in a fragment
shader),
// a unit normal `n' to the surface in eye coordinates.
// Most of the components are in cpri (primary color), the specular
// component is in csec (secondary color).
// Useful for blending color and textures.
void separateSpecularColor(gl_MaterialParameters m,
                           vec3 surfacePosEyeCoords,
                           vec3 n,
                           bool twoSided,
                           out vec4 cpri,
                           out vec4 csec)
{
  initColorsWithAmbient(m,cpri,csec);

  // For each light,
  int i=0;
  while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
    {
    lightSeparateSpecularColor(gl_LightSource[i],m,surfacePosEyeCoords,n,
                               twoSided,cpri,csec);
    ++i;
    }
}

// Lighting computation based on a material m,
// a position on the surface expressed in eye coordinate (typically a vertex
//  position in a vertex shader, something interpolated in a fragment
shader),
// a unit normal to the surface in eye coordinates.
// The result includes the specular component.
vec4 singleColor(gl_MaterialParameters m,
                 vec3 surfacePosEyeCoords,
                 vec3 n,
                 bool twoSided)
{
  vec4 cpri;
  vec4 csec;
  separateSpecularColor(m,surfacePosEyeCoords,n,twoSided,cpri,csec);
  return cpri+csec;
}

#endif




ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line
497
vtkShaderProgram2 (0x36bf250):  a shader failed to compile. Its log is:
Fragment shader failed to compile with the following errors:
ERROR: 0:19: error(#105) #version must occur before any other statement in
the program
ERROR: error(#273) 1 compilation errors.  No code generated

. Its source code is:
#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1
//
============================================================================
//
//  Program:   Visualization Toolkit
//  Module:    vtkShadowMapPassShader_fs.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.
//
//
============================================================================

// Fragment shader used by the shadow mapping render pass.

#version 110

// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by
adding
// a line at the beginning like:
// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing
// lights.

uniform sampler2DShadow shadowMaps[VTK_LIGHTING_NUMBER_OF_LIGHTS];
uniform sampler2D spotLightShape;

varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];
varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];

void main(void)
{
  gl_FragColor=vec4(0.0,0.0,0.0,0.0);
  int i=0;
  while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
    {
    float factor=0.0;
    if(shadowCoord[i].w>0.0)
      {
      vec2 projected=shadowCoord[i].xy/shadowCoord[i].w;
      if(projected.x>=0.0 && projected.x<=1.0
        && projected.y>=0.0 && projected.y<=1.0)
        {
        factor=shadow2DProj(shadowMaps[i],shadowCoord[i]).x;
        }
      }
    vec4 colorFactor=texture2DProj(spotLightShape,shadowCoord[i])*factor;
    gl_FragColor+=frontColors[i]*colorFactor.x;
//    gl_FragColor+=frontColors[i]*factor;
    ++i;
    }

  gl_FragColor=clamp(gl_FragColor,0.0,1.0);

  // we don't let the prop to execute its fragment shader because it
  // already executed in the previous pass with none shadowing lights.
  //  propFuncFS();

  // gl_FragColor will be blending with framebuffer value containing other
  // lights contributions.
  // use alpha_testing for black/dark color?
}




ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkOpenGLProperty.cxx, line
393
vtkOpenGLProperty (0x2b47e00): Couldn't build the shader program. At this
point , it can be an error in a shader or a driver bug.


ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line
497
vtkShaderProgram2 (0x36bf250):  a shader failed to compile. Its log is:
Vertex shader failed to compile with the following errors:
ERROR: 0:19: error(#105) #version must occur before any other statement in
the program
ERROR: error(#273) 1 compilation errors.  No code generated

. Its source code is:
#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1
//
============================================================================
//
//  Program:   Visualization Toolkit
//  Module:    vtkShadowMapPassShader_vs.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.
//
//
============================================================================

// Vertex shader used by the shadow mapping render pass.

#version 110

// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by
adding
// a line at the beginning like:
// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing
// lights.


void propFuncVS();

// defined in vtkLighting_s.glsl

void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,
                                gl_MaterialParameters m,
                                vec3 surfacePosEyeCoords,
                                vec3 n,
                                bool twoSided,
                                inout vec4 cpri,
                                inout vec4 csec);

void initBlackColors(out vec4 cpri,
                     out vec4 csec);


// input are
// uniform gl_TextureMatrix[VTK_LIGHTING_NUMBER_OF_LIGHTS];

varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];
varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];

void main(void)
{
  vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;
  vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;
  vec3 n=gl_NormalMatrix*gl_Normal;
  n=normalize(n);

  int i=0;
  while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
    {
    vec4 cpri;
    vec4 csec;
    initBlackColors(cpri,csec); // because ambient in previous pass.


lightSeparateSpecularColor(gl_LightSource[i],gl_FrontMaterial,eyeCoords,n,
                               false,cpri,csec);
//    frontColors[i]=vec4(0.5,0.5,0.5,1.0); // cpri+csec;

//    frontColors[i]=gl_FrontMaterial.diffuse*gl_LightSource[i].diffuse;

    frontColors[i]=cpri; //+csec;

    // we could have everything in just gl_TextureMatrix[i] but this would
    // require to add code vtkOpenGLActor. Also the value of the uniform
    // gl_TextureMatrix[i] would have to be changed on each actor.
    // gl_TextureMatrix[i] would be:
    // scale_bias*projection_light[i]*view_light[i]*model
    // and we would have just texCoord=gl_TextureMatrix[i]*gl_Vertex;
    //
    // gl_TextureMatrix[i] is actually:
    // scale_bias*projection_light[i]*view_light[i]*view_camera_inv

    vec4 texCoord=gl_TextureMatrix[i]*heyeCoords;
    shadowCoord[i]=texCoord/texCoord.w;
    ++i;
    }

  // we have to use the fixed-pipeline transform to avoid mismatching with
  // other passes.
  gl_Position=ftransform();

  // propFuncVS(); // opportunity for the prop to execute its vertex shader.



  // we don't initialize gl_FrontColor because we have an array of colors
  // in frontColors[].
}




ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line
497
vtkShaderProgram2 (0x36bf250):  a shader failed to compile. Its log is:
Vertex shader failed to compile with the following errors:
ERROR: 0:20: error(#105) #version must occur before any other statement in
the program
ERROR: error(#273) 1 compilation errors.  No code generated

. Its source code is:
#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1
//
============================================================================
//
//  Program:   Visualization Toolkit
//  Module:    vtkLighting_s.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.
//
//
============================================================================

// This file defines some lighting functions.
// They can be used either in a vertex or fragment shader.

#version 110

// Example in vertex shader:
// Reminder: two-sided/one-sided is controlled by GL_VERTEX_PROGRAM_TWO_SIDE
//
// vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;
// vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;
// vec3 n=gl_Normalmatrix*gl_Normal;
// n=normalize(n);
//
separateSpecularColor(gl_FrontMaterial,eyeCoords,n,gl_FrontColor,gl_FrontSecondaryColor);
 // If two-sided.
//
separateSpecularColor(gl_BackMaterial,eyeCoords,n,gl_BackColor,gl_BackSecondaryColor);

 // Typical:
// gl_FrontColor=singleColor(gl_FrontMaterial,eyeCoords,n);

// VTK_LIGHTING_NUMBER_OF_LIGHTS has to be defined (by shader source string
// concatenation) to be the number of lights on, contiguous from 0 to
// VTK_LIGHTING_NUMBER_OF_LIGHTS-1
// it has to be less than gl_MaxLights (typically 8)

// Per light computation
// (it means the scene ambient term is missing).
// lightSource is usually as gl_LightSource[i]
void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,
                                gl_MaterialParameters m,
                                vec3 surfacePosEyeCoords,
                                vec3 n,
                                bool twoSided,
                                inout vec4 cpri,
                                inout vec4 csec)
{
  vec3 ldir;
  vec3 h;
  float att;
  float spot;
  float shininessFactor;
  vec3 wReverseRayDir=surfacePosEyeCoords;

  if(lightSource.position.w!=0.0)
    {
    // ldir=light direction
    vec3 lightPos=lightSource.position.xyz/lightSource.position.w;
    ldir=lightPos-surfacePosEyeCoords;
    float sqrDistance=dot(ldir,ldir);
    ldir=normalize(ldir);
    h=normalize(ldir+normalize(wReverseRayDir));

att=1.0/(lightSource.constantAttenuation+lightSource.linearAttenuation*sqrt(sqrDistance)+lightSource.quadraticAttenuation*sqrDistance);
    // USED
    }
  else
    {
    att=1.0;
    ldir=lightSource.position.xyz;
    ldir=normalize(ldir);
    h=normalize(ldir+wReverseRayDir);
    }

  if(att>0.0)
    {
    // USED
    if(lightSource.spotCutoff==180.0)
      {
      spot=1.0;
      // NOT USED
      }
    else
      {
      // USED

      float coef=-dot(ldir,normalize(lightSource.spotDirection));
      if(coef>=lightSource.spotCosCutoff)
        {
        spot=pow(coef,lightSource.spotExponent);
        // USED
        }
      else
        {
        spot=0.0;
        // NOT USED
        }
      }
    if(spot>0.0)
      {
      // USED

      // LIT operation...
      float nDotL=dot(n,ldir);
      float nDotH=dot(n,h);

      // separate nDotL and nDotH for two-sided shading, otherwise we
      // get black spots.

      if(nDotL<0.0) // two-sided shading
        {
//        nDotL=-nDotL; // mostly NOT USED
        nDotL=0.0;
        }

      if(nDotH<0.0) // two-sided shading
        {
//        nDotH=-nDotH; // mostly USED, except on the back face of the
plane.
        nDotH=0.0;
        }

      // ambient term for this light
      vec4 cpril=m.ambient*lightSource.ambient;// acm*adi

//      cpri=cpril;
//      return;

      // diffuse term for this light
      if(nDotL>0.0)
        {
        // USED
        cpril+=m.diffuse*lightSource.diffuse*nDotL; // dcm*dcli
        }


      // specular term for this light
      shininessFactor=pow(nDotH,m.shininess); // srm

      cpri+=att*spot*cpril;

      // scm*scli
      csec+=att*spot*
        m.specular*lightSource.specular*shininessFactor;

      }
    }
}

// Ignore Scene ambient. Useful in multipass, if the ambient was already
// taken into account in a previous pass.
void initBlackColors(out vec4 cpri,
                     out vec4 csec)
{
  cpri=vec4(0.0,0.0,0.0,1.0);
  csec=vec4(0.0,0.0,0.0,1.0);
}

void initColorsWithAmbient(gl_MaterialParameters m,
                           out vec4 cpri,
                           out vec4 csec)
{
  cpri=m.emission+m.ambient*gl_LightModel.ambient; // ecm+acm*acs
  csec=vec4(0.0,0.0,0.0,1.0);
}

#ifdef VTK_LIGHTING_NUMBER_OF_LIGHTS

// This is convenience method to use in shader but you better do
// this computation on the CPU and send the result as a uniform.

// True if any enabled light is a positional one.
bool needSurfacePositionInEyeCoordinates()
{
 int i=0;
 bool result=false;
 while(!result && i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
  {
   result=gl_LightSource[i].position.w!=0.0;
   ++i;
  }
 return result;
}

// Lighting computation based on a material m,
// a position on the surface expressed in eye coordinate (typically a vertex
//  position in a vertex shader, something interpolated in a fragment
shader),
// a unit normal `n' to the surface in eye coordinates.
// Most of the components are in cpri (primary color), the specular
// component is in csec (secondary color).
// Useful for blending color and textures.
void separateSpecularColor(gl_MaterialParameters m,
                           vec3 surfacePosEyeCoords,
                           vec3 n,
                           bool twoSided,
                           out vec4 cpri,
                           out vec4 csec)
{
  initColorsWithAmbient(m,cpri,csec);

  // For each light,
  int i=0;
  while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
    {
    lightSeparateSpecularColor(gl_LightSource[i],m,surfacePosEyeCoords,n,
                               twoSided,cpri,csec);
    ++i;
    }
}

// Lighting computation based on a material m,
// a position on the surface expressed in eye coordinate (typically a vertex
//  position in a vertex shader, something interpolated in a fragment
shader),
// a unit normal to the surface in eye coordinates.
// The result includes the specular component.
vec4 singleColor(gl_MaterialParameters m,
                 vec3 surfacePosEyeCoords,
                 vec3 n,
                 bool twoSided)
{
  vec4 cpri;
  vec4 csec;
  separateSpecularColor(m,surfacePosEyeCoords,n,twoSided,cpri,csec);
  return cpri+csec;
}

#endif




ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line
497
vtkShaderProgram2 (0x36bf250):  a shader failed to compile. Its log is:
Fragment shader failed to compile with the following errors:
ERROR: 0:19: error(#105) #version must occur before any other statement in
the program
ERROR: error(#273) 1 compilation errors.  No code generated

. Its source code is:
#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1
//
============================================================================
//
//  Program:   Visualization Toolkit
//  Module:    vtkShadowMapPassShader_fs.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.
//
//
============================================================================

// Fragment shader used by the shadow mapping render pass.

#version 110

// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by
adding
// a line at the beginning like:
// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing
// lights.

uniform sampler2DShadow shadowMaps[VTK_LIGHTING_NUMBER_OF_LIGHTS];
uniform sampler2D spotLightShape;

varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];
varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];

void main(void)
{
  gl_FragColor=vec4(0.0,0.0,0.0,0.0);
  int i=0;
  while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
    {
    float factor=0.0;
    if(shadowCoord[i].w>0.0)
      {
      vec2 projected=shadowCoord[i].xy/shadowCoord[i].w;
      if(projected.x>=0.0 && projected.x<=1.0
        && projected.y>=0.0 && projected.y<=1.0)
        {
        factor=shadow2DProj(shadowMaps[i],shadowCoord[i]).x;
        }
      }
    vec4 colorFactor=texture2DProj(spotLightShape,shadowCoord[i])*factor;
    gl_FragColor+=frontColors[i]*colorFactor.x;
//    gl_FragColor+=frontColors[i]*factor;
    ++i;
    }

  gl_FragColor=clamp(gl_FragColor,0.0,1.0);

  // we don't let the prop to execute its fragment shader because it
  // already executed in the previous pass with none shadowing lights.
  //  propFuncFS();

  // gl_FragColor will be blending with framebuffer value containing other
  // lights contributions.
  // use alpha_testing for black/dark color?
}




ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkOpenGLProperty.cxx, line
393
vtkOpenGLProperty (0x2b47e00): Couldn't build the shader program. At this
point , it can be an error in a shader or a driver bug.


ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line
497
vtkShaderProgram2 (0x36c6020):  a shader failed to compile. Its log is:
Vertex shader failed to compile with the following errors:
ERROR: 0:19: error(#105) #version must occur before any other statement in
the program
ERROR: error(#273) 1 compilation errors.  No code generated

. Its source code is:
#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1
//
============================================================================
//
//  Program:   Visualization Toolkit
//  Module:    vtkShadowMapPassShader_vs.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.
//
//
============================================================================

// Vertex shader used by the shadow mapping render pass.

#version 110

// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by
adding
// a line at the beginning like:
// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing
// lights.


void propFuncVS();

// defined in vtkLighting_s.glsl

void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,
                                gl_MaterialParameters m,
                                vec3 surfacePosEyeCoords,
                                vec3 n,
                                bool twoSided,
                                inout vec4 cpri,
                                inout vec4 csec);

void initBlackColors(out vec4 cpri,
                     out vec4 csec);


// input are
// uniform gl_TextureMatrix[VTK_LIGHTING_NUMBER_OF_LIGHTS];

varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];
varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];

void main(void)
{
  vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;
  vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;
  vec3 n=gl_NormalMatrix*gl_Normal;
  n=normalize(n);

  int i=0;
  while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
    {
    vec4 cpri;
    vec4 csec;
    initBlackColors(cpri,csec); // because ambient in previous pass.


lightSeparateSpecularColor(gl_LightSource[i],gl_FrontMaterial,eyeCoords,n,
                               false,cpri,csec);
//    frontColors[i]=vec4(0.5,0.5,0.5,1.0); // cpri+csec;

//    frontColors[i]=gl_FrontMaterial.diffuse*gl_LightSource[i].diffuse;

    frontColors[i]=cpri; //+csec;

    // we could have everything in just gl_TextureMatrix[i] but this would
    // require to add code vtkOpenGLActor. Also the value of the uniform
    // gl_TextureMatrix[i] would have to be changed on each actor.
    // gl_TextureMatrix[i] would be:
    // scale_bias*projection_light[i]*view_light[i]*model
    // and we would have just texCoord=gl_TextureMatrix[i]*gl_Vertex;
    //
    // gl_TextureMatrix[i] is actually:
    // scale_bias*projection_light[i]*view_light[i]*view_camera_inv

    vec4 texCoord=gl_TextureMatrix[i]*heyeCoords;
    shadowCoord[i]=texCoord/texCoord.w;
    ++i;
    }

  // we have to use the fixed-pipeline transform to avoid mismatching with
  // other passes.
  gl_Position=ftransform();

  // propFuncVS(); // opportunity for the prop to execute its vertex shader.



  // we don't initialize gl_FrontColor because we have an array of colors
  // in frontColors[].
}




ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line
497
vtkShaderProgram2 (0x36c6020):  a shader failed to compile. Its log is:
Vertex shader failed to compile with the following errors:
ERROR: 0:20: error(#105) #version must occur before any other statement in
the program
ERROR: error(#273) 1 compilation errors.  No code generated

. Its source code is:
#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1
//
============================================================================
//
//  Program:   Visualization Toolkit
//  Module:    vtkLighting_s.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.
//
//
============================================================================

// This file defines some lighting functions.
// They can be used either in a vertex or fragment shader.

#version 110

// Example in vertex shader:
// Reminder: two-sided/one-sided is controlled by GL_VERTEX_PROGRAM_TWO_SIDE
//
// vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;
// vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;
// vec3 n=gl_Normalmatrix*gl_Normal;
// n=normalize(n);
//
separateSpecularColor(gl_FrontMaterial,eyeCoords,n,gl_FrontColor,gl_FrontSecondaryColor);
 // If two-sided.
//
separateSpecularColor(gl_BackMaterial,eyeCoords,n,gl_BackColor,gl_BackSecondaryColor);

 // Typical:
// gl_FrontColor=singleColor(gl_FrontMaterial,eyeCoords,n);

// VTK_LIGHTING_NUMBER_OF_LIGHTS has to be defined (by shader source string
// concatenation) to be the number of lights on, contiguous from 0 to
// VTK_LIGHTING_NUMBER_OF_LIGHTS-1
// it has to be less than gl_MaxLights (typically 8)

// Per light computation
// (it means the scene ambient term is missing).
// lightSource is usually as gl_LightSource[i]
void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,
                                gl_MaterialParameters m,
                                vec3 surfacePosEyeCoords,
                                vec3 n,
                                bool twoSided,
                                inout vec4 cpri,
                                inout vec4 csec)
{
  vec3 ldir;
  vec3 h;
  float att;
  float spot;
  float shininessFactor;
  vec3 wReverseRayDir=surfacePosEyeCoords;

  if(lightSource.position.w!=0.0)
    {
    // ldir=light direction
    vec3 lightPos=lightSource.position.xyz/lightSource.position.w;
    ldir=lightPos-surfacePosEyeCoords;
    float sqrDistance=dot(ldir,ldir);
    ldir=normalize(ldir);
    h=normalize(ldir+normalize(wReverseRayDir));

att=1.0/(lightSource.constantAttenuation+lightSource.linearAttenuation*sqrt(sqrDistance)+lightSource.quadraticAttenuation*sqrDistance);
    // USED
    }
  else
    {
    att=1.0;
    ldir=lightSource.position.xyz;
    ldir=normalize(ldir);
    h=normalize(ldir+wReverseRayDir);
    }

  if(att>0.0)
    {
    // USED
    if(lightSource.spotCutoff==180.0)
      {
      spot=1.0;
      // NOT USED
      }
    else
      {
      // USED

      float coef=-dot(ldir,normalize(lightSource.spotDirection));
      if(coef>=lightSource.spotCosCutoff)
        {
        spot=pow(coef,lightSource.spotExponent);
        // USED
        }
      else
        {
        spot=0.0;
        // NOT USED
        }
      }
    if(spot>0.0)
      {
      // USED

      // LIT operation...
      float nDotL=dot(n,ldir);
      float nDotH=dot(n,h);

      // separate nDotL and nDotH for two-sided shading, otherwise we
      // get black spots.

      if(nDotL<0.0) // two-sided shading
        {
//        nDotL=-nDotL; // mostly NOT USED
        nDotL=0.0;
        }

      if(nDotH<0.0) // two-sided shading
        {
//        nDotH=-nDotH; // mostly USED, except on the back face of the
plane.
        nDotH=0.0;
        }

      // ambient term for this light
      vec4 cpril=m.ambient*lightSource.ambient;// acm*adi

//      cpri=cpril;
//      return;

      // diffuse term for this light
      if(nDotL>0.0)
        {
        // USED
        cpril+=m.diffuse*lightSource.diffuse*nDotL; // dcm*dcli
        }


      // specular term for this light
      shininessFactor=pow(nDotH,m.shininess); // srm

      cpri+=att*spot*cpril;

      // scm*scli
      csec+=att*spot*
        m.specular*lightSource.specular*shininessFactor;

      }
    }
}

// Ignore Scene ambient. Useful in multipass, if the ambient was already
// taken into account in a previous pass.
void initBlackColors(out vec4 cpri,
                     out vec4 csec)
{
  cpri=vec4(0.0,0.0,0.0,1.0);
  csec=vec4(0.0,0.0,0.0,1.0);
}

void initColorsWithAmbient(gl_MaterialParameters m,
                           out vec4 cpri,
                           out vec4 csec)
{
  cpri=m.emission+m.ambient*gl_LightModel.ambient; // ecm+acm*acs
  csec=vec4(0.0,0.0,0.0,1.0);
}

#ifdef VTK_LIGHTING_NUMBER_OF_LIGHTS

// This is convenience method to use in shader but you better do
// this computation on the CPU and send the result as a uniform.

// True if any enabled light is a positional one.
bool needSurfacePositionInEyeCoordinates()
{
 int i=0;
 bool result=false;
 while(!result && i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
  {
   result=gl_LightSource[i].position.w!=0.0;
   ++i;
  }
 return result;
}

// Lighting computation based on a material m,
// a position on the surface expressed in eye coordinate (typically a vertex
//  position in a vertex shader, something interpolated in a fragment
shader),
// a unit normal `n' to the surface in eye coordinates.
// Most of the components are in cpri (primary color), the specular
// component is in csec (secondary color).
// Useful for blending color and textures.
void separateSpecularColor(gl_MaterialParameters m,
                           vec3 surfacePosEyeCoords,
                           vec3 n,
                           bool twoSided,
                           out vec4 cpri,
                           out vec4 csec)
{
  initColorsWithAmbient(m,cpri,csec);

  // For each light,
  int i=0;
  while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
    {
    lightSeparateSpecularColor(gl_LightSource[i],m,surfacePosEyeCoords,n,
                               twoSided,cpri,csec);
    ++i;
    }
}

// Lighting computation based on a material m,
// a position on the surface expressed in eye coordinate (typically a vertex
//  position in a vertex shader, something interpolated in a fragment
shader),
// a unit normal to the surface in eye coordinates.
// The result includes the specular component.
vec4 singleColor(gl_MaterialParameters m,
                 vec3 surfacePosEyeCoords,
                 vec3 n,
                 bool twoSided)
{
  vec4 cpri;
  vec4 csec;
  separateSpecularColor(m,surfacePosEyeCoords,n,twoSided,cpri,csec);
  return cpri+csec;
}

#endif




ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line
497
vtkShaderProgram2 (0x36c6020):  a shader failed to compile. Its log is:
Fragment shader failed to compile with the following errors:
ERROR: 0:19: error(#105) #version must occur before any other statement in
the program
ERROR: error(#273) 1 compilation errors.  No code generated

. Its source code is:
#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1
//
============================================================================
//
//  Program:   Visualization Toolkit
//  Module:    vtkShadowMapPassShader_fs.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.
//
//
============================================================================

// Fragment shader used by the shadow mapping render pass.

#version 110

// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by
adding
// a line at the beginning like:
// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing
// lights.

uniform sampler2DShadow shadowMaps[VTK_LIGHTING_NUMBER_OF_LIGHTS];
uniform sampler2D spotLightShape;

varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];
varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];

void main(void)
{
  gl_FragColor=vec4(0.0,0.0,0.0,0.0);
  int i=0;
  while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
    {
    float factor=0.0;
    if(shadowCoord[i].w>0.0)
      {
      vec2 projected=shadowCoord[i].xy/shadowCoord[i].w;
      if(projected.x>=0.0 && projected.x<=1.0
        && projected.y>=0.0 && projected.y<=1.0)
        {
        factor=shadow2DProj(shadowMaps[i],shadowCoord[i]).x;
        }
      }
    vec4 colorFactor=texture2DProj(spotLightShape,shadowCoord[i])*factor;
    gl_FragColor+=frontColors[i]*colorFactor.x;
//    gl_FragColor+=frontColors[i]*factor;
    ++i;
    }

  gl_FragColor=clamp(gl_FragColor,0.0,1.0);

  // we don't let the prop to execute its fragment shader because it
  // already executed in the previous pass with none shadowing lights.
  //  propFuncFS();

  // gl_FragColor will be blending with framebuffer value containing other
  // lights contributions.
  // use alpha_testing for black/dark color?
}




ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkOpenGLProperty.cxx, line
393
vtkOpenGLProperty (0x2b99710): Couldn't build the shader program. At this
point , it can be an error in a shader or a driver bug.


ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line
497
vtkShaderProgram2 (0x36bf250):  a shader failed to compile. Its log is:
Vertex shader failed to compile with the following errors:
ERROR: 0:19: error(#105) #version must occur before any other statement in
the program
ERROR: error(#273) 1 compilation errors.  No code generated

. Its source code is:
#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1
//
============================================================================
//
//  Program:   Visualization Toolkit
//  Module:    vtkShadowMapPassShader_vs.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.
//
//
============================================================================

// Vertex shader used by the shadow mapping render pass.

#version 110

// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by
adding
// a line at the beginning like:
// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing
// lights.


void propFuncVS();

// defined in vtkLighting_s.glsl

void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,
                                gl_MaterialParameters m,
                                vec3 surfacePosEyeCoords,
                                vec3 n,
                                bool twoSided,
                                inout vec4 cpri,
                                inout vec4 csec);

void initBlackColors(out vec4 cpri,
                     out vec4 csec);


// input are
// uniform gl_TextureMatrix[VTK_LIGHTING_NUMBER_OF_LIGHTS];

varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];
varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];

void main(void)
{
  vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;
  vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;
  vec3 n=gl_NormalMatrix*gl_Normal;
  n=normalize(n);

  int i=0;
  while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
    {
    vec4 cpri;
    vec4 csec;
    initBlackColors(cpri,csec); // because ambient in previous pass.


lightSeparateSpecularColor(gl_LightSource[i],gl_FrontMaterial,eyeCoords,n,
                               false,cpri,csec);
//    frontColors[i]=vec4(0.5,0.5,0.5,1.0); // cpri+csec;

//    frontColors[i]=gl_FrontMaterial.diffuse*gl_LightSource[i].diffuse;

    frontColors[i]=cpri; //+csec;

    // we could have everything in just gl_TextureMatrix[i] but this would
    // require to add code vtkOpenGLActor. Also the value of the uniform
    // gl_TextureMatrix[i] would have to be changed on each actor.
    // gl_TextureMatrix[i] would be:
    // scale_bias*projection_light[i]*view_light[i]*model
    // and we would have just texCoord=gl_TextureMatrix[i]*gl_Vertex;
    //
    // gl_TextureMatrix[i] is actually:
    // scale_bias*projection_light[i]*view_light[i]*view_camera_inv

    vec4 texCoord=gl_TextureMatrix[i]*heyeCoords;
    shadowCoord[i]=texCoord/texCoord.w;
    ++i;
    }

  // we have to use the fixed-pipeline transform to avoid mismatching with
  // other passes.
  gl_Position=ftransform();

  // propFuncVS(); // opportunity for the prop to execute its vertex shader.



  // we don't initialize gl_FrontColor because we have an array of colors
  // in frontColors[].
}




ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line
497
vtkShaderProgram2 (0x36bf250):  a shader failed to compile. Its log is:
Vertex shader failed to compile with the following errors:
ERROR: 0:20: error(#105) #version must occur before any other statement in
the program
ERROR: error(#273) 1 compilation errors.  No code generated

. Its source code is:
#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1
//
============================================================================
//
//  Program:   Visualization Toolkit
//  Module:    vtkLighting_s.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.
//
//
============================================================================

// This file defines some lighting functions.
// They can be used either in a vertex or fragment shader.

#version 110

// Example in vertex shader:
// Reminder: two-sided/one-sided is controlled by GL_VERTEX_PROGRAM_TWO_SIDE
//
// vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;
// vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;
// vec3 n=gl_Normalmatrix*gl_Normal;
// n=normalize(n);
//
separateSpecularColor(gl_FrontMaterial,eyeCoords,n,gl_FrontColor,gl_FrontSecondaryColor);
 // If two-sided.
//
separateSpecularColor(gl_BackMaterial,eyeCoords,n,gl_BackColor,gl_BackSecondaryColor);

 // Typical:
// gl_FrontColor=singleColor(gl_FrontMaterial,eyeCoords,n);

// VTK_LIGHTING_NUMBER_OF_LIGHTS has to be defined (by shader source string
// concatenation) to be the number of lights on, contiguous from 0 to
// VTK_LIGHTING_NUMBER_OF_LIGHTS-1
// it has to be less than gl_MaxLights (typically 8)

// Per light computation
// (it means the scene ambient term is missing).
// lightSource is usually as gl_LightSource[i]
void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,
                                gl_MaterialParameters m,
                                vec3 surfacePosEyeCoords,
                                vec3 n,
                                bool twoSided,
                                inout vec4 cpri,
                                inout vec4 csec)
{
  vec3 ldir;
  vec3 h;
  float att;
  float spot;
  float shininessFactor;
  vec3 wReverseRayDir=surfacePosEyeCoords;

  if(lightSource.position.w!=0.0)
    {
    // ldir=light direction
    vec3 lightPos=lightSource.position.xyz/lightSource.position.w;
    ldir=lightPos-surfacePosEyeCoords;
    float sqrDistance=dot(ldir,ldir);
    ldir=normalize(ldir);
    h=normalize(ldir+normalize(wReverseRayDir));

att=1.0/(lightSource.constantAttenuation+lightSource.linearAttenuation*sqrt(sqrDistance)+lightSource.quadraticAttenuation*sqrDistance);
    // USED
    }
  else
    {
    att=1.0;
    ldir=lightSource.position.xyz;
    ldir=normalize(ldir);
    h=normalize(ldir+wReverseRayDir);
    }

  if(att>0.0)
    {
    // USED
    if(lightSource.spotCutoff==180.0)
      {
      spot=1.0;
      // NOT USED
      }
    else
      {
      // USED

      float coef=-dot(ldir,normalize(lightSource.spotDirection));
      if(coef>=lightSource.spotCosCutoff)
        {
        spot=pow(coef,lightSource.spotExponent);
        // USED
        }
      else
        {
        spot=0.0;
        // NOT USED
        }
      }
    if(spot>0.0)
      {
      // USED

      // LIT operation...
      float nDotL=dot(n,ldir);
      float nDotH=dot(n,h);

      // separate nDotL and nDotH for two-sided shading, otherwise we
      // get black spots.

      if(nDotL<0.0) // two-sided shading
        {
//        nDotL=-nDotL; // mostly NOT USED
        nDotL=0.0;
        }

      if(nDotH<0.0) // two-sided shading
        {
//        nDotH=-nDotH; // mostly USED, except on the back face of the
plane.
        nDotH=0.0;
        }

      // ambient term for this light
      vec4 cpril=m.ambient*lightSource.ambient;// acm*adi

//      cpri=cpril;
//      return;

      // diffuse term for this light
      if(nDotL>0.0)
        {
        // USED
        cpril+=m.diffuse*lightSource.diffuse*nDotL; // dcm*dcli
        }


      // specular term for this light
      shininessFactor=pow(nDotH,m.shininess); // srm

      cpri+=att*spot*cpril;

      // scm*scli
      csec+=att*spot*
        m.specular*lightSource.specular*shininessFactor;

      }
    }
}

// Ignore Scene ambient. Useful in multipass, if the ambient was already
// taken into account in a previous pass.
void initBlackColors(out vec4 cpri,
                     out vec4 csec)
{
  cpri=vec4(0.0,0.0,0.0,1.0);
  csec=vec4(0.0,0.0,0.0,1.0);
}

void initColorsWithAmbient(gl_MaterialParameters m,
                           out vec4 cpri,
                           out vec4 csec)
{
  cpri=m.emission+m.ambient*gl_LightModel.ambient; // ecm+acm*acs
  csec=vec4(0.0,0.0,0.0,1.0);
}

#ifdef VTK_LIGHTING_NUMBER_OF_LIGHTS

// This is convenience method to use in shader but you better do
// this computation on the CPU and send the result as a uniform.

// True if any enabled light is a positional one.
bool needSurfacePositionInEyeCoordinates()
{
 int i=0;
 bool result=false;
 while(!result && i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
  {
   result=gl_LightSource[i].position.w!=0.0;
   ++i;
  }
 return result;
}

// Lighting computation based on a material m,
// a position on the surface expressed in eye coordinate (typically a vertex
//  position in a vertex shader, something interpolated in a fragment
shader),
// a unit normal `n' to the surface in eye coordinates.
// Most of the components are in cpri (primary color), the specular
// component is in csec (secondary color).
// Useful for blending color and textures.
void separateSpecularColor(gl_MaterialParameters m,
                           vec3 surfacePosEyeCoords,
                           vec3 n,
                           bool twoSided,
                           out vec4 cpri,
                           out vec4 csec)
{
  initColorsWithAmbient(m,cpri,csec);

  // For each light,
  int i=0;
  while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
    {
    lightSeparateSpecularColor(gl_LightSource[i],m,surfacePosEyeCoords,n,
                               twoSided,cpri,csec);
    ++i;
    }
}

// Lighting computation based on a material m,
// a position on the surface expressed in eye coordinate (typically a vertex
//  position in a vertex shader, something interpolated in a fragment
shader),
// a unit normal to the surface in eye coordinates.
// The result includes the specular component.
vec4 singleColor(gl_MaterialParameters m,
                 vec3 surfacePosEyeCoords,
                 vec3 n,
                 bool twoSided)
{
  vec4 cpri;
  vec4 csec;
  separateSpecularColor(m,surfacePosEyeCoords,n,twoSided,cpri,csec);
  return cpri+csec;
}

#endif




ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line
497
vtkShaderProgram2 (0x36bf250):  a shader failed to compile. Its log is:
Fragment shader failed to compile with the following errors:
ERROR: 0:19: error(#105) #version must occur before any other statement in
the program
ERROR: error(#273) 1 compilation errors.  No code generated

. Its source code is:
#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1
//
============================================================================
//
//  Program:   Visualization Toolkit
//  Module:    vtkShadowMapPassShader_fs.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.
//
//
============================================================================

// Fragment shader used by the shadow mapping render pass.

#version 110

// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by
adding
// a line at the beginning like:
// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing
// lights.

uniform sampler2DShadow shadowMaps[VTK_LIGHTING_NUMBER_OF_LIGHTS];
uniform sampler2D spotLightShape;

varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];
varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];

void main(void)
{
  gl_FragColor=vec4(0.0,0.0,0.0,0.0);
  int i=0;
  while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
    {
    float factor=0.0;
    if(shadowCoord[i].w>0.0)
      {
      vec2 projected=shadowCoord[i].xy/shadowCoord[i].w;
      if(projected.x>=0.0 && projected.x<=1.0
        && projected.y>=0.0 && projected.y<=1.0)
        {
        factor=shadow2DProj(shadowMaps[i],shadowCoord[i]).x;
        }
      }
    vec4 colorFactor=texture2DProj(spotLightShape,shadowCoord[i])*factor;
    gl_FragColor+=frontColors[i]*colorFactor.x;
//    gl_FragColor+=frontColors[i]*factor;
    ++i;
    }

  gl_FragColor=clamp(gl_FragColor,0.0,1.0);

  // we don't let the prop to execute its fragment shader because it
  // already executed in the previous pass with none shadowing lights.
  //  propFuncFS();

  // gl_FragColor will be blending with framebuffer value containing other
  // lights contributions.
  // use alpha_testing for black/dark color?
}




ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkOpenGLProperty.cxx, line
393
vtkOpenGLProperty (0x2b47e00): Couldn't build the shader program. At this
point , it can be an error in a shader or a driver bug.


ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line
497
vtkShaderProgram2 (0x36c6020):  a shader failed to compile. Its log is:
Vertex shader failed to compile with the following errors:
ERROR: 0:19: error(#105) #version must occur before any other statement in
the program
ERROR: error(#273) 1 compilation errors.  No code generated

. Its source code is:
#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1
//
============================================================================
//
//  Program:   Visualization Toolkit
//  Module:    vtkShadowMapPassShader_vs.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.
//
//
============================================================================

// Vertex shader used by the shadow mapping render pass.

#version 110

// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by
adding
// a line at the beginning like:
// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing
// lights.


void propFuncVS();

// defined in vtkLighting_s.glsl

void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,
                                gl_MaterialParameters m,
                                vec3 surfacePosEyeCoords,
                                vec3 n,
                                bool twoSided,
                                inout vec4 cpri,
                                inout vec4 csec);

void initBlackColors(out vec4 cpri,
                     out vec4 csec);


// input are
// uniform gl_TextureMatrix[VTK_LIGHTING_NUMBER_OF_LIGHTS];

varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];
varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];

void main(void)
{
  vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;
  vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;
  vec3 n=gl_NormalMatrix*gl_Normal;
  n=normalize(n);

  int i=0;
  while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
    {
    vec4 cpri;
    vec4 csec;
    initBlackColors(cpri,csec); // because ambient in previous pass.


lightSeparateSpecularColor(gl_LightSource[i],gl_FrontMaterial,eyeCoords,n,
                               false,cpri,csec);
//    frontColors[i]=vec4(0.5,0.5,0.5,1.0); // cpri+csec;

//    frontColors[i]=gl_FrontMaterial.diffuse*gl_LightSource[i].diffuse;

    frontColors[i]=cpri; //+csec;

    // we could have everything in just gl_TextureMatrix[i] but this would
    // require to add code vtkOpenGLActor. Also the value of the uniform
    // gl_TextureMatrix[i] would have to be changed on each actor.
    // gl_TextureMatrix[i] would be:
    // scale_bias*projection_light[i]*view_light[i]*model
    // and we would have just texCoord=gl_TextureMatrix[i]*gl_Vertex;
    //
    // gl_TextureMatrix[i] is actually:
    // scale_bias*projection_light[i]*view_light[i]*view_camera_inv

    vec4 texCoord=gl_TextureMatrix[i]*heyeCoords;
    shadowCoord[i]=texCoord/texCoord.w;
    ++i;
    }

  // we have to use the fixed-pipeline transform to avoid mismatching with
  // other passes.
  gl_Position=ftransform();

  // propFuncVS(); // opportunity for the prop to execute its vertex shader.



  // we don't initialize gl_FrontColor because we have an array of colors
  // in frontColors[].
}




ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line
497
vtkShaderProgram2 (0x36c6020):  a shader failed to compile. Its log is:
Vertex shader failed to compile with the following errors:
ERROR: 0:20: error(#105) #version must occur before any other statement in
the program
ERROR: error(#273) 1 compilation errors.  No code generated

. Its source code is:
#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1
//
============================================================================
//
//  Program:   Visualization Toolkit
//  Module:    vtkLighting_s.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.
//
//
============================================================================

// This file defines some lighting functions.
// They can be used either in a vertex or fragment shader.

#version 110

// Example in vertex shader:
// Reminder: two-sided/one-sided is controlled by GL_VERTEX_PROGRAM_TWO_SIDE
//
// vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;
// vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;
// vec3 n=gl_Normalmatrix*gl_Normal;
// n=normalize(n);
//
separateSpecularColor(gl_FrontMaterial,eyeCoords,n,gl_FrontColor,gl_FrontSecondaryColor);
 // If two-sided.
//
separateSpecularColor(gl_BackMaterial,eyeCoords,n,gl_BackColor,gl_BackSecondaryColor);

 // Typical:
// gl_FrontColor=singleColor(gl_FrontMaterial,eyeCoords,n);

// VTK_LIGHTING_NUMBER_OF_LIGHTS has to be defined (by shader source string
// concatenation) to be the number of lights on, contiguous from 0 to
// VTK_LIGHTING_NUMBER_OF_LIGHTS-1
// it has to be less than gl_MaxLights (typically 8)

// Per light computation
// (it means the scene ambient term is missing).
// lightSource is usually as gl_LightSource[i]
void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,
                                gl_MaterialParameters m,
                                vec3 surfacePosEyeCoords,
                                vec3 n,
                                bool twoSided,
                                inout vec4 cpri,
                                inout vec4 csec)
{
  vec3 ldir;
  vec3 h;
  float att;
  float spot;
  float shininessFactor;
  vec3 wReverseRayDir=surfacePosEyeCoords;

  if(lightSource.position.w!=0.0)
    {
    // ldir=light direction
    vec3 lightPos=lightSource.position.xyz/lightSource.position.w;
    ldir=lightPos-surfacePosEyeCoords;
    float sqrDistance=dot(ldir,ldir);
    ldir=normalize(ldir);
    h=normalize(ldir+normalize(wReverseRayDir));

att=1.0/(lightSource.constantAttenuation+lightSource.linearAttenuation*sqrt(sqrDistance)+lightSource.quadraticAttenuation*sqrDistance);
    // USED
    }
  else
    {
    att=1.0;
    ldir=lightSource.position.xyz;
    ldir=normalize(ldir);
    h=normalize(ldir+wReverseRayDir);
    }

  if(att>0.0)
    {
    // USED
    if(lightSource.spotCutoff==180.0)
      {
      spot=1.0;
      // NOT USED
      }
    else
      {
      // USED

      float coef=-dot(ldir,normalize(lightSource.spotDirection));
      if(coef>=lightSource.spotCosCutoff)
        {
        spot=pow(coef,lightSource.spotExponent);
        // USED
        }
      else
        {
        spot=0.0;
        // NOT USED
        }
      }
    if(spot>0.0)
      {
      // USED

      // LIT operation...
      float nDotL=dot(n,ldir);
      float nDotH=dot(n,h);

      // separate nDotL and nDotH for two-sided shading, otherwise we
      // get black spots.

      if(nDotL<0.0) // two-sided shading
        {
//        nDotL=-nDotL; // mostly NOT USED
        nDotL=0.0;
        }

      if(nDotH<0.0) // two-sided shading
        {
//        nDotH=-nDotH; // mostly USED, except on the back face of the
plane.
        nDotH=0.0;
        }

      // ambient term for this light
      vec4 cpril=m.ambient*lightSource.ambient;// acm*adi

//      cpri=cpril;
//      return;

      // diffuse term for this light
      if(nDotL>0.0)
        {
        // USED
        cpril+=m.diffuse*lightSource.diffuse*nDotL; // dcm*dcli
        }


      // specular term for this light
      shininessFactor=pow(nDotH,m.shininess); // srm

      cpri+=att*spot*cpril;

      // scm*scli
      csec+=att*spot*
        m.specular*lightSource.specular*shininessFactor;

      }
    }
}

// Ignore Scene ambient. Useful in multipass, if the ambient was already
// taken into account in a previous pass.
void initBlackColors(out vec4 cpri,
                     out vec4 csec)
{
  cpri=vec4(0.0,0.0,0.0,1.0);
  csec=vec4(0.0,0.0,0.0,1.0);
}

void initColorsWithAmbient(gl_MaterialParameters m,
                           out vec4 cpri,
                           out vec4 csec)
{
  cpri=m.emission+m.ambient*gl_LightModel.ambient; // ecm+acm*acs
  csec=vec4(0.0,0.0,0.0,1.0);
}

#ifdef VTK_LIGHTING_NUMBER_OF_LIGHTS

// This is convenience method to use in shader but you better do
// this computation on the CPU and send the result as a uniform.

// True if any enabled light is a positional one.
bool needSurfacePositionInEyeCoordinates()
{
 int i=0;
 bool result=false;
 while(!result && i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
  {
   result=gl_LightSource[i].position.w!=0.0;
   ++i;
  }
 return result;
}

// Lighting computation based on a material m,
// a position on the surface expressed in eye coordinate (typically a vertex
//  position in a vertex shader, something interpolated in a fragment
shader),
// a unit normal `n' to the surface in eye coordinates.
// Most of the components are in cpri (primary color), the specular
// component is in csec (secondary color).
// Useful for blending color and textures.
void separateSpecularColor(gl_MaterialParameters m,
                           vec3 surfacePosEyeCoords,
                           vec3 n,
                           bool twoSided,
                           out vec4 cpri,
                           out vec4 csec)
{
  initColorsWithAmbient(m,cpri,csec);

  // For each light,
  int i=0;
  while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
    {
    lightSeparateSpecularColor(gl_LightSource[i],m,surfacePosEyeCoords,n,
                               twoSided,cpri,csec);
    ++i;
    }
}

// Lighting computation based on a material m,
// a position on the surface expressed in eye coordinate (typically a vertex
//  position in a vertex shader, something interpolated in a fragment
shader),
// a unit normal to the surface in eye coordinates.
// The result includes the specular component.
vec4 singleColor(gl_MaterialParameters m,
                 vec3 surfacePosEyeCoords,
                 vec3 n,
                 bool twoSided)
{
  vec4 cpri;
  vec4 csec;
  separateSpecularColor(m,surfacePosEyeCoords,n,twoSided,cpri,csec);
  return cpri+csec;
}

#endif




ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line
497
vtkShaderProgram2 (0x36c6020):  a shader failed to compile. Its log is:
Fragment shader failed to compile with the following errors:
ERROR: 0:19: error(#105) #version must occur before any other statement in
the program
ERROR: error(#273) 1 compilation errors.  No code generated

. Its source code is:
#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1
//
============================================================================
//
//  Program:   Visualization Toolkit
//  Module:    vtkShadowMapPassShader_fs.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.
//
//
============================================================================

// Fragment shader used by the shadow mapping render pass.

#version 110

// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by
adding
// a line at the beginning like:
// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing
// lights.

uniform sampler2DShadow shadowMaps[VTK_LIGHTING_NUMBER_OF_LIGHTS];
uniform sampler2D spotLightShape;

varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];
varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];

void main(void)
{
  gl_FragColor=vec4(0.0,0.0,0.0,0.0);
  int i=0;
  while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)
    {
    float factor=0.0;
    if(shadowCoord[i].w>0.0)
      {
      vec2 projected=shadowCoord[i].xy/shadowCoord[i].w;
      if(projected.x>=0.0 && projected.x<=1.0
        && projected.y>=0.0 && projected.y<=1.0)
        {
        factor=shadow2DProj(shadowMaps[i],shadowCoord[i]).x;
        }
      }
    vec4 colorFactor=texture2DProj(spotLightShape,shadowCoord[i])*factor;
    gl_FragColor+=frontColors[i]*colorFactor.x;
//    gl_FragColor+=frontColors[i]*factor;
    ++i;
    }

  gl_FragColor=clamp(gl_FragColor,0.0,1.0);

  // we don't let the prop to execute its fragment shader because it
  // already executed in the previous pass with none shadowing lights.
  //  propFuncFS();

  // gl_FragColor will be blending with framebuffer value containing other
  // lights contributions.
  // use alpha_testing for black/dark color?
}

ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkOpenGLProperty.cxx, line
393
vtkOpenGLProperty (0x2b99710): Couldn't build the shader program. At this
point , it can be an error in a shader or a driver bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110414/0e3610cf/attachment.htm>


More information about the vtkusers mailing list