Hi,<br><br>I'm running the code below in the Ubuntu 10.10 and ATI Radeon HD 3200 video card. <br><br>But does shadow <meta http-equiv="content-type" content="text/html; charset=utf-8">display (Other PC with NVidia is displayed).<br>
<br>The VTK version is from git version 94fe54a6eb6f6a05ada35305f183a073197be743 (Apr. 13)<div><br>
Regards<br><br><br><b>Code:</b><br><br>from vtk import *
<br> <br>iren = vtkRenderWindowInteractor()
<br> <br>renWin = vtkRenderWindow()
<br>renWin.SetMultiSamples(0)
<br>
<br>renWin.SetAlphaBitPlanes(1)
<br>iren.SetRenderWindow(renWin)
<br> <br>renderer = vtkRenderer()
<br>renWin.AddRenderer(renderer)
<br> <br> <br> <br> <br>cameraP = vtkCameraPass()
<br> <br>opaque = vtkOpaquePass()
<br> <br>peeling=vtkDepthPeelingPass()
<br>peeling.SetMaximumNumberOfPeels(200)
<br>peeling.SetOcclusionRatio(0.1)
<br> <br>translucent=vtkTranslucentPass()
<br>peeling.SetTranslucentPass(translucent)
<br> <br>volume=vtkVolumetricPass()
<br>overlay=vtkOverlayPass()
<br>lights=vtkLightsPass()
<br>opaqueSequence=vtkSequencePass()
<br> <br>passes2=vtkRenderPassCollection()
<br>passes2.AddItem(lights)
<br>passes2.AddItem(opaque)
<br> <br>opaqueSequence.SetPasses(passes2)
<br>opaqueCameraPass=vtkCameraPass()
<br>opaqueCameraPass.SetDelegatePass(opaqueSequence)
<br> <br>shadowsBaker=vtkShadowMapBakerPass()
<br>shadowsBaker.SetOpaquePass(opaqueCameraPass)
<br>shadowsBaker.SetResolution(1024)
<br> <br>#To cancel self-shadowing.
<br>shadowsBaker.SetPolygonOffsetFactor(3.1)
<br>shadowsBaker.SetPolygonOffsetUnits(10.0)
<br> <br>shadows=vtkShadowMapPass()
<br>shadows.SetShadowMapBakerPass(shadowsBaker)
<br>shadows.SetOpaquePass(opaqueSequence)
<br> <br>seq=vtkSequencePass()
<br>passes=vtkRenderPassCollection()
<br>passes.AddItem(shadowsBaker)
<br>passes.AddItem(shadows)
<br>passes.AddItem(lights)
<br>passes.AddItem(peeling)
<br>passes.AddItem(volume)
<br>passes.AddItem(overlay)
<br> <br>seq.SetPasses(passes)
<br>cameraP.SetDelegatePass(seq)
<br>renderer.SetPass(cameraP)
<br> <br> <br>stl = vtkSTLReader()
<br>stl.SetFileName('head.stl')
<br>stl.Update()
<br> <br>stlNormals=vtkPolyDataNormals()
<br>stlNormals.SetInputConnection(stl.GetOutputPort())
<br>stlNormals.SetComputePointNormals(0)
<br>stlNormals.SetComputeCellNormals(1)
<br>stlNormals.SetComputePointNormals(0)
<br>stlNormals.Update()
<br> <br>stlMapper=vtkPolyDataMapper()
<br>stlMapper.SetInputConnection(stlNormals.GetOutputPort())
<br>#boxNormals.Delete()
<br>#boxSource.Delete()
<br>stlMapper.SetScalarVisibility(0)
<br> <br>stlActor=vtkActor()
<br> <br>stlKeyProperties=vtkInformation()
<br>stlKeyProperties.Set(vtkShadowMapBakerPass.OCCLUDER(),0) #// dummy val.
<br>stlKeyProperties.Set(vtkShadowMapBakerPass.RECEIVER(),0) #// dummy val.
<br>stlActor.SetPropertyKeys(stlKeyProperties)
<br>stlActor.SetMapper(stlMapper)
<br>stlActor.SetVisibility(1)
<br>stlActor.SetPosition(-2.0,2.0,0.0)
<br>stlActor.GetProperty().SetColor(0.66,0.66,0.66)
<br> <br> <br># -------------------------------------------------------------------------------
<br> <br>sphereSource=vtkSphereSource()
<br>sphereSource.SetRadius(1)
<br>sphereSource.SetThetaResolution(32)
<br>sphereSource.SetPhiResolution(32)
<br> <br>sphereMapper=vtkPolyDataMapper()
<br>sphereMapper.SetInputConnection(sphereSource.GetOutputPort())
<br>sphereMapper.SetScalarVisibility(0)
<br> <br>sphereActor=vtkActor()
<br> <br>sphereKeyProperties=vtkInformation()
<br>sphereKeyProperties.Set(vtkShadowMapBakerPass.OCCLUDER(),0) #// dummy val.
<br>sphereKeyProperties.Set(vtkShadowMapBakerPass.RECEIVER(),0) #// dummy val.
<br>sphereActor.SetPropertyKeys(sphereKeyProperties)
<br> <br>sphereActor.SetMapper(sphereMapper)
<br> <br>sphereActor.SetVisibility(1)
<br>b_stl = stlActor.GetBounds()
<br>sphereActor.SetPosition((b_stl[0] + b_stl[1])/2, (b_stl[2] + b_stl[3])/2, b_stl[5] + 50)
<br>sphereActor.GetProperty().SetColor(1.0,1.0,0.0)
<br> <br>renderer.AddActor(stlActor)
<br>renderer.ResetCamera()
<br> <br>renderer.AddActor(sphereActor)
<br> <br>#lighting the sphere
<br>l2=vtkLight()
<br> <br>s_pos = sphereActor.GetPosition()
<br>l2.SetPosition(s_pos[0], s_pos[1], s_pos[2] + 100)
<br>l2.SetFocalPoint(sphereActor.GetPosition())
<br>l2.SetColor(0.5,0.5,0.5)
<br>l2.SetPositional(1)
<br> <br>renderer.AddLight(l2)
<br>l2.SetSwitch(1)
<br> <br>renderer.SetBackground(0.66,0.66,0.66)
<br> <br> <br>renderer.SetGradientBackground(True)
<br>renWin.SetSize(1000,1000)
<br>renWin.Render()
<br> <br>camera=renderer.GetActiveCamera()
<br>camera.Azimuth(40.0)
<br>camera.Elevation(10.0)
<br> <br>camera.SetPosition(s_pos[0] + 50, s_pos[1], s_pos[2] + 100)
<br> <br>renderer.Render()
<br>renWin.Render()
<br>iren.Start()
<br><br><br><b>Error log:</b><br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line 497<br>vtkShaderProgram2 (0x36bf250): a shader failed to compile. Its log is:<br>Vertex shader failed to compile with the following errors:<br>
ERROR: 0:19: error(#105) #version must occur before any other statement in the program<br>ERROR: error(#273) 1 compilation errors. No code generated<br><br>. Its source code is:<br>#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1<br>
// ============================================================================<br>//<br>// Program: Visualization Toolkit<br>// Module: vtkShadowMapPassShader_vs.glsl<br>//<br>// Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen<br>
// All rights reserved.<br>// See Copyright.txt or <a href="http://www.kitware.com/Copyright.htm" target="_blank">http://www.kitware.com/Copyright.htm</a> for details.<br>//<br>// This software is distributed WITHOUT ANY WARRANTY; without even<br>
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR<br>// PURPOSE. See the above copyright notice for more information.<br>//<br>// ============================================================================<br>
<br>// Vertex shader used by the shadow mapping render pass.<br><br>#version 110<br><br>// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by adding<br>// a line at the beginning like:<br>// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing<br>
// lights.<br><br><br>void propFuncVS();<br><br>// defined in vtkLighting_s.glsl<br><br>void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,<br> gl_MaterialParameters m,<br>
vec3 surfacePosEyeCoords,<br> vec3 n,<br> bool twoSided,<br> inout vec4 cpri,<br> inout vec4 csec);<br>
<br>void initBlackColors(out vec4 cpri,<br> out vec4 csec);<br><br><br>// input are<br>// uniform gl_TextureMatrix[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br><br>varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>
varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br><br>void main(void)<br>{<br> vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;<br> vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;<br> vec3 n=gl_NormalMatrix*gl_Normal;<br>
n=normalize(n);<br> <br> int i=0;<br> while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)<br> {<br> vec4 cpri;<br> vec4 csec;<br> initBlackColors(cpri,csec); // because ambient in previous pass.<br> <br> lightSeparateSpecularColor(gl_LightSource[i],gl_FrontMaterial,eyeCoords,n,<br>
false,cpri,csec);<br>// frontColors[i]=vec4(0.5,0.5,0.5,1.0); // cpri+csec;<br> <br>// frontColors[i]=gl_FrontMaterial.diffuse*gl_LightSource[i].diffuse;<br> <br> frontColors[i]=cpri; //+csec;<br>
<br> // we could have everything in just gl_TextureMatrix[i] but this would<br> // require to add code vtkOpenGLActor. Also the value of the uniform<br> // gl_TextureMatrix[i] would have to be changed on each actor.<br>
// gl_TextureMatrix[i] would be:<br> // scale_bias*projection_light[i]*view_light[i]*model<br> // and we would have just texCoord=gl_TextureMatrix[i]*gl_Vertex;<br> //<br> // gl_TextureMatrix[i] is actually:<br>
// scale_bias*projection_light[i]*view_light[i]*view_camera_inv<br> <br> vec4 texCoord=gl_TextureMatrix[i]*heyeCoords;<br> shadowCoord[i]=texCoord/texCoord.w;<br> ++i;<br> }<br> <br> // we have to use the fixed-pipeline transform to avoid mismatching with<br>
// other passes.<br> gl_Position=ftransform();<br> <br> // propFuncVS(); // opportunity for the prop to execute its vertex shader.<br> <br> <br> <br> // we don't initialize gl_FrontColor because we have an array of colors<br>
// in frontColors[].<br>}<br><br><br><br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line 497<br>vtkShaderProgram2 (0x36bf250): a shader failed to compile. Its log is:<br>Vertex shader failed to compile with the following errors:<br>
ERROR: 0:20: error(#105) #version must occur before any other statement in the program<br>ERROR: error(#273) 1 compilation errors. No code generated<br><br>. Its source code is:<br>#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1<br>
// ============================================================================<br>//<br>// Program: Visualization Toolkit<br>// Module: vtkLighting_s.glsl<br>//<br>// Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen<br>
// All rights reserved.<br>// See Copyright.txt or <a href="http://www.kitware.com/Copyright.htm" target="_blank">http://www.kitware.com/Copyright.htm</a> for details.<br>//<br>// This software is distributed WITHOUT ANY WARRANTY; without even<br>
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR<br>// PURPOSE. See the above copyright notice for more information.<br>//<br>// ============================================================================<br>
<br>// This file defines some lighting functions.<br>// They can be used either in a vertex or fragment shader.<br><br>#version 110<br><br>// Example in vertex shader:<br>// Reminder: two-sided/one-sided is controlled by GL_VERTEX_PROGRAM_TWO_SIDE<br>
//<br>// vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;<br>// vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;<br>// vec3 n=gl_Normalmatrix*gl_Normal;<br>// n=normalize(n);<br>// separateSpecularColor(gl_FrontMaterial,eyeCoords,n,gl_FrontColor,gl_FrontSecondaryColor);<br>
// If two-sided.<br>// separateSpecularColor(gl_BackMaterial,eyeCoords,n,gl_BackColor,gl_BackSecondaryColor);<br><br> // Typical:<br>// gl_FrontColor=singleColor(gl_FrontMaterial,eyeCoords,n);<br><br>// VTK_LIGHTING_NUMBER_OF_LIGHTS has to be defined (by shader source string<br>
// concatenation) to be the number of lights on, contiguous from 0 to<br>// VTK_LIGHTING_NUMBER_OF_LIGHTS-1<br>// it has to be less than gl_MaxLights (typically 8)<br><br>// Per light computation<br>// (it means the scene ambient term is missing).<br>
// lightSource is usually as gl_LightSource[i]<br>void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,<br> gl_MaterialParameters m,<br> vec3 surfacePosEyeCoords,<br>
vec3 n,<br> bool twoSided,<br> inout vec4 cpri,<br> inout vec4 csec)<br>{<br> vec3 ldir;<br> vec3 h;<br>
float att;<br> float spot;<br> float shininessFactor;<br> vec3 wReverseRayDir=surfacePosEyeCoords;<br> <br> if(lightSource.position.w!=0.0)<br> {<br> // ldir=light direction<br> vec3 lightPos=lightSource.position.xyz/lightSource.position.w;<br>
ldir=lightPos-surfacePosEyeCoords;<br> float sqrDistance=dot(ldir,ldir);<br> ldir=normalize(ldir);<br> h=normalize(ldir+normalize(wReverseRayDir));<br> att=1.0/(lightSource.constantAttenuation+lightSource.linearAttenuation*sqrt(sqrDistance)+lightSource.quadraticAttenuation*sqrDistance);<br>
// USED<br> }<br> else<br> {<br> att=1.0;<br> ldir=lightSource.position.xyz;<br> ldir=normalize(ldir);<br> h=normalize(ldir+wReverseRayDir);<br> }<br> <br> if(att>0.0)<br> {<br> // USED<br>
if(lightSource.spotCutoff==180.0)<br> {<br> spot=1.0;<br> // NOT USED<br> }<br> else<br> {<br> // USED<br> <br> float coef=-dot(ldir,normalize(lightSource.spotDirection));<br>
if(coef>=lightSource.spotCosCutoff)<br> {<br> spot=pow(coef,lightSource.spotExponent);<br> // USED<br> }<br> else<br> {<br> spot=0.0;<br> // NOT USED<br> }<br>
}<br> if(spot>0.0)<br> {<br> // USED<br> <br> // LIT operation...<br> float nDotL=dot(n,ldir);<br> float nDotH=dot(n,h);<br> <br> // separate nDotL and nDotH for two-sided shading, otherwise we<br>
// get black spots.<br> <br> if(nDotL<0.0) // two-sided shading<br> {<br>// nDotL=-nDotL; // mostly NOT USED<br> nDotL=0.0;<br> }<br> <br> if(nDotH<0.0) // two-sided shading<br>
{<br>// nDotH=-nDotH; // mostly USED, except on the back face of the plane.<br> nDotH=0.0;<br> }<br> <br> // ambient term for this light<br> vec4 cpril=m.ambient*lightSource.ambient;// acm*adi<br>
<br>// cpri=cpril;<br>// return;<br> <br> // diffuse term for this light<br> if(nDotL>0.0)<br> {<br> // USED<br> cpril+=m.diffuse*lightSource.diffuse*nDotL; // dcm*dcli<br>
}<br> <br> <br> // specular term for this light<br> shininessFactor=pow(nDotH,m.shininess); // srm<br> <br> cpri+=att*spot*cpril;<br> <br> // scm*scli<br> csec+=att*spot*<br>
m.specular*lightSource.specular*shininessFactor;<br> <br> }<br> }<br>}<br><br>// Ignore Scene ambient. Useful in multipass, if the ambient was already<br>// taken into account in a previous pass.<br>
void initBlackColors(out vec4 cpri,<br>
out vec4 csec)<br>{<br> cpri=vec4(0.0,0.0,0.0,1.0);<br> csec=vec4(0.0,0.0,0.0,1.0);<br>}<br><br>void initColorsWithAmbient(gl_MaterialParameters m,<br> out vec4 cpri,<br> out vec4 csec)<br>
{<br> cpri=m.emission+m.ambient*gl_LightModel.ambient; // ecm+acm*acs<br> csec=vec4(0.0,0.0,0.0,1.0);<br>}<br><br>#ifdef VTK_LIGHTING_NUMBER_OF_LIGHTS<br><br>// This is convenience method to use in shader but you better do<br>
// this computation on the CPU and send the result as a uniform.<br><br>// True if any enabled light is a positional one.<br>bool needSurfacePositionInEyeCoordinates()<br>{<br> int i=0;<br> bool result=false;<br> while(!result && i<VTK_LIGHTING_NUMBER_OF_LIGHTS)<br>
{<br> result=gl_LightSource[i].position.w!=0.0;<br> ++i;<br> }<br> return result;<br>}<br><br>// Lighting computation based on a material m,<br>// a position on the surface expressed in eye coordinate (typically a vertex<br>
// position in a vertex shader, something interpolated in a fragment shader),<br>// a unit normal `n' to the surface in eye coordinates.<br>// Most of the components are in cpri (primary color), the specular<br>// component is in csec (secondary color).<br>
// Useful for blending color and textures.<br>void separateSpecularColor(gl_MaterialParameters m,<br> vec3 surfacePosEyeCoords,<br> vec3 n,<br> bool twoSided,<br>
out vec4 cpri,<br> out vec4 csec)<br>{<br> initColorsWithAmbient(m,cpri,csec);<br> <br> // For each light,<br> int i=0;<br> while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS) <br>
{<br> lightSeparateSpecularColor(gl_LightSource[i],m,surfacePosEyeCoords,n,<br> twoSided,cpri,csec);<br> ++i;<br> }<br>}<br><br>// Lighting computation based on a material m,<br>
// a position on the surface expressed in eye coordinate (typically a vertex<br>// position in a vertex shader, something interpolated in a fragment shader),<br>// a unit normal to the surface in eye coordinates.<br>// The result includes the specular component.<br>
vec4 singleColor(gl_MaterialParameters m,<br> vec3 surfacePosEyeCoords,<br> vec3 n,<br> bool twoSided)<br>{<br> vec4 cpri;<br> vec4 csec;<br> separateSpecularColor(m,surfacePosEyeCoords,n,twoSided,cpri,csec);<br>
return cpri+csec;<br>}<br><br>#endif<br><br><br><br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line 497<br>vtkShaderProgram2 (0x36bf250): a shader failed to compile. Its log is:<br>Fragment shader failed to compile with the following errors:<br>
ERROR: 0:19: error(#105) #version must occur before any other statement in the program<br>ERROR: error(#273) 1 compilation errors. No code generated<br><br>. Its source code is:<br>#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1<br>
// ============================================================================<br>//<br>// Program: Visualization Toolkit<br>// Module: vtkShadowMapPassShader_fs.glsl<br>//<br>// Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen<br>
// All rights reserved.<br>// See Copyright.txt or <a href="http://www.kitware.com/Copyright.htm" target="_blank">http://www.kitware.com/Copyright.htm</a> for details.<br>//<br>// This software is distributed WITHOUT ANY WARRANTY; without even<br>
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR<br>// PURPOSE. See the above copyright notice for more information.<br>//<br>// ============================================================================<br>
<br>// Fragment shader used by the shadow mapping render pass.<br><br>#version 110<br><br>// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by adding<br>// a line at the beginning like:<br>// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing<br>
// lights.<br><br>uniform sampler2DShadow shadowMaps[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>uniform sampler2D spotLightShape;<br><br>varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>
<br>void main(void)<br>{<br> gl_FragColor=vec4(0.0,0.0,0.0,0.0);<br> int i=0;<br> while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)<br> {<br> float factor=0.0;<br> if(shadowCoord[i].w>0.0)<br> {<br> vec2 projected=shadowCoord[i].xy/shadowCoord[i].w;<br>
if(projected.x>=0.0 && projected.x<=1.0<br> && projected.y>=0.0 && projected.y<=1.0)<br> {<br> factor=shadow2DProj(shadowMaps[i],shadowCoord[i]).x;<br> }<br>
}<br> vec4 colorFactor=texture2DProj(spotLightShape,shadowCoord[i])*factor;<br> gl_FragColor+=frontColors[i]*colorFactor.x;<br>// gl_FragColor+=frontColors[i]*factor;<br> ++i;<br> }<br> <br> gl_FragColor=clamp(gl_FragColor,0.0,1.0);<br>
<br> // we don't let the prop to execute its fragment shader because it<br> // already executed in the previous pass with none shadowing lights.<br> // propFuncFS();<br> <br> // gl_FragColor will be blending with framebuffer value containing other<br>
// lights contributions.<br> // use alpha_testing for black/dark color?<br>}<br><br><br><br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkOpenGLProperty.cxx, line 393<br>vtkOpenGLProperty (0x2b47e00): Couldn't build the shader program. At this point , it can be an error in a shader or a driver bug.<br>
<br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line 497<br>vtkShaderProgram2 (0x36bf250): a shader failed to compile. Its log is:<br>Vertex shader failed to compile with the following errors:<br>
ERROR: 0:19: error(#105) #version must occur before any other statement in the program<br>ERROR: error(#273) 1 compilation errors. No code generated<br><br>. Its source code is:<br>#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1<br>
// ============================================================================<br>//<br>// Program: Visualization Toolkit<br>// Module: vtkShadowMapPassShader_vs.glsl<br>//<br>// Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen<br>
// All rights reserved.<br>// See Copyright.txt or <a href="http://www.kitware.com/Copyright.htm" target="_blank">http://www.kitware.com/Copyright.htm</a> for details.<br>//<br>// This software is distributed WITHOUT ANY WARRANTY; without even<br>
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR<br>// PURPOSE. See the above copyright notice for more information.<br>//<br>// ============================================================================<br>
<br>// Vertex shader used by the shadow mapping render pass.<br><br>#version 110<br><br>// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by adding<br>// a line at the beginning like:<br>// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing<br>
// lights.<br><br><br>void propFuncVS();<br><br>// defined in vtkLighting_s.glsl<br><br>void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,<br> gl_MaterialParameters m,<br>
vec3 surfacePosEyeCoords,<br> vec3 n,<br> bool twoSided,<br> inout vec4 cpri,<br> inout vec4 csec);<br>
<br>void initBlackColors(out vec4 cpri,<br> out vec4 csec);<br><br><br>// input are<br>// uniform gl_TextureMatrix[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br><br>varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>
varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br><br>void main(void)<br>{<br> vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;<br> vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;<br> vec3 n=gl_NormalMatrix*gl_Normal;<br>
n=normalize(n);<br> <br> int i=0;<br> while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)<br> {<br> vec4 cpri;<br> vec4 csec;<br> initBlackColors(cpri,csec); // because ambient in previous pass.<br> <br> lightSeparateSpecularColor(gl_LightSource[i],gl_FrontMaterial,eyeCoords,n,<br>
false,cpri,csec);<br>// frontColors[i]=vec4(0.5,0.5,0.5,1.0); // cpri+csec;<br> <br>// frontColors[i]=gl_FrontMaterial.diffuse*gl_LightSource[i].diffuse;<br> <br> frontColors[i]=cpri; //+csec;<br>
<br> // we could have everything in just gl_TextureMatrix[i] but this would<br> // require to add code vtkOpenGLActor. Also the value of the uniform<br> // gl_TextureMatrix[i] would have to be changed on each actor.<br>
// gl_TextureMatrix[i] would be:<br> // scale_bias*projection_light[i]*view_light[i]*model<br> // and we would have just texCoord=gl_TextureMatrix[i]*gl_Vertex;<br> //<br> // gl_TextureMatrix[i] is actually:<br>
// scale_bias*projection_light[i]*view_light[i]*view_camera_inv<br> <br> vec4 texCoord=gl_TextureMatrix[i]*heyeCoords;<br> shadowCoord[i]=texCoord/texCoord.w;<br> ++i;<br> }<br> <br> // we have to use the fixed-pipeline transform to avoid mismatching with<br>
// other passes.<br> gl_Position=ftransform();<br> <br> // propFuncVS(); // opportunity for the prop to execute its vertex shader.<br> <br> <br> <br> // we don't initialize gl_FrontColor because we have an array of colors<br>
// in frontColors[].<br>}<br><br><br><br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line 497<br>vtkShaderProgram2 (0x36bf250): a shader failed to compile. Its log is:<br>Vertex shader failed to compile with the following errors:<br>
ERROR: 0:20: error(#105) #version must occur before any other statement in the program<br>ERROR: error(#273) 1 compilation errors. No code generated<br><br>. Its source code is:<br>#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1<br>
// ============================================================================<br>//<br>// Program: Visualization Toolkit<br>// Module: vtkLighting_s.glsl<br>//<br>// Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen<br>
// All rights reserved.<br>// See Copyright.txt or <a href="http://www.kitware.com/Copyright.htm" target="_blank">http://www.kitware.com/Copyright.htm</a> for details.<br>//<br>// This software is distributed WITHOUT ANY WARRANTY; without even<br>
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR<br>// PURPOSE. See the above copyright notice for more information.<br>//<br>// ============================================================================<br>
<br>// This file defines some lighting functions.<br>// They can be used either in a vertex or fragment shader.<br><br>#version 110<br><br>// Example in vertex shader:<br>// Reminder: two-sided/one-sided is controlled by GL_VERTEX_PROGRAM_TWO_SIDE<br>
//<br>// vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;<br>// vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;<br>// vec3 n=gl_Normalmatrix*gl_Normal;<br>// n=normalize(n);<br>// separateSpecularColor(gl_FrontMaterial,eyeCoords,n,gl_FrontColor,gl_FrontSecondaryColor);<br>
// If two-sided.<br>// separateSpecularColor(gl_BackMaterial,eyeCoords,n,gl_BackColor,gl_BackSecondaryColor);<br><br> // Typical:<br>// gl_FrontColor=singleColor(gl_FrontMaterial,eyeCoords,n);<br><br>// VTK_LIGHTING_NUMBER_OF_LIGHTS has to be defined (by shader source string<br>
// concatenation) to be the number of lights on, contiguous from 0 to<br>// VTK_LIGHTING_NUMBER_OF_LIGHTS-1<br>// it has to be less than gl_MaxLights (typically 8)<br><br>// Per light computation<br>// (it means the scene ambient term is missing).<br>
// lightSource is usually as gl_LightSource[i]<br>void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,<br> gl_MaterialParameters m,<br> vec3 surfacePosEyeCoords,<br>
vec3 n,<br> bool twoSided,<br> inout vec4 cpri,<br> inout vec4 csec)<br>{<br> vec3 ldir;<br> vec3 h;<br>
float att;<br> float spot;<br> float shininessFactor;<br> vec3 wReverseRayDir=surfacePosEyeCoords;<br> <br> if(lightSource.position.w!=0.0)<br> {<br> // ldir=light direction<br> vec3 lightPos=lightSource.position.xyz/lightSource.position.w;<br>
ldir=lightPos-surfacePosEyeCoords;<br> float sqrDistance=dot(ldir,ldir);<br> ldir=normalize(ldir);<br> h=normalize(ldir+normalize(wReverseRayDir));<br> att=1.0/(lightSource.constantAttenuation+lightSource.linearAttenuation*sqrt(sqrDistance)+lightSource.quadraticAttenuation*sqrDistance);<br>
// USED<br> }<br> else<br> {<br> att=1.0;<br> ldir=lightSource.position.xyz;<br> ldir=normalize(ldir);<br> h=normalize(ldir+wReverseRayDir);<br> }<br> <br> if(att>0.0)<br> {<br> // USED<br>
if(lightSource.spotCutoff==180.0)<br> {<br> spot=1.0;<br> // NOT USED<br> }<br> else<br> {<br> // USED<br> <br> float coef=-dot(ldir,normalize(lightSource.spotDirection));<br>
if(coef>=lightSource.spotCosCutoff)<br> {<br> spot=pow(coef,lightSource.spotExponent);<br> // USED<br> }<br> else<br> {<br> spot=0.0;<br> // NOT USED<br> }<br>
}<br> if(spot>0.0)<br> {<br> // USED<br> <br> // LIT operation...<br> float nDotL=dot(n,ldir);<br> float nDotH=dot(n,h);<br> <br> // separate nDotL and nDotH for two-sided shading, otherwise we<br>
// get black spots.<br> <br> if(nDotL<0.0) // two-sided shading<br> {<br>// nDotL=-nDotL; // mostly NOT USED<br> nDotL=0.0;<br> }<br> <br> if(nDotH<0.0) // two-sided shading<br>
{<br>// nDotH=-nDotH; // mostly USED, except on the back face of the plane.<br> nDotH=0.0;<br> }<br> <br> // ambient term for this light<br> vec4 cpril=m.ambient*lightSource.ambient;// acm*adi<br>
<br>// cpri=cpril;<br>// return;<br> <br> // diffuse term for this light<br> if(nDotL>0.0)<br> {<br> // USED<br> cpril+=m.diffuse*lightSource.diffuse*nDotL; // dcm*dcli<br>
}<br> <br> <br> // specular term for this light<br> shininessFactor=pow(nDotH,m.shininess); // srm<br> <br> cpri+=att*spot*cpril;<br> <br> // scm*scli<br> csec+=att*spot*<br>
m.specular*lightSource.specular*shininessFactor;<br> <br> }<br> }<br>}<br><br>// Ignore Scene ambient. Useful in multipass, if the ambient was already<br>// taken into account in a previous pass.<br>
void initBlackColors(out vec4 cpri,<br>
out vec4 csec)<br>{<br> cpri=vec4(0.0,0.0,0.0,1.0);<br> csec=vec4(0.0,0.0,0.0,1.0);<br>}<br><br>void initColorsWithAmbient(gl_MaterialParameters m,<br> out vec4 cpri,<br> out vec4 csec)<br>
{<br> cpri=m.emission+m.ambient*gl_LightModel.ambient; // ecm+acm*acs<br> csec=vec4(0.0,0.0,0.0,1.0);<br>}<br><br>#ifdef VTK_LIGHTING_NUMBER_OF_LIGHTS<br><br>// This is convenience method to use in shader but you better do<br>
// this computation on the CPU and send the result as a uniform.<br><br>// True if any enabled light is a positional one.<br>bool needSurfacePositionInEyeCoordinates()<br>{<br> int i=0;<br> bool result=false;<br> while(!result && i<VTK_LIGHTING_NUMBER_OF_LIGHTS)<br>
{<br> result=gl_LightSource[i].position.w!=0.0;<br> ++i;<br> }<br> return result;<br>}<br><br>// Lighting computation based on a material m,<br>// a position on the surface expressed in eye coordinate (typically a vertex<br>
// position in a vertex shader, something interpolated in a fragment shader),<br>// a unit normal `n' to the surface in eye coordinates.<br>// Most of the components are in cpri (primary color), the specular<br>// component is in csec (secondary color).<br>
// Useful for blending color and textures.<br>void separateSpecularColor(gl_MaterialParameters m,<br> vec3 surfacePosEyeCoords,<br> vec3 n,<br> bool twoSided,<br>
out vec4 cpri,<br> out vec4 csec)<br>{<br> initColorsWithAmbient(m,cpri,csec);<br> <br> // For each light,<br> int i=0;<br> while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS) <br>
{<br> lightSeparateSpecularColor(gl_LightSource[i],m,surfacePosEyeCoords,n,<br> twoSided,cpri,csec);<br> ++i;<br> }<br>}<br><br>// Lighting computation based on a material m,<br>
// a position on the surface expressed in eye coordinate (typically a vertex<br>// position in a vertex shader, something interpolated in a fragment shader),<br>// a unit normal to the surface in eye coordinates.<br>// The result includes the specular component.<br>
vec4 singleColor(gl_MaterialParameters m,<br> vec3 surfacePosEyeCoords,<br> vec3 n,<br> bool twoSided)<br>{<br> vec4 cpri;<br> vec4 csec;<br> separateSpecularColor(m,surfacePosEyeCoords,n,twoSided,cpri,csec);<br>
return cpri+csec;<br>}<br><br>#endif<br><br><br><br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line 497<br>vtkShaderProgram2 (0x36bf250): a shader failed to compile. Its log is:<br>Fragment shader failed to compile with the following errors:<br>
ERROR: 0:19: error(#105) #version must occur before any other statement in the program<br>ERROR: error(#273) 1 compilation errors. No code generated<br><br>. Its source code is:<br>#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1<br>
// ============================================================================<br>//<br>// Program: Visualization Toolkit<br>// Module: vtkShadowMapPassShader_fs.glsl<br>//<br>// Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen<br>
// All rights reserved.<br>// See Copyright.txt or <a href="http://www.kitware.com/Copyright.htm" target="_blank">http://www.kitware.com/Copyright.htm</a> for details.<br>//<br>// This software is distributed WITHOUT ANY WARRANTY; without even<br>
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR<br>// PURPOSE. See the above copyright notice for more information.<br>//<br>// ============================================================================<br>
<br>// Fragment shader used by the shadow mapping render pass.<br><br>#version 110<br><br>// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by adding<br>// a line at the beginning like:<br>// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing<br>
// lights.<br><br>uniform sampler2DShadow shadowMaps[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>uniform sampler2D spotLightShape;<br><br>varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>
<br>void main(void)<br>{<br> gl_FragColor=vec4(0.0,0.0,0.0,0.0);<br> int i=0;<br> while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)<br> {<br> float factor=0.0;<br> if(shadowCoord[i].w>0.0)<br> {<br> vec2 projected=shadowCoord[i].xy/shadowCoord[i].w;<br>
if(projected.x>=0.0 && projected.x<=1.0<br> && projected.y>=0.0 && projected.y<=1.0)<br> {<br> factor=shadow2DProj(shadowMaps[i],shadowCoord[i]).x;<br> }<br>
}<br> vec4 colorFactor=texture2DProj(spotLightShape,shadowCoord[i])*factor;<br> gl_FragColor+=frontColors[i]*colorFactor.x;<br>// gl_FragColor+=frontColors[i]*factor;<br> ++i;<br> }<br> <br> gl_FragColor=clamp(gl_FragColor,0.0,1.0);<br>
<br> // we don't let the prop to execute its fragment shader because it<br> // already executed in the previous pass with none shadowing lights.<br> // propFuncFS();<br> <br> // gl_FragColor will be blending with framebuffer value containing other<br>
// lights contributions.<br> // use alpha_testing for black/dark color?<br>}<br><br><br><br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkOpenGLProperty.cxx, line 393<br>vtkOpenGLProperty (0x2b47e00): Couldn't build the shader program. At this point , it can be an error in a shader or a driver bug.<br>
<br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line 497<br>vtkShaderProgram2 (0x36c6020): a shader failed to compile. Its log is:<br>Vertex shader failed to compile with the following errors:<br>
ERROR: 0:19: error(#105) #version must occur before any other statement in the program<br>ERROR: error(#273) 1 compilation errors. No code generated<br><br>. Its source code is:<br>#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1<br>
// ============================================================================<br>//<br>// Program: Visualization Toolkit<br>// Module: vtkShadowMapPassShader_vs.glsl<br>//<br>// Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen<br>
// All rights reserved.<br>// See Copyright.txt or <a href="http://www.kitware.com/Copyright.htm" target="_blank">http://www.kitware.com/Copyright.htm</a> for details.<br>//<br>// This software is distributed WITHOUT ANY WARRANTY; without even<br>
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR<br>// PURPOSE. See the above copyright notice for more information.<br>//<br>// ============================================================================<br>
<br>// Vertex shader used by the shadow mapping render pass.<br><br>#version 110<br><br>// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by adding<br>// a line at the beginning like:<br>// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing<br>
// lights.<br><br><br>void propFuncVS();<br><br>// defined in vtkLighting_s.glsl<br><br>void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,<br> gl_MaterialParameters m,<br>
vec3 surfacePosEyeCoords,<br> vec3 n,<br> bool twoSided,<br> inout vec4 cpri,<br> inout vec4 csec);<br>
<br>void initBlackColors(out vec4 cpri,<br> out vec4 csec);<br><br><br>// input are<br>// uniform gl_TextureMatrix[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br><br>varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>
varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br><br>void main(void)<br>{<br> vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;<br> vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;<br> vec3 n=gl_NormalMatrix*gl_Normal;<br>
n=normalize(n);<br> <br> int i=0;<br> while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)<br> {<br> vec4 cpri;<br> vec4 csec;<br> initBlackColors(cpri,csec); // because ambient in previous pass.<br> <br> lightSeparateSpecularColor(gl_LightSource[i],gl_FrontMaterial,eyeCoords,n,<br>
false,cpri,csec);<br>// frontColors[i]=vec4(0.5,0.5,0.5,1.0); // cpri+csec;<br> <br>// frontColors[i]=gl_FrontMaterial.diffuse*gl_LightSource[i].diffuse;<br> <br> frontColors[i]=cpri; //+csec;<br>
<br> // we could have everything in just gl_TextureMatrix[i] but this would<br> // require to add code vtkOpenGLActor. Also the value of the uniform<br> // gl_TextureMatrix[i] would have to be changed on each actor.<br>
// gl_TextureMatrix[i] would be:<br> // scale_bias*projection_light[i]*view_light[i]*model<br> // and we would have just texCoord=gl_TextureMatrix[i]*gl_Vertex;<br> //<br> // gl_TextureMatrix[i] is actually:<br>
// scale_bias*projection_light[i]*view_light[i]*view_camera_inv<br> <br> vec4 texCoord=gl_TextureMatrix[i]*heyeCoords;<br> shadowCoord[i]=texCoord/texCoord.w;<br> ++i;<br> }<br> <br> // we have to use the fixed-pipeline transform to avoid mismatching with<br>
// other passes.<br> gl_Position=ftransform();<br> <br> // propFuncVS(); // opportunity for the prop to execute its vertex shader.<br> <br> <br> <br> // we don't initialize gl_FrontColor because we have an array of colors<br>
// in frontColors[].<br>}<br><br><br><br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line 497<br>vtkShaderProgram2 (0x36c6020): a shader failed to compile. Its log is:<br>Vertex shader failed to compile with the following errors:<br>
ERROR: 0:20: error(#105) #version must occur before any other statement in the program<br>ERROR: error(#273) 1 compilation errors. No code generated<br><br>. Its source code is:<br>#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1<br>
// ============================================================================<br>//<br>// Program: Visualization Toolkit<br>// Module: vtkLighting_s.glsl<br>//<br>// Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen<br>
// All rights reserved.<br>// See Copyright.txt or <a href="http://www.kitware.com/Copyright.htm" target="_blank">http://www.kitware.com/Copyright.htm</a> for details.<br>//<br>// This software is distributed WITHOUT ANY WARRANTY; without even<br>
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR<br>// PURPOSE. See the above copyright notice for more information.<br>//<br>// ============================================================================<br>
<br>// This file defines some lighting functions.<br>// They can be used either in a vertex or fragment shader.<br><br>#version 110<br><br>// Example in vertex shader:<br>// Reminder: two-sided/one-sided is controlled by GL_VERTEX_PROGRAM_TWO_SIDE<br>
//<br>// vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;<br>// vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;<br>// vec3 n=gl_Normalmatrix*gl_Normal;<br>// n=normalize(n);<br>// separateSpecularColor(gl_FrontMaterial,eyeCoords,n,gl_FrontColor,gl_FrontSecondaryColor);<br>
// If two-sided.<br>// separateSpecularColor(gl_BackMaterial,eyeCoords,n,gl_BackColor,gl_BackSecondaryColor);<br><br> // Typical:<br>// gl_FrontColor=singleColor(gl_FrontMaterial,eyeCoords,n);<br><br>// VTK_LIGHTING_NUMBER_OF_LIGHTS has to be defined (by shader source string<br>
// concatenation) to be the number of lights on, contiguous from 0 to<br>// VTK_LIGHTING_NUMBER_OF_LIGHTS-1<br>// it has to be less than gl_MaxLights (typically 8)<br><br>// Per light computation<br>// (it means the scene ambient term is missing).<br>
// lightSource is usually as gl_LightSource[i]<br>void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,<br> gl_MaterialParameters m,<br> vec3 surfacePosEyeCoords,<br>
vec3 n,<br> bool twoSided,<br> inout vec4 cpri,<br> inout vec4 csec)<br>{<br> vec3 ldir;<br> vec3 h;<br>
float att;<br> float spot;<br> float shininessFactor;<br> vec3 wReverseRayDir=surfacePosEyeCoords;<br> <br> if(lightSource.position.w!=0.0)<br> {<br> // ldir=light direction<br> vec3 lightPos=lightSource.position.xyz/lightSource.position.w;<br>
ldir=lightPos-surfacePosEyeCoords;<br> float sqrDistance=dot(ldir,ldir);<br> ldir=normalize(ldir);<br> h=normalize(ldir+normalize(wReverseRayDir));<br> att=1.0/(lightSource.constantAttenuation+lightSource.linearAttenuation*sqrt(sqrDistance)+lightSource.quadraticAttenuation*sqrDistance);<br>
// USED<br> }<br> else<br> {<br> att=1.0;<br> ldir=lightSource.position.xyz;<br> ldir=normalize(ldir);<br> h=normalize(ldir+wReverseRayDir);<br> }<br> <br> if(att>0.0)<br> {<br> // USED<br>
if(lightSource.spotCutoff==180.0)<br> {<br> spot=1.0;<br> // NOT USED<br> }<br> else<br> {<br> // USED<br> <br> float coef=-dot(ldir,normalize(lightSource.spotDirection));<br>
if(coef>=lightSource.spotCosCutoff)<br> {<br> spot=pow(coef,lightSource.spotExponent);<br> // USED<br> }<br> else<br> {<br> spot=0.0;<br> // NOT USED<br> }<br>
}<br> if(spot>0.0)<br> {<br> // USED<br> <br> // LIT operation...<br> float nDotL=dot(n,ldir);<br> float nDotH=dot(n,h);<br> <br> // separate nDotL and nDotH for two-sided shading, otherwise we<br>
// get black spots.<br> <br> if(nDotL<0.0) // two-sided shading<br> {<br>// nDotL=-nDotL; // mostly NOT USED<br> nDotL=0.0;<br> }<br> <br> if(nDotH<0.0) // two-sided shading<br>
{<br>// nDotH=-nDotH; // mostly USED, except on the back face of the plane.<br> nDotH=0.0;<br> }<br> <br> // ambient term for this light<br> vec4 cpril=m.ambient*lightSource.ambient;// acm*adi<br>
<br>// cpri=cpril;<br>// return;<br> <br> // diffuse term for this light<br> if(nDotL>0.0)<br> {<br> // USED<br> cpril+=m.diffuse*lightSource.diffuse*nDotL; // dcm*dcli<br>
}<br> <br> <br> // specular term for this light<br> shininessFactor=pow(nDotH,m.shininess); // srm<br> <br> cpri+=att*spot*cpril;<br> <br> // scm*scli<br> csec+=att*spot*<br>
m.specular*lightSource.specular*shininessFactor;<br> <br> }<br> }<br>}<br><br>// Ignore Scene ambient. Useful in multipass, if the ambient was already<br>// taken into account in a previous pass.<br>
void initBlackColors(out vec4 cpri,<br>
out vec4 csec)<br>{<br> cpri=vec4(0.0,0.0,0.0,1.0);<br> csec=vec4(0.0,0.0,0.0,1.0);<br>}<br><br>void initColorsWithAmbient(gl_MaterialParameters m,<br> out vec4 cpri,<br> out vec4 csec)<br>
{<br> cpri=m.emission+m.ambient*gl_LightModel.ambient; // ecm+acm*acs<br> csec=vec4(0.0,0.0,0.0,1.0);<br>}<br><br>#ifdef VTK_LIGHTING_NUMBER_OF_LIGHTS<br><br>// This is convenience method to use in shader but you better do<br>
// this computation on the CPU and send the result as a uniform.<br><br>// True if any enabled light is a positional one.<br>bool needSurfacePositionInEyeCoordinates()<br>{<br> int i=0;<br> bool result=false;<br> while(!result && i<VTK_LIGHTING_NUMBER_OF_LIGHTS)<br>
{<br> result=gl_LightSource[i].position.w!=0.0;<br> ++i;<br> }<br> return result;<br>}<br><br>// Lighting computation based on a material m,<br>// a position on the surface expressed in eye coordinate (typically a vertex<br>
// position in a vertex shader, something interpolated in a fragment shader),<br>// a unit normal `n' to the surface in eye coordinates.<br>// Most of the components are in cpri (primary color), the specular<br>// component is in csec (secondary color).<br>
// Useful for blending color and textures.<br>void separateSpecularColor(gl_MaterialParameters m,<br> vec3 surfacePosEyeCoords,<br> vec3 n,<br> bool twoSided,<br>
out vec4 cpri,<br> out vec4 csec)<br>{<br> initColorsWithAmbient(m,cpri,csec);<br> <br> // For each light,<br> int i=0;<br> while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS) <br>
{<br> lightSeparateSpecularColor(gl_LightSource[i],m,surfacePosEyeCoords,n,<br> twoSided,cpri,csec);<br> ++i;<br> }<br>}<br><br>// Lighting computation based on a material m,<br>
// a position on the surface expressed in eye coordinate (typically a vertex<br>// position in a vertex shader, something interpolated in a fragment shader),<br>// a unit normal to the surface in eye coordinates.<br>// The result includes the specular component.<br>
vec4 singleColor(gl_MaterialParameters m,<br> vec3 surfacePosEyeCoords,<br> vec3 n,<br> bool twoSided)<br>{<br> vec4 cpri;<br> vec4 csec;<br> separateSpecularColor(m,surfacePosEyeCoords,n,twoSided,cpri,csec);<br>
return cpri+csec;<br>}<br><br>#endif<br><br><br><br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line 497<br>vtkShaderProgram2 (0x36c6020): a shader failed to compile. Its log is:<br>Fragment shader failed to compile with the following errors:<br>
ERROR: 0:19: error(#105) #version must occur before any other statement in the program<br>ERROR: error(#273) 1 compilation errors. No code generated<br><br>. Its source code is:<br>#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1<br>
// ============================================================================<br>//<br>// Program: Visualization Toolkit<br>// Module: vtkShadowMapPassShader_fs.glsl<br>//<br>// Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen<br>
// All rights reserved.<br>// See Copyright.txt or <a href="http://www.kitware.com/Copyright.htm" target="_blank">http://www.kitware.com/Copyright.htm</a> for details.<br>//<br>// This software is distributed WITHOUT ANY WARRANTY; without even<br>
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR<br>// PURPOSE. See the above copyright notice for more information.<br>//<br>// ============================================================================<br>
<br>// Fragment shader used by the shadow mapping render pass.<br><br>#version 110<br><br>// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by adding<br>// a line at the beginning like:<br>// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing<br>
// lights.<br><br>uniform sampler2DShadow shadowMaps[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>uniform sampler2D spotLightShape;<br><br>varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>
<br>void main(void)<br>{<br> gl_FragColor=vec4(0.0,0.0,0.0,0.0);<br> int i=0;<br> while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)<br> {<br> float factor=0.0;<br> if(shadowCoord[i].w>0.0)<br> {<br> vec2 projected=shadowCoord[i].xy/shadowCoord[i].w;<br>
if(projected.x>=0.0 && projected.x<=1.0<br> && projected.y>=0.0 && projected.y<=1.0)<br> {<br> factor=shadow2DProj(shadowMaps[i],shadowCoord[i]).x;<br> }<br>
}<br> vec4 colorFactor=texture2DProj(spotLightShape,shadowCoord[i])*factor;<br> gl_FragColor+=frontColors[i]*colorFactor.x;<br>// gl_FragColor+=frontColors[i]*factor;<br> ++i;<br> }<br> <br> gl_FragColor=clamp(gl_FragColor,0.0,1.0);<br>
<br> // we don't let the prop to execute its fragment shader because it<br> // already executed in the previous pass with none shadowing lights.<br> // propFuncFS();<br> <br> // gl_FragColor will be blending with framebuffer value containing other<br>
// lights contributions.<br> // use alpha_testing for black/dark color?<br>}<br><br><br><br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkOpenGLProperty.cxx, line 393<br>vtkOpenGLProperty (0x2b99710): Couldn't build the shader program. At this point , it can be an error in a shader or a driver bug.<br>
<br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line 497<br>vtkShaderProgram2 (0x36bf250): a shader failed to compile. Its log is:<br>Vertex shader failed to compile with the following errors:<br>
ERROR: 0:19: error(#105) #version must occur before any other statement in the program<br>ERROR: error(#273) 1 compilation errors. No code generated<br><br>. Its source code is:<br>#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1<br>
// ============================================================================<br>//<br>// Program: Visualization Toolkit<br>// Module: vtkShadowMapPassShader_vs.glsl<br>//<br>// Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen<br>
// All rights reserved.<br>// See Copyright.txt or <a href="http://www.kitware.com/Copyright.htm" target="_blank">http://www.kitware.com/Copyright.htm</a> for details.<br>//<br>// This software is distributed WITHOUT ANY WARRANTY; without even<br>
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR<br>// PURPOSE. See the above copyright notice for more information.<br>//<br>// ============================================================================<br>
<br>// Vertex shader used by the shadow mapping render pass.<br><br>#version 110<br><br>// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by adding<br>// a line at the beginning like:<br>// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing<br>
// lights.<br><br><br>void propFuncVS();<br><br>// defined in vtkLighting_s.glsl<br><br>void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,<br> gl_MaterialParameters m,<br>
vec3 surfacePosEyeCoords,<br> vec3 n,<br> bool twoSided,<br> inout vec4 cpri,<br> inout vec4 csec);<br>
<br>void initBlackColors(out vec4 cpri,<br> out vec4 csec);<br><br><br>// input are<br>// uniform gl_TextureMatrix[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br><br>varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>
varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br><br>void main(void)<br>{<br> vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;<br> vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;<br> vec3 n=gl_NormalMatrix*gl_Normal;<br>
n=normalize(n);<br> <br> int i=0;<br> while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)<br> {<br> vec4 cpri;<br> vec4 csec;<br> initBlackColors(cpri,csec); // because ambient in previous pass.<br> <br> lightSeparateSpecularColor(gl_LightSource[i],gl_FrontMaterial,eyeCoords,n,<br>
false,cpri,csec);<br>// frontColors[i]=vec4(0.5,0.5,0.5,1.0); // cpri+csec;<br> <br>// frontColors[i]=gl_FrontMaterial.diffuse*gl_LightSource[i].diffuse;<br> <br> frontColors[i]=cpri; //+csec;<br>
<br> // we could have everything in just gl_TextureMatrix[i] but this would<br> // require to add code vtkOpenGLActor. Also the value of the uniform<br> // gl_TextureMatrix[i] would have to be changed on each actor.<br>
// gl_TextureMatrix[i] would be:<br> // scale_bias*projection_light[i]*view_light[i]*model<br> // and we would have just texCoord=gl_TextureMatrix[i]*gl_Vertex;<br> //<br> // gl_TextureMatrix[i] is actually:<br>
// scale_bias*projection_light[i]*view_light[i]*view_camera_inv<br> <br> vec4 texCoord=gl_TextureMatrix[i]*heyeCoords;<br> shadowCoord[i]=texCoord/texCoord.w;<br> ++i;<br> }<br> <br> // we have to use the fixed-pipeline transform to avoid mismatching with<br>
// other passes.<br> gl_Position=ftransform();<br> <br> // propFuncVS(); // opportunity for the prop to execute its vertex shader.<br> <br> <br> <br> // we don't initialize gl_FrontColor because we have an array of colors<br>
// in frontColors[].<br>}<br><br><br><br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line 497<br>vtkShaderProgram2 (0x36bf250): a shader failed to compile. Its log is:<br>Vertex shader failed to compile with the following errors:<br>
ERROR: 0:20: error(#105) #version must occur before any other statement in the program<br>ERROR: error(#273) 1 compilation errors. No code generated<br><br>. Its source code is:<br>#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1<br>
// ============================================================================<br>//<br>// Program: Visualization Toolkit<br>// Module: vtkLighting_s.glsl<br>//<br>// Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen<br>
// All rights reserved.<br>// See Copyright.txt or <a href="http://www.kitware.com/Copyright.htm" target="_blank">http://www.kitware.com/Copyright.htm</a> for details.<br>//<br>// This software is distributed WITHOUT ANY WARRANTY; without even<br>
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR<br>// PURPOSE. See the above copyright notice for more information.<br>//<br>// ============================================================================<br>
<br>// This file defines some lighting functions.<br>// They can be used either in a vertex or fragment shader.<br><br>#version 110<br><br>// Example in vertex shader:<br>// Reminder: two-sided/one-sided is controlled by GL_VERTEX_PROGRAM_TWO_SIDE<br>
//<br>// vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;<br>// vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;<br>// vec3 n=gl_Normalmatrix*gl_Normal;<br>// n=normalize(n);<br>// separateSpecularColor(gl_FrontMaterial,eyeCoords,n,gl_FrontColor,gl_FrontSecondaryColor);<br>
// If two-sided.<br>// separateSpecularColor(gl_BackMaterial,eyeCoords,n,gl_BackColor,gl_BackSecondaryColor);<br><br> // Typical:<br>// gl_FrontColor=singleColor(gl_FrontMaterial,eyeCoords,n);<br><br>// VTK_LIGHTING_NUMBER_OF_LIGHTS has to be defined (by shader source string<br>
// concatenation) to be the number of lights on, contiguous from 0 to<br>// VTK_LIGHTING_NUMBER_OF_LIGHTS-1<br>// it has to be less than gl_MaxLights (typically 8)<br><br>// Per light computation<br>// (it means the scene ambient term is missing).<br>
// lightSource is usually as gl_LightSource[i]<br>void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,<br> gl_MaterialParameters m,<br> vec3 surfacePosEyeCoords,<br>
vec3 n,<br> bool twoSided,<br> inout vec4 cpri,<br> inout vec4 csec)<br>{<br> vec3 ldir;<br> vec3 h;<br>
float att;<br> float spot;<br> float shininessFactor;<br> vec3 wReverseRayDir=surfacePosEyeCoords;<br> <br> if(lightSource.position.w!=0.0)<br> {<br> // ldir=light direction<br> vec3 lightPos=lightSource.position.xyz/lightSource.position.w;<br>
ldir=lightPos-surfacePosEyeCoords;<br> float sqrDistance=dot(ldir,ldir);<br> ldir=normalize(ldir);<br> h=normalize(ldir+normalize(wReverseRayDir));<br> att=1.0/(lightSource.constantAttenuation+lightSource.linearAttenuation*sqrt(sqrDistance)+lightSource.quadraticAttenuation*sqrDistance);<br>
// USED<br> }<br> else<br> {<br> att=1.0;<br> ldir=lightSource.position.xyz;<br> ldir=normalize(ldir);<br> h=normalize(ldir+wReverseRayDir);<br> }<br> <br> if(att>0.0)<br> {<br> // USED<br>
if(lightSource.spotCutoff==180.0)<br> {<br> spot=1.0;<br> // NOT USED<br> }<br> else<br> {<br> // USED<br> <br> float coef=-dot(ldir,normalize(lightSource.spotDirection));<br>
if(coef>=lightSource.spotCosCutoff)<br> {<br> spot=pow(coef,lightSource.spotExponent);<br> // USED<br> }<br> else<br> {<br> spot=0.0;<br> // NOT USED<br> }<br>
}<br> if(spot>0.0)<br> {<br> // USED<br> <br> // LIT operation...<br> float nDotL=dot(n,ldir);<br> float nDotH=dot(n,h);<br> <br> // separate nDotL and nDotH for two-sided shading, otherwise we<br>
// get black spots.<br> <br> if(nDotL<0.0) // two-sided shading<br> {<br>// nDotL=-nDotL; // mostly NOT USED<br> nDotL=0.0;<br> }<br> <br> if(nDotH<0.0) // two-sided shading<br>
{<br>// nDotH=-nDotH; // mostly USED, except on the back face of the plane.<br> nDotH=0.0;<br> }<br> <br> // ambient term for this light<br> vec4 cpril=m.ambient*lightSource.ambient;// acm*adi<br>
<br>// cpri=cpril;<br>// return;<br> <br> // diffuse term for this light<br> if(nDotL>0.0)<br> {<br> // USED<br> cpril+=m.diffuse*lightSource.diffuse*nDotL; // dcm*dcli<br>
}<br> <br> <br> // specular term for this light<br> shininessFactor=pow(nDotH,m.shininess); // srm<br> <br> cpri+=att*spot*cpril;<br> <br> // scm*scli<br> csec+=att*spot*<br>
m.specular*lightSource.specular*shininessFactor;<br> <br> }<br> }<br>}<br><br>// Ignore Scene ambient. Useful in multipass, if the ambient was already<br>// taken into account in a previous pass.<br>
void initBlackColors(out vec4 cpri,<br>
out vec4 csec)<br>{<br> cpri=vec4(0.0,0.0,0.0,1.0);<br> csec=vec4(0.0,0.0,0.0,1.0);<br>}<br><br>void initColorsWithAmbient(gl_MaterialParameters m,<br> out vec4 cpri,<br> out vec4 csec)<br>
{<br> cpri=m.emission+m.ambient*gl_LightModel.ambient; // ecm+acm*acs<br> csec=vec4(0.0,0.0,0.0,1.0);<br>}<br><br>#ifdef VTK_LIGHTING_NUMBER_OF_LIGHTS<br><br>// This is convenience method to use in shader but you better do<br>
// this computation on the CPU and send the result as a uniform.<br><br>// True if any enabled light is a positional one.<br>bool needSurfacePositionInEyeCoordinates()<br>{<br> int i=0;<br> bool result=false;<br> while(!result && i<VTK_LIGHTING_NUMBER_OF_LIGHTS)<br>
{<br> result=gl_LightSource[i].position.w!=0.0;<br> ++i;<br> }<br> return result;<br>}<br><br>// Lighting computation based on a material m,<br>// a position on the surface expressed in eye coordinate (typically a vertex<br>
// position in a vertex shader, something interpolated in a fragment shader),<br>// a unit normal `n' to the surface in eye coordinates.<br>// Most of the components are in cpri (primary color), the specular<br>// component is in csec (secondary color).<br>
// Useful for blending color and textures.<br>void separateSpecularColor(gl_MaterialParameters m,<br> vec3 surfacePosEyeCoords,<br> vec3 n,<br> bool twoSided,<br>
out vec4 cpri,<br> out vec4 csec)<br>{<br> initColorsWithAmbient(m,cpri,csec);<br> <br> // For each light,<br> int i=0;<br> while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS) <br>
{<br> lightSeparateSpecularColor(gl_LightSource[i],m,surfacePosEyeCoords,n,<br> twoSided,cpri,csec);<br> ++i;<br> }<br>}<br><br>// Lighting computation based on a material m,<br>
// a position on the surface expressed in eye coordinate (typically a vertex<br>// position in a vertex shader, something interpolated in a fragment shader),<br>// a unit normal to the surface in eye coordinates.<br>// The result includes the specular component.<br>
vec4 singleColor(gl_MaterialParameters m,<br> vec3 surfacePosEyeCoords,<br> vec3 n,<br> bool twoSided)<br>{<br> vec4 cpri;<br> vec4 csec;<br> separateSpecularColor(m,surfacePosEyeCoords,n,twoSided,cpri,csec);<br>
return cpri+csec;<br>}<br><br>#endif<br><br><br><br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line 497<br>vtkShaderProgram2 (0x36bf250): a shader failed to compile. Its log is:<br>Fragment shader failed to compile with the following errors:<br>
ERROR: 0:19: error(#105) #version must occur before any other statement in the program<br>ERROR: error(#273) 1 compilation errors. No code generated<br><br>. Its source code is:<br>#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1<br>
// ============================================================================<br>//<br>// Program: Visualization Toolkit<br>// Module: vtkShadowMapPassShader_fs.glsl<br>//<br>// Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen<br>
// All rights reserved.<br>// See Copyright.txt or <a href="http://www.kitware.com/Copyright.htm" target="_blank">http://www.kitware.com/Copyright.htm</a> for details.<br>//<br>// This software is distributed WITHOUT ANY WARRANTY; without even<br>
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR<br>// PURPOSE. See the above copyright notice for more information.<br>//<br>// ============================================================================<br>
<br>// Fragment shader used by the shadow mapping render pass.<br><br>#version 110<br><br>// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by adding<br>// a line at the beginning like:<br>// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing<br>
// lights.<br><br>uniform sampler2DShadow shadowMaps[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>uniform sampler2D spotLightShape;<br><br>varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>
<br>void main(void)<br>{<br> gl_FragColor=vec4(0.0,0.0,0.0,0.0);<br> int i=0;<br> while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)<br> {<br> float factor=0.0;<br> if(shadowCoord[i].w>0.0)<br> {<br> vec2 projected=shadowCoord[i].xy/shadowCoord[i].w;<br>
if(projected.x>=0.0 && projected.x<=1.0<br> && projected.y>=0.0 && projected.y<=1.0)<br> {<br> factor=shadow2DProj(shadowMaps[i],shadowCoord[i]).x;<br> }<br>
}<br> vec4 colorFactor=texture2DProj(spotLightShape,shadowCoord[i])*factor;<br> gl_FragColor+=frontColors[i]*colorFactor.x;<br>// gl_FragColor+=frontColors[i]*factor;<br> ++i;<br> }<br> <br> gl_FragColor=clamp(gl_FragColor,0.0,1.0);<br>
<br> // we don't let the prop to execute its fragment shader because it<br> // already executed in the previous pass with none shadowing lights.<br> // propFuncFS();<br> <br> // gl_FragColor will be blending with framebuffer value containing other<br>
// lights contributions.<br> // use alpha_testing for black/dark color?<br>}<br><br><br><br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkOpenGLProperty.cxx, line 393<br>vtkOpenGLProperty (0x2b47e00): Couldn't build the shader program. At this point , it can be an error in a shader or a driver bug.<br>
<br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line 497<br>vtkShaderProgram2 (0x36c6020): a shader failed to compile. Its log is:<br>Vertex shader failed to compile with the following errors:<br>
ERROR: 0:19: error(#105) #version must occur before any other statement in the program<br>ERROR: error(#273) 1 compilation errors. No code generated<br><br>. Its source code is:<br>#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1<br>
// ============================================================================<br>//<br>// Program: Visualization Toolkit<br>// Module: vtkShadowMapPassShader_vs.glsl<br>//<br>// Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen<br>
// All rights reserved.<br>// See Copyright.txt or <a href="http://www.kitware.com/Copyright.htm" target="_blank">http://www.kitware.com/Copyright.htm</a> for details.<br>//<br>// This software is distributed WITHOUT ANY WARRANTY; without even<br>
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR<br>// PURPOSE. See the above copyright notice for more information.<br>//<br>// ============================================================================<br>
<br>// Vertex shader used by the shadow mapping render pass.<br><br>#version 110<br><br>// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by adding<br>// a line at the beginning like:<br>// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing<br>
// lights.<br><br><br>void propFuncVS();<br><br>// defined in vtkLighting_s.glsl<br><br>void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,<br> gl_MaterialParameters m,<br>
vec3 surfacePosEyeCoords,<br> vec3 n,<br> bool twoSided,<br> inout vec4 cpri,<br> inout vec4 csec);<br>
<br>void initBlackColors(out vec4 cpri,<br> out vec4 csec);<br><br><br>// input are<br>// uniform gl_TextureMatrix[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br><br>varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>
varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br><br>void main(void)<br>{<br> vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;<br> vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;<br> vec3 n=gl_NormalMatrix*gl_Normal;<br>
n=normalize(n);<br> <br> int i=0;<br> while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)<br> {<br> vec4 cpri;<br> vec4 csec;<br> initBlackColors(cpri,csec); // because ambient in previous pass.<br> <br> lightSeparateSpecularColor(gl_LightSource[i],gl_FrontMaterial,eyeCoords,n,<br>
false,cpri,csec);<br>// frontColors[i]=vec4(0.5,0.5,0.5,1.0); // cpri+csec;<br> <br>// frontColors[i]=gl_FrontMaterial.diffuse*gl_LightSource[i].diffuse;<br> <br> frontColors[i]=cpri; //+csec;<br>
<br> // we could have everything in just gl_TextureMatrix[i] but this would<br> // require to add code vtkOpenGLActor. Also the value of the uniform<br> // gl_TextureMatrix[i] would have to be changed on each actor.<br>
// gl_TextureMatrix[i] would be:<br> // scale_bias*projection_light[i]*view_light[i]*model<br> // and we would have just texCoord=gl_TextureMatrix[i]*gl_Vertex;<br> //<br> // gl_TextureMatrix[i] is actually:<br>
// scale_bias*projection_light[i]*view_light[i]*view_camera_inv<br> <br> vec4 texCoord=gl_TextureMatrix[i]*heyeCoords;<br> shadowCoord[i]=texCoord/texCoord.w;<br> ++i;<br> }<br> <br> // we have to use the fixed-pipeline transform to avoid mismatching with<br>
// other passes.<br> gl_Position=ftransform();<br> <br> // propFuncVS(); // opportunity for the prop to execute its vertex shader.<br> <br> <br> <br> // we don't initialize gl_FrontColor because we have an array of colors<br>
// in frontColors[].<br>}<br><br><br><br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line 497<br>vtkShaderProgram2 (0x36c6020): a shader failed to compile. Its log is:<br>Vertex shader failed to compile with the following errors:<br>
ERROR: 0:20: error(#105) #version must occur before any other statement in the program<br>ERROR: error(#273) 1 compilation errors. No code generated<br><br>. Its source code is:<br>#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1<br>
// ============================================================================<br>//<br>// Program: Visualization Toolkit<br>// Module: vtkLighting_s.glsl<br>//<br>// Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen<br>
// All rights reserved.<br>// See Copyright.txt or <a href="http://www.kitware.com/Copyright.htm" target="_blank">http://www.kitware.com/Copyright.htm</a> for details.<br>//<br>// This software is distributed WITHOUT ANY WARRANTY; without even<br>
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR<br>// PURPOSE. See the above copyright notice for more information.<br>//<br>// ============================================================================<br>
<br>// This file defines some lighting functions.<br>// They can be used either in a vertex or fragment shader.<br><br>#version 110<br><br>// Example in vertex shader:<br>// Reminder: two-sided/one-sided is controlled by GL_VERTEX_PROGRAM_TWO_SIDE<br>
//<br>// vec4 heyeCoords=gl_ModelViewMatrix*gl_Vertex;<br>// vec3 eyeCoords=heyeCoords.xyz/heyeCoords.w;<br>// vec3 n=gl_Normalmatrix*gl_Normal;<br>// n=normalize(n);<br>// separateSpecularColor(gl_FrontMaterial,eyeCoords,n,gl_FrontColor,gl_FrontSecondaryColor);<br>
// If two-sided.<br>// separateSpecularColor(gl_BackMaterial,eyeCoords,n,gl_BackColor,gl_BackSecondaryColor);<br><br> // Typical:<br>// gl_FrontColor=singleColor(gl_FrontMaterial,eyeCoords,n);<br><br>// VTK_LIGHTING_NUMBER_OF_LIGHTS has to be defined (by shader source string<br>
// concatenation) to be the number of lights on, contiguous from 0 to<br>// VTK_LIGHTING_NUMBER_OF_LIGHTS-1<br>// it has to be less than gl_MaxLights (typically 8)<br><br>// Per light computation<br>// (it means the scene ambient term is missing).<br>
// lightSource is usually as gl_LightSource[i]<br>void lightSeparateSpecularColor(gl_LightSourceParameters lightSource,<br> gl_MaterialParameters m,<br> vec3 surfacePosEyeCoords,<br>
vec3 n,<br> bool twoSided,<br> inout vec4 cpri,<br> inout vec4 csec)<br>{<br> vec3 ldir;<br> vec3 h;<br>
float att;<br> float spot;<br> float shininessFactor;<br> vec3 wReverseRayDir=surfacePosEyeCoords;<br> <br> if(lightSource.position.w!=0.0)<br> {<br> // ldir=light direction<br> vec3 lightPos=lightSource.position.xyz/lightSource.position.w;<br>
ldir=lightPos-surfacePosEyeCoords;<br> float sqrDistance=dot(ldir,ldir);<br> ldir=normalize(ldir);<br> h=normalize(ldir+normalize(wReverseRayDir));<br> att=1.0/(lightSource.constantAttenuation+lightSource.linearAttenuation*sqrt(sqrDistance)+lightSource.quadraticAttenuation*sqrDistance);<br>
// USED<br> }<br> else<br> {<br> att=1.0;<br> ldir=lightSource.position.xyz;<br> ldir=normalize(ldir);<br> h=normalize(ldir+wReverseRayDir);<br> }<br> <br> if(att>0.0)<br> {<br> // USED<br>
if(lightSource.spotCutoff==180.0)<br> {<br> spot=1.0;<br> // NOT USED<br> }<br> else<br> {<br> // USED<br> <br> float coef=-dot(ldir,normalize(lightSource.spotDirection));<br>
if(coef>=lightSource.spotCosCutoff)<br> {<br> spot=pow(coef,lightSource.spotExponent);<br> // USED<br> }<br> else<br> {<br> spot=0.0;<br> // NOT USED<br> }<br>
}<br> if(spot>0.0)<br> {<br> // USED<br> <br> // LIT operation...<br> float nDotL=dot(n,ldir);<br> float nDotH=dot(n,h);<br> <br> // separate nDotL and nDotH for two-sided shading, otherwise we<br>
// get black spots.<br> <br> if(nDotL<0.0) // two-sided shading<br> {<br>// nDotL=-nDotL; // mostly NOT USED<br> nDotL=0.0;<br> }<br> <br> if(nDotH<0.0) // two-sided shading<br>
{<br>// nDotH=-nDotH; // mostly USED, except on the back face of the plane.<br> nDotH=0.0;<br> }<br> <br> // ambient term for this light<br> vec4 cpril=m.ambient*lightSource.ambient;// acm*adi<br>
<br>// cpri=cpril;<br>// return;<br> <br> // diffuse term for this light<br> if(nDotL>0.0)<br> {<br> // USED<br> cpril+=m.diffuse*lightSource.diffuse*nDotL; // dcm*dcli<br>
}<br> <br> <br> // specular term for this light<br> shininessFactor=pow(nDotH,m.shininess); // srm<br> <br> cpri+=att*spot*cpril;<br> <br> // scm*scli<br> csec+=att*spot*<br>
m.specular*lightSource.specular*shininessFactor;<br> <br> }<br> }<br>}<br><br>// Ignore Scene ambient. Useful in multipass, if the ambient was already<br>// taken into account in a previous pass.<br>
void initBlackColors(out vec4 cpri,<br>
out vec4 csec)<br>{<br> cpri=vec4(0.0,0.0,0.0,1.0);<br> csec=vec4(0.0,0.0,0.0,1.0);<br>}<br><br>void initColorsWithAmbient(gl_MaterialParameters m,<br> out vec4 cpri,<br> out vec4 csec)<br>
{<br> cpri=m.emission+m.ambient*gl_LightModel.ambient; // ecm+acm*acs<br> csec=vec4(0.0,0.0,0.0,1.0);<br>}<br><br>#ifdef VTK_LIGHTING_NUMBER_OF_LIGHTS<br><br>// This is convenience method to use in shader but you better do<br>
// this computation on the CPU and send the result as a uniform.<br><br>// True if any enabled light is a positional one.<br>bool needSurfacePositionInEyeCoordinates()<br>{<br> int i=0;<br> bool result=false;<br> while(!result && i<VTK_LIGHTING_NUMBER_OF_LIGHTS)<br>
{<br> result=gl_LightSource[i].position.w!=0.0;<br> ++i;<br> }<br> return result;<br>}<br><br>// Lighting computation based on a material m,<br>// a position on the surface expressed in eye coordinate (typically a vertex<br>
// position in a vertex shader, something interpolated in a fragment shader),<br>// a unit normal `n' to the surface in eye coordinates.<br>// Most of the components are in cpri (primary color), the specular<br>// component is in csec (secondary color).<br>
// Useful for blending color and textures.<br>void separateSpecularColor(gl_MaterialParameters m,<br> vec3 surfacePosEyeCoords,<br> vec3 n,<br> bool twoSided,<br>
out vec4 cpri,<br> out vec4 csec)<br>{<br> initColorsWithAmbient(m,cpri,csec);<br> <br> // For each light,<br> int i=0;<br> while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS) <br>
{<br> lightSeparateSpecularColor(gl_LightSource[i],m,surfacePosEyeCoords,n,<br> twoSided,cpri,csec);<br> ++i;<br> }<br>}<br><br>// Lighting computation based on a material m,<br>
// a position on the surface expressed in eye coordinate (typically a vertex<br>// position in a vertex shader, something interpolated in a fragment shader),<br>// a unit normal to the surface in eye coordinates.<br>// The result includes the specular component.<br>
vec4 singleColor(gl_MaterialParameters m,<br> vec3 surfacePosEyeCoords,<br> vec3 n,<br> bool twoSided)<br>{<br> vec4 cpri;<br> vec4 csec;<br> separateSpecularColor(m,surfacePosEyeCoords,n,twoSided,cpri,csec);<br>
return cpri+csec;<br>}<br><br>#endif<br><br><br><br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkShaderProgram2.cxx, line 497<br>vtkShaderProgram2 (0x36c6020): a shader failed to compile. Its log is:<br>Fragment shader failed to compile with the following errors:<br>
ERROR: 0:19: error(#105) #version must occur before any other statement in the program<br>ERROR: error(#273) 1 compilation errors. No code generated<br><br>. Its source code is:<br>#define VTK_LIGHTING_NUMBER_OF_LIGHTS 1<br>
// ============================================================================<br>//<br>// Program: Visualization Toolkit<br>// Module: vtkShadowMapPassShader_fs.glsl<br>//<br>// Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen<br>
// All rights reserved.<br>// See Copyright.txt or <a href="http://www.kitware.com/Copyright.htm" target="_blank">http://www.kitware.com/Copyright.htm</a> for details.<br>//<br>// This software is distributed WITHOUT ANY WARRANTY; without even<br>
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR<br>// PURPOSE. See the above copyright notice for more information.<br>//<br>// ============================================================================<br>
<br>// Fragment shader used by the shadow mapping render pass.<br><br>#version 110<br><br>// NOTE: this shader is concatened on the fly by vtkShadowMapPass.cxx by adding<br>// a line at the beginning like:<br>// #define VTK_LIGHTING_NUMBER_OF_LIGHTS equal to the number of shadowing<br>
// lights.<br><br>uniform sampler2DShadow shadowMaps[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>uniform sampler2D spotLightShape;<br><br>varying vec4 shadowCoord[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>varying vec4 frontColors[VTK_LIGHTING_NUMBER_OF_LIGHTS];<br>
<br>void main(void)<br>{<br> gl_FragColor=vec4(0.0,0.0,0.0,0.0);<br> int i=0;<br> while(i<VTK_LIGHTING_NUMBER_OF_LIGHTS)<br> {<br> float factor=0.0;<br> if(shadowCoord[i].w>0.0)<br> {<br> vec2 projected=shadowCoord[i].xy/shadowCoord[i].w;<br>
if(projected.x>=0.0 && projected.x<=1.0<br> && projected.y>=0.0 && projected.y<=1.0)<br> {<br> factor=shadow2DProj(shadowMaps[i],shadowCoord[i]).x;<br> }<br>
}<br> vec4 colorFactor=texture2DProj(spotLightShape,shadowCoord[i])*factor;<br> gl_FragColor+=frontColors[i]*colorFactor.x;<br>// gl_FragColor+=frontColors[i]*factor;<br> ++i;<br> }<br> <br> gl_FragColor=clamp(gl_FragColor,0.0,1.0);<br>
<br> // we don't let the prop to execute its fragment shader because it<br> // already executed in the previous pass with none shadowing lights.<br> // propFuncFS();<br> <br> // gl_FragColor will be blending with framebuffer value containing other<br>
// lights contributions.<br> // use alpha_testing for black/dark color?<br>}<br><br>ERROR: In /home/paulo/Desktop/vtk/VTK/Rendering/vtkOpenGLProperty.cxx, line 393<br>vtkOpenGLProperty (0x2b99710): Couldn't build the shader program. At this point , it can be an error in a shader or a driver bug.<br>
<br><br>
</div>