Book Image

Lua Game Development Cookbook

By : Mario Kasuba, Mário Kašuba
Book Image

Lua Game Development Cookbook

By: Mario Kasuba, Mário Kašuba

Overview of this book

Table of Contents (16 chapters)
Lua Game Development Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Writing a fragment (pixel) shader


Fragment shader operates on pixel fragments from the rasterization process. The rasterizer transforms the whole graphical scene into a set of values that form fragments. A set of values that are related to one graphical primitive is called a fragment. These values may contain colors, alpha transparency, depth values, or even user supplied data. The fragment shader program might even decide whether to discard certain pixels from being drawn into the frame buffer.

Fragment shaders are often used in two-pass postprocessing. In the first pass, the whole scene is rendered into the texture or a buffer by using the first fragment shader. This shader renders primitives without postprocessing effects. In the second pass, this texture is used on a rectangle that covers the whole screen. This pass uses the fragment shader to control rendering of the texture on the rectangle. This way you can apply various effects such as High Definition Range transformation—HDR, screen...