The OpenGL ES shading language provides an important feature of discarding fragments using the discard
keyword; this keyword is used only in the fragment shader to prevent updating the framebuffer. In other words, using this keyword throws away the current fragment and stops execution of the fragment shader. This feature of the OpenGL ES shading language is a simple yet effective feature, which opens up possibilities of producing cross-sectional views of 3D geometries, holes, or perforated surfaces.
This recipe reuses the last recipe; this requires a few changes in the fragment shader to demonstrate discarded fragment capabilities.
Rename the polka shader vertex and the fragment shader file as DiscardFragVertex.glsl
and DiscardFragFragment.glsl
. Open the fragment shader file and add the highlighted code:
#version 300 es // Many lines skipped . . . layout(location = 0) out vec4 FinalColor; vec3 GouraudShading( bool frontSide ) { // Reuse two...