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

Setting up lighting


The fixed pipeline of OpenGL allows you to set up simple lighting. This lighting system is mostly used for static scenes with a few light sources. This is mostly because it has a few limitations:

  • OpenGL guarantees that there are at least eight light sources available.

  • It only supports Gouraud shading—vertex color interpolation

  • There are predefined equations for normal mapping and attenuation. You can only change a few parameters.

If you're okay with these limitations, you can use this lighting system without the need of CPU-computed lighting or GPU shaders. Games such as Quake and Quake 2 use vertex colors and light map textures to compute lighting on CPU, which is expensive, but these games use certain tricks to keep the performance at an acceptable level. For instance, Quake 2 uses compressed normal vectors that can be compressed into 1 byte.

Getting ready

This recipe will operate not only with vertex position coordinates but also with normal vectors. Normal vectors are important...