How to set custom shader with VTK 8.1(C++)

Hi,everyone
How can i set custom shader with VTK8.1?
I know it’s probably using vtkShaderProgram,but i can’t find any example.
Could you please provide insights for achieving this? Your guidance would be greatly appreciated.

Hello,

To set shaders for your mapper in VTK 8.1, please take a look at Rendering/OpenGL2/Testing/Cxx/TestUserShader.cxx · v8.1.0 · VTK / VTK · GitLab and Rendering/OpenGL2/Testing/Cxx/TestUserShader2.cxx · v8.1.0 · VTK / VTK · GitLab .

best,

PC

Thanks for your reply.
I can’t find the method of AddShaderReplacement,but i will try SetVertexShaderCode and SetFragmentShaderCode.
Hope it works.
Thanks again for your help

Hello,

AddShaderReplacement() belongs to the vtkOpenGLShaderProperty class, which was introduced in VTK 9.

best,

PC

Hello,
Thanks for your reply.
I use AddVertexShaderReplacement and AddFragmentShaderReplacement in VTK(9.3.0), which can work well.But while replaced with SetFragmentShaderCode and SetVertexShaderCode, if i set opacity and get closer to the model, it will be low FPS.
In NVIDIA Nsight Graphics, i find this:


glClear() and Draw many times, could you tell me what’s wrong with it.
It will have the same issue in VTK(8.1.0).
Any reply would be greatly appreciated

Sorry,i found this was a Depthpeeling problem, I did not set the reference in the shader

How do I set the uniform attribute in VTK(8.1.0).
The method of SetUniform is only found in vtkShaderProgram, but i don’t know how to use vtkShaderProgram.No other method related to ShaderProgram was found.
Any reply would be greatly appreciated