shawn
June 6, 2024, 1:33pm
1
Hey all,
Sorry if this is a really simple question, I am working with Paraview (Paraview uses the VTK toolkit) and attempting to do a replacement shader, currently my code looks like this
{
"type": "fragment",
"original": "//VTK::Light::Impl",
"replacement": "gl_FragData[0] = vec4(1.0,0.0,0.0,1.0);"
}
I understand that what I am doing is replacing (I think the main function?) of VTK::Light but I am not really too sure what VTK::Light is. Is there any source code for that and how would I find it?
sankhesh
(Sankhesh Jhaveri)
June 6, 2024, 1:55pm
2
Hi @shawn ,
As you’ve noticed VTK’s mappers use a dynamic shader generation approach where we start with an empty shader file with some pre-defined tags like //VTK::Light::Impl
.
A quick way to dump out the shader code at run time is to introduce an error, like a syntax error.
So, something like
{
"type": "vertex",
"original": "//VTK::Picking::Impl",
"replacement": "My syntax error;
//VTK::Picking::Impl"
}
would yield
ERROR: In vtkShaderProgram.cxx, line 427
vtkShaderProgram (000001807CFD0A90): 1: #version 150
2: #ifndef GL_ES
3: #define highp
4: #define mediump
5: #define lowp
6: #define texelFetchBuffer texelFetch
7: #endif // GL_ES
8: #define attribute in
9: #define varying out
10:
11:
12: // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
13: // SPDX-License-Identifier: BSD-3-Clause
14:
15: in vec4 vertexMC;
16:
17:
18:
19: // frag position in VC
20: out vec4 vertexVCVSOutput;
21:
22: // optional normal declaration
23: //VTK::Normal::Dec
24: in vec3 normalMC;
25: uniform mat3 normalMatrix;
26: out vec3 normalVCVSOutput;
27:
28: // extra lighting parameters
29: //VTK::Light::Dec
30:
31: // Texture coordinates
32: //VTK::TCoord::Dec
33:
34: // material property values
35: //VTK::Color::Dec
36:
37: // clipping plane vars
38: //VTK::Clip::Dec
39:
40: // camera and actor matrix values
41: uniform mat4 MCDCMatrix;
42: uniform mat4 MCVCMatrix;
43:
44: // Apple Bug
45: //VTK::PrimID::Dec
46:
47: // Value raster
48: //VTK::ValuePass::Dec
49:
50: // picking support
51: //VTK::Picking::Dec
52:
53: // Surface with edges on GLES 3.0
54: //VTK::EdgesGLES30::Dec
55:
56: // PointSize on GLES 3.0
57: //VTK::PointSizeGLES30::Dec
58:
59: // LineWidth on GLES 3.0
60: //VTK::LineWidthGLES30::Dec
61:
62: void main()
63: {
64: //VTK::CustomBegin::Impl
65:
66: //VTK::PointSizeGLES30::Impl
67:
68: //VTK::Color::Impl
69:
70: normalVCVSOutput = normalMatrix * normalMC;
71: //VTK::Normal::Impl
72:
73: //VTK::TCoord::Impl
74:
75: //VTK::Clip::Impl
76:
77: //VTK::PrimID::Impl
78:
79: vertexVCVSOutput = MCVCMatrix * vertexMC;
80: gl_Position = MCDCMatrix * vertexMC;
81:
82:
83: //VTK::LineWidthGLES30::Impl
84:
85: //VTK::ValuePass::Impl
86:
87: //VTK::Light::Impl
88:
89: My syntax error;
90: //VTK::Picking::Impl
91:
92: //VTK::CustomEnd::Impl
93:
94: //VTK::EdgesGLES30::Impl
95: }
ERROR: In vtkShaderProgram.cxx, line 428
vtkShaderProgram (000001807CFD0A90): 0(89) : error C0000: syntax error, unexpected ';', expecting "::" at token ";"
That should give you an idea of what the final generated shader code looks like. If you need to drill down to what the in-built tag replacement for a particular tag is, you’d have to browse through the mapper code. For example: https://gitlab.kitware.com/vtk/vtk/-/blob/66096615a1b90be9f401bfefea77ceb4e2189fae/Rendering/OpenGL2/vtkOpenGLPolyDataMapper.cxx#L620-627 is the default replacement for //VTK::Edges::Dec
.
Shaders in VTK is an old wiki page that describes the logic behind these tags.
shawn
June 6, 2024, 2:01pm
3
This is amazing information, thank you so much. I will be going through this and asking any questions I have after.
shawn
June 6, 2024, 2:42pm
4
Let me see if I did this correctly, would the replacement tag for //VTK::Light::Dec
be and this would be considered all the code in VTK::Light::Impl
?
https://gitlab.kitware.com/vtk/vtk/-/blob/66096615a1b90be9f401bfefea77ceb4e2189fae/Rendering/OpenGL2/vtkOpenGLPolyDataMapper.cxx#L1104-1465 ?