I have some code that reads a .vtp file with vtkXMLPolyDataReader that contains lines. I can run the code and see the lines with my desktop app, but when I compile it to WebAssembly I get the following error when running in the browser:
ERROR: In /work/src/Rendering/OpenGL2/vtkShaderProgram.cxx, line 498
put_char @ SwisRadar.js:2270
SwisRadar.js:2270 vtkShaderProgram (0x705458): Links failed: FRAGMENT varying clipDistancesGSOutput does not match any VERTEX varying
put_char @ SwisRadar.js:2270
I have attached the .vtp file I am using as a zipped file.koax_colines.zip (3.5 MB)
I have discovered that if I don’t add my clipping planes collection (2 clipping planes) to the vtkPolyDataMapper the lines render correctly. Looks like a problem with using clipping planes in WebAssembly VTK.
Firefox is giving a little more descriptive error:
ERROR: In /work/src/Rendering/OpenGL2/vtkShaderProgram.cxx, line 498 SwisRadar.js:2270:16
WebGL warning: linkProgram: Varying clipDistancesGSOutput has static-use in the frag shader, but is undeclared in the vert shader. SwisRadar.js:11104:13
vtkShaderProgram (0x70f4e0): Links failed: Varying clipDistancesGSOutput has static-use in the frag shader, but is undeclared in the vert shader.
vtkShaderProgram::Substitute(FSSource, "//VTK::Clip::Dec",
"uniform int numClipPlanes;\n"
"in float clipDistancesVSOutput[6];");
vtkShaderProgram::Substitute(FSSource, "//VTK::Clip::Impl",
"for (int planeNum = 0; planeNum < numClipPlanes; planeNum++)\n"
" {\n"
" if (clipDistancesVSOutput[planeNum] < 0.0) discard;\n"
" }\n");
}
It looks like the fragment shader is also expecting clipDistancesVSOutput as an input, but if a geometry shader is used it is outputting clipDistancesGSOutput. I am going to try to modify the code so the geometry shader also outputs clipDistancesVSOutput instead of clipDistancesGSOutput.
Can anybody else verify if this seems like a bug in VTK?
Below is the shader code that is causing the error. Vertex shader is first, followed by geometry shader, and then the fragment shader. Can anybody that knows glsl better than me figure this out?
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.
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.
=========================================================================/
// Template for the polydata mappers geometry shader
// VC position of this fragment
//VTK::PositionVC::Dec
// primitiveID
//VTK::PrimID::Dec
// optional color passed in from the vertex shader, vertexColor
//VTK::Color::Dec
// optional surface normal declaration
//VTK::Normal::Dec
// extra lighting parameters
//VTK::Light::Dec
// Texture coordinates
//VTK::TCoord::Dec
// picking support
//VTK::Picking::Dec
// Depth Peeling Support
//VTK::DepthPeeling::Dec
// clipping plane vars
uniform int numClipPlanes;
uniform vec4 clipPlanes[6];
in vec4 clipVertexMC;
out float clipDistancesGSOutput[6];
void main()
{
// compute the lines direction
vec2 normal = normalize(
gl_in[1].gl_Position.xy/gl_in[1].gl_Position.w -
gl_in[0].gl_Position.xy/gl_in[0].gl_Position.w);
// rotate 90 degrees
normal = vec2(-1.0normal.y,normal.x);
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.
=========================================================================/
// Template for the polydata mappers fragment shader
uniform int PrimitiveIDOffset;
// VC position of this fragment
//VTK::PositionVC::Dec
// Camera prop
uniform int cameraParallel;
// optional color passed in from the vertex shader, vertexColor
uniform float ambientIntensity; // the material ambient
uniform float diffuseIntensity; // the material diffuse
uniform float opacityUniform; // the fragment opacity
uniform vec3 ambientColorUniform; // ambient color
uniform vec3 diffuseColorUniform; // diffuse color
// optional surface normal declaration
//VTK::Normal::Dec
// extra lighting parameters
uniform vec3 lightColor0;
// Texture maps
//VTK::TMap::Dec
// Texture coordinates
//VTK::TCoord::Dec
// picking support
//VTK::Picking::Dec
// Depth Peeling Support
//VTK::DepthPeeling::Dec
// clipping plane vars
uniform int numClipPlanes;
in float clipDistancesVSOutput[6];
Ahhhhh. Sorry for the repeated posts, but I just discovered that WebGL doesn’t support geometry shaders! Is there an easy way to tell the vtkOpenGLPolyDataMapper to not use geometry shaders?
Ok, I finally got it to work. I put an #ifdef check for Emscripten and write an empty string to the geometry shader if it is defined.
I then ran into a problem with the vertex and fragment shader code not having the uniform numClipPlanes at the same precision. After some research I discovered that in GLES, if the uniform in the fragment shader is defined as an int, then it must be prefixed with highp.
Not sure if my changes should be included in the main VTK source or not?
I’ll try catching up on this next week. We do want to incorporate fixes for shader code to make it work with WebGL (usually webgl is a bit more picky but the fixes tend to be easy)
Hi, I would like to ask a few questions about shaders.
First,Did you define the parameters in the code of the shader you presented yourself?
E.g in FS // extra lighting parameters uniform vec3 lightColor0; // clipping plane vars uniform int numClipPlanes; in float clipDistancesVSOutput[6];
Second,Do you know how to get vtk’s own shader to get external data? I can only replace my own shader with Polydatamapper now?
Looking forward to your reply!