Looking in the OpenGL shading language reference, I can't find the definition of "discard".
I think it will cancel output from the fragment shader. But will it also cancel execution? Or do you need to explicitely call "return" as well?
Looking in the OpenGL shading language reference, I can't find the definition of "discard".
I think it will cancel output from the fragment shader. But will it also cancel execution? Or do you need to explicitely call "return" as well?
It's on page 109 (115 in PDF numbering).Looking in the OpenGL shading language reference, I can't find the definition of "discard".
Whether discard "cancels execution" depends entirely on the hardware. In general, execution will only be canceled if an entire pixel group (the size of which depends on hardware) all execute a discard. So if you're trying to discard to avoid expensive computations, it may or may not help, depending on the spatial locality of the discards.
"The discard keyword is only allowed within fragment shaders. It can be used within a fragment shader to abandon the operation on the current fragment. This keyword causes the fragment to be discarded and no updates to any buffers will occur. Control flow exits the shader, and subsequent implicit or explicit derivatives are undefined when this exit is non-uniform."
Seems clear enough; you should not need to call return. Even if this does not really cancel execution for that fragment, it must logically act like it.
I had started a thread about this issue a year ago, but this didn't go very far
http://www.opengl.org/discussion_boa...L-compiler-bug
Found it on page 107 (113 PDF).
I used the search function for the word "discard" when displaying the document in Google Chrome, which did not turn up this reference. When I downloaded the document, I could search as expected using Acrobat PDF reader. A little worrying, I have depended on this search a lot.