View vtkOpenGLShaderCache substitutions and compile error message

Hi all,

I’m going a bit crazy trying to figure out a compilation issue on MacOS. I know OpenGL isn’t supported anymore… but most of our code has been working great except for this one shader that I am trying to debug. Using C++, Qt 5.6, and VTK 8.0.

First problem, my actual OpenGL version is 4.1 in “Core” mode, but my code always run with the compatibility version which is OpenGL ES 2.1 and only supports GLSL 1.20 (obtained from GL_SHADING_LANGUAGE_VERSION). I suspect some version issue with the new shader code as it works on different OS / OpenGL versions.

The C++ code extend vtkGPUVolumeRayCastMapper and creates a shader like this:

this->Impl->ShaderProgram = this->Impl->ShaderCache->ReadyShaderProgram(vertexShader.c_str(), fragmentShader.c_str(), "");

if (!this->Impl->ShaderProgram || !this->Impl->ShaderProgram->GetCompiled()) {
    qDebug() << "Shader failed to compile.";
}

and the shader looks like this:

//VTK::System::Dec

vec4 g_fragColor = vec4(0.0);

vec3 g_dataPos;
vec3 g_dirStep;
float g_rayStepLength;
vec4 g_srcColor;
vec4 g_eyePosObj;
bool g_exit;
uniform vec4 in_volume_scale;
uniform vec4 in_volume_bias;

//VTK::Output::Dec
etc...

I’m not seeing any information other than the ShaderProgram isn’t created. So I’m trying to run the code in glslviewer to debug them and get error messages, but obviously with the //VTK:: substitution it doesn’t compile…

So my questions are:

  1. Can I get actual error messages / information on why the shader failed to compile from ShaderCache->ReadyShaderProgram()?
  2. Can I see what has the cache replaced the //VTK::System::Dec and //VTK::Output::Dec tags with and output the final shader that VTK runs so that I can run it somewhere else?

Again, apologize if I am missing something obvious, I’m pretty new to VTK/GLSL in general.

Thanks

The vertex and fragment shaders are dynamically generated based on the various options provided to the mapper. To print the full shader code, you can just print the shader strings right before the call to ReadyShaderProgram at the very end of vtkOpenGLGPUVolumeRayCastMapper::BuildShader

Thanks for your answer Sankhesh!

I am printing the fragmentShader string right before the ReadyShaderProgram call, but the shader string still has the //VTK::System::Dec not substituted. I would like to know what #version tag this gets replaced with. Is that possible?

Ah, I see.

That replacement is done in vtkOpenGLShaderCache::ReplaceShaderValues

Hi! How should I print the source code of the shader in vtk.js?
Is it also through the ShaderCache.readyShaderProgramArray() method?
I tried it and it didn’t work. I customize my shader by replacing the code, and I intentionally write a mistake when replacing, so that the shader reports an error on the console, so that I can see the complete shader code.

Adding a replacement with an intentional error is fine to print out the source code. In vtk-js the replacement happens via vtkShaderProgram.substitute

Thanks for your advice!