OpenGL 4 Shading Language Cookbook(Second Edition)
上QQ阅读APP看书,第一时间看更新

What this book covers

Chapter 1, Getting Started with GLSL, explains the steps needed to compile, link, and use GLSL shaders within an OpenGL program. It also covers how to send data to shaders using attributes and uniform variables, and the use of the GLM library for mathematics support. Every modern OpenGL program today requires a function loader. In this chapter, we also cover the use of GLLoadGen, a relatively new and easy-to-use OpenGL loader generator.

Chapter 2, The Basics of GLSL Shaders, introduces you to the basics of GLSL programming with per-vertex shading. In this chapter, you see examples of basic shading techniques such as the ADS (ambient, diffuse, and specular) shading algorithm, two-sided shading, and flat shading. It also covers examples of basic GLSL concepts such as functions and subroutines.

Chapter 3, Lighting, Shading, and Optimization, presents more advanced shading techniques, with a focus on the fragment shader. It introduces you to techniques such as spotlights, per-fragment shading, toon shading, fog, and others. We also discuss several simple optimizations to make your shaders run faster.

Chapter 4, Using Textures, provides a general introduction to using textures in GLSL shaders. Textures can be used for a variety of purposes besides simply "pasting" an image onto a surface. In this chapter, we cover the basic application of one or more 2D textures, as well as a variety of other techniques including alpha maps, normal maps, cube maps, projected textures, and rendering to a texture. We also cover sampler objects, a relatively new feature that decouples sampling parameters from the texture object itself.

Chapter 5, Image Processing and Screen Space Techniques, explains common techniques for the post-processing of rendered images and some other screen-space techniques. Image post-processing is becoming a crucially important part of modern game engines and other rendering pipelines. This chapter discusses how to implement some of the more common post-processing techniques such as tone mapping, bloom, blur, gamma correction, and edge detection. We also cover some screen-space rendering techniques such as deferred shading, multisample antialiasing, and order-independent transparency.

Chapter 6, Using Geometry and Tessellation Shaders, covers techniques that demonstrate how to use these new and powerful shader stages. After reading this chapter, you should be comfortable with their basic functionality and understand how to use them. We cover techniques such as geometry-shader-generated point sprites, silhouette lines, depth-based tessellation, Bezier surfaces, and more.

Chapter 7, Shadows, introduces basic techniques for producing real-time shadows. This chapter includes recipes for the two most common shadow techniques: shadow maps and shadow volumes. We cover common techniques for antialiasing shadow maps, as well as how to use the geometry shader to help produce shadow volumes.

Chapter 8, Using Noise in Shaders, covers the use of Perlin noise for creating various effects. The first recipe shows you how to create a wide variety of textures containing noise data using GLM (a powerful mathematics library). Then we move on to recipes that use noise textures for creating a number of effects such as wood grain, clouds, disintegration, paint, and static.

Chapter 9, Particle Systems and Animation, focuses on techniques for creating particle systems. We see how to create a particle system to simulate fire, smoke, and water. We also make use of the OpenGL feature called transform feedback, in order to gain additional efficiency by moving the particle updates onto the GPU.

Chapter 10, Using Compute Shaders, introduces you to several techniques that make use of one of the newest features in OpenGL, the compute shader. The compute shader provides us with the ability to do general computation on the GPU within OpenGL. In this chapter, we discuss how to use the compute shader for particle simulations, cloth simulation, edge detection, and the generation of a procedural fractal texture. After reading this chapter, the reader should have a good feel for how to use the compute shader for arbitrary computational tasks.