Texture Mapping and Lighting


  • Perspective-Correct Texture Mapping Basics
  • A Simple Texture-Mapper
  • Optimizing Texture Mapping
  • Simple Lighting
  • Implementing Texture Lighting
  • Advanced Lighting Using a Shade Map
  • Additional Concepts
  • Summary

When Super Nintendo came out when I was just a kid, I knew I had to have one. Super Nintendo was quite a step up from the previous Nintendo Entertainment System, complete with superior 2D graphics, cooler games, and whatever other whiz-bang feature was popular at the time. Soon enough, Christmas came around and I had one sitting under the tree. Later, my mom's friend came over with her son who was a few years younger than me. He was too young to be my peer, but, of course, it was my duty to entertain him anyway. We turned on my brand-new game system and began playing a generic 2D side-scrolling game. The game's parallax scrolling techniques made his jaw drop. Trees in the foreground were scrolling by quickly while the mountains in the back were slowly creeping, all with sharp and realistic textures. Never had he seen anything like it before. He shook his head and exclaimed, "Now that's 3D!" But, of course, it wasn't 3D. It was just an effect that simulated depth in a very two-dimensional scene—but simulated it well enough to impress a young boy. I didn't explain to him that the game wasn't really 3D because I realized something important: As long as a game is drawing onto a 2D surface such as a TV or computer monitor, the game is really just simulating a 3D scene. It's just a 2D picture, but the idea is to simulate 3D as realistically as possible. 3D is in the eye of the beholder. That brings us to the topics of this chapter: texture mapping and lighting. The demos from , "3D Graphics," gave depth, but everything on the screen was made up of simple, solid-colored polygons, which looked very abstract. In this chapter, you'll give polygons textures and shading, creating a more realistic experience. By the end of this chapter, you should be able to run the demos and finally say, "Now that's 3D!" Specifically, you'll create a software-based texture-mapper and implement lighting using a shade map, a technique popularized by games such as the original Quake. Despite its drawbacks, a software renderer in Java has a few advantages over a hardware renderer, such as not requiring a hardware-dependent API or having to worry about out-of-date or buggy 3D drivers. Plus, building a 3D texture-mapping engine is just plain fun. Eventually, you might want to use a hardware-based 3D renderer to deliver maximum performance in a game, but the techniques you'll learn in this chapter will enable you to understand and control any 3D renderer more thoroughly, whether it's hardware-based or not.