0

I'm trying to render a semi-transparent object inside of a skybox. However with my current implementation the textures are blended with the background color instead of the skybox (if there is no other object in the way).

Here are some milestones in my implementation I thought would be useful to share:

init:

[...]
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
[...]

render:

[...]
[render scene]
[...]
glUseProgram(program_skybox);
glDepthFunc(GL_LEQUAL);
glDepthMask(GL_FALSE);
[bind view & projection matrices]
[draw skybox]
glDepthMask(GL_TRUE);
glDepthFunc(GL_LESS);

What should I change to make my skybox blend? I suppose the problem is with the depth buffer?

Ecto
  • 1,125
  • 1
  • 7
  • 13
  • 4
    As walways, alpha blending requires sorting. As your skybox is the furthest object by definition, you must draw it first. – Quentin Apr 25 '20 at 17:27
  • @Quentin oh yeah thank you, add it as an answer – Ecto Apr 25 '20 at 17:30
  • Maybe a duplicate of https://stackoverflow.com/questions/45770076/rendering-transparent-objects/45770274#45770274? It's not the exact same problem but the same underlying cause – BDL Apr 25 '20 at 17:39
  • also take a peek at this: [How to create Order Independent transparency?](https://stackoverflow.com/a/37783085/2521214) – Spektre Apr 26 '20 at 07:17
  • @Spektre I was just looking at order independent transparency, but I didn't get very wise from it. Also, I'd guess the comment you suggest would work only for two-layered objects, but I have "many" transparent objects in my scene. I'd love to hear from you if you know more about this topic! – Ecto Apr 26 '20 at 11:21
  • @Ecto you can have more transparent objects ... that linked answer just avoids z-sorting (on per primitive manner) by rendering by CW/CCW winding rule instead. You know if you have mesh with strict winding defined (so `GL_CULL_FACE` is working as should) then all backside faces have opposite winding to all front faces. So no need to sort them just render by winding. from that you just z-sort the objects instead of all faces ... I avoid even that as my transparent objects do not intersect and are "concentic" ... so one is inside the other one. – Spektre Apr 26 '20 at 14:06
  • @Ecto In case of single layer you just use half of the rendering passes... I also recommend to look at the other answer by `Zouch` the nVidia link handles this problem in depth – Spektre Apr 26 '20 at 14:07
  • @Spektre Thanks, so far I have just made all semi-transparent pixels have alpha value of 1 or 0 so there is no need to merge colors and discarded fragments with zero, which doesn't look perfect, but gets the job done and probably is much easier to implement. – Ecto Apr 26 '20 at 16:48

0 Answers0