0

I was reading about the side effects of using "discard" in OpenGL's fragment shader, such as early testing being disabled. But I could not find any alternative for alpha-testing until I stumbled upon glAlphaFunc, which seems to be deprecated since OpenGL 3.0. However I could not find any documentation on why it has been removed, and there seems to be no alternative to "discard".

Type Definition
  • 75
  • 1
  • 13
  • 3
    *"I was reading about the side effects of using "discard" in OpenGL's fragment shader, such as early testing being disabled."* - Why do you think the alpha test does not have this downside? – Rabbid76 May 14 '20 at 07:58
  • I can say if this is true for `AlphaFunc` but it is likely. If you add new functionalities or ways of solving a problem in library, you might come to a point where one thing can be done in different ways. Such situations are something you want to avoid because it can introduce hard to debug code because then you might lose the overview where and how a certain behavior was set (you would need to search in you code for `glAlphaFunc` and in the shaders for `discard`) . As `discard` can do the same thing as `AlphaFunc` is better to deprecate the `AlphaFunc` over the more general `discard` method. – t.niese May 14 '20 at 12:02

1 Answers1

3

Alpha testing has (on all implementations I know of) never been done in the early testing stage. I don't think it is even possible there because before the fragment shader has been executed there is no concept of a color or a alpha channel.

In addition, enabling alpha testing usually disables early depth testing (see here), which means that it behaves the same as when discard is used in the shader.

I cannot directly answer why glAlphaFunc has been removed, but since there is no real difference between discard and alpha testing, it's not really a problem.

BDL
  • 21,052
  • 22
  • 49
  • 55
  • Thank you. I didn't know that early depth testing was disabled once alpha testing is enabled. It also seems that as long as the shader has any side effects such as writing to a texture, early testing is also disabled. That means that it probably has no meaningful use for something like deferred rendering anyways. – Type Definition May 14 '20 at 17:42