11.3. LatticeHere's a little bit of a gimmick. In this example, we show how not to draw the object procedurally. In this example, we look at how the discard command can be used in a fragment shader to achieve some interesting effects. The discard command causes fragments to be discarded rather than used to update the frame buffer. We use this to draw geometry with "holes." The vertex shader is the exact same vertex shader used for stripes (Section 11.1.1). The fragment shader is shown in Listing 11.6. Listing 11.6. Fragment shader for procedurally discarding part of an object
The part of the object to be discarded is determined by the values of the s and t texture coordinates. A scale factor is applied to adjust the frequency of the lattice. The fractional part of this scaled texture-coordinate value is computed to provide a number in the range [0,1]. These values are compared with the threshold values that have been provided. If both values exceed the threshold, the fragment is discarded. Otherwise, we do a simple lighting calculation and render the fragment. In Color Plate 14, the threshold values were both set to 0.13. This means that more than three-quarters of the fragments were being discarded! And that's what I call a "holy cow!" |