0

I am trying to render a transparent object with OpenGL. But as you can see in the image, faces are messed up. I don't think that is due to the normal vectors because the non-transparent mesh looks fine. enter image description here

I am using:

glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

and my fragment shader is:

#version 440 core
in vec3 frag_normal;
uniform vec3 color;
uniform float opacity;
void main()
{
    vec3 ambientLightIntensity = vec3(0.4f, 0.4f, 0.4f);
    vec3 sunLightIntensity = vec3(0.4f, 0.4f, 0.4f);
    vec3 sunLightDirection = normalize(vec3(0.0f, 0.0f, 1.0f));
    vec3 lightIntensity = ambientLightIntensity + sunLightIntensity * max(dot(frag_normal, sunLightDirection), 0.0f);
    FragColor = vec4(color.x, color.y, color.z, opacity) * vec4(lightIntensity, 1.0f);
}
Hamid
  • 137
  • 1
  • 5
  • 3
    Naive transparency only works if triangles are ordered back to front. Sorting them is not practical, look up "order-independent transparency". – HolyBlackCat Aug 05 '21 at 15:46

0 Answers0