I used my own defined shader code in vtk and passed it into the “vtkOpenGLActor”. What I wanted to achieve was a semi transparent effect on the model, but the rendering result was unexpected. When the camera moved to certain angles, the model suddenly became opaque and accompanied by problems like scan lines appearing on the model. I am not sure what the reason is
std::string vShader = R"(
#version 150 core
#define attribute in
#define varying out
in vec4 vertexMC;
in vec3 normalMC;
uniform mat4 MCDCMatrix;
uniform mat4 MCVCMatrix;
uniform mat3 normalMatrix;
out vec4 ViewPos;
out vec3 ViewNormal;
void main()
{
ViewPos = MCVCMatrix * vertexMC;
ViewNormal = normalMatrix * normalMC;
gl_Position = MCDCMatrix * vertexMC;
}
)";
std::string fShader = R"(
#version 150 core
#define varying in
out vec4 fragOutput0;
in vec4 ViewPos;
in vec3 ViewNormal;
uniform float opacity;
void main()
{
vec3 N = normalize(ViewNormal);
vec3 V = normalize(-ViewPos.xyz);
if(gl_FrontFacing == false){ N = -N;}
float ndv = clamp(dot(N,V),0,1);
vec4 color = vec4( vec3(0.4, 0.7392, 0.3667) * ndv, opacity);
fragOutput0 = color;
}
)";
Actor->GetShaderProperty()->SetVertexShaderCode(vShader.c_str());
Actor->GetShaderProperty()->SetFragmentShaderCode(fShader.c_str());
Actor->GetShaderProperty()->GetFragmentCustomUniforms()->SetUniformf("opacity", 0.7);