0

I have managed to get a transparent cube using

glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

and in shader.frag:

gl_FragColor = vec4(texture2D(TextureMap_uniform, uv).xyz,0.5);

but now I would like the solid model I am moving around above the transparent cubes to be opaque (the transparency is applied to everything at the moment). Can anyone point me in the right direction?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Weaver
  • 145
  • 8
  • 1
    It's the `0.5` in the `gl_FragColor = vec4(texture2D(TextureMap_uniform, uv).xyz,0.5);` which makes them half-transparent. Change that (e.g. using a uniform instead like recommended in the answer) to modify the transparency (0.0 -> invisible, 1.0 -> opaque). – Scheff's Cat May 10 '19 at 11:44
  • 1
    Alternatively, you could `glDisable(GL_BLEND);` before rendering the cubes intended to be opaque. With disabled blending, the alpha value has no effect. – Scheff's Cat May 10 '19 at 11:46
  • see [OpenGL - How to create Order Independent transparency?](https://stackoverflow.com/a/37783085/2521214) – Spektre May 11 '19 at 08:04

1 Answers1

1

are you using the same shader ? if yes, then you will need to pass to your shader the information about opacity for each object. a way to do that simply is by using uniform variables.

check out those links :

https://www.khronos.org/opengl/wiki/Uniform_(GLSL) https://www.khronos.org/opengl/wiki/GLAPI/glUniform

cfaz
  • 185
  • 7
  • 2
    You just have earned your first 10 points rep. ;-) To improve the answer, you should cite the essence from the links. (Links may get lost and are not considered as that reliable to provide important info.) – Scheff's Cat May 10 '19 at 11:49