Lattice

Here’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 framebuffer. We use this to draw geometry with “holes”. The vertex shader is the exact same vertex shader used for stripes (“Regular Patterns”). The fragment shader is shown in Example 8.8.

Example 8.8. Fragment Shader for Procedurally Discarding Part of an Object

in vec3 DiffuseColor;in vec3 SpecularColor;in vec2 TexCoordout vec3 FragColor;uniform vec2  Scale;uniform vec2  Threshold;uniform vec3  SurfaceColor; ...

Get OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.