Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
112 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

Uniform Terrain Decalcomania


As part of our first year group project at the Academy of Interactive Entertainment we needed to create a terrain class. One thing that we wanted for our terrain was the ability to place scorch marks onto its surface. I searched the Internet for tutorials and examples but failed to find anything of substance; perhaps the topic was too simple or I needed to find a new search engine. Eventually, I established that decals were going to be the solution to my problem.

Introduction: What Is A Decal?

So what exactly is a decal, you may ask? Well, the American Heritage Dictionary of the English Language describes a decal as:

  1. A picture or design transferred by decalcomania.
  2. A decorative sticker.

And the same dictionary describes decalcomania as:

  1. The process of transferring pictures or designs printed on specially prepared paper to materials such as glass or metal.
  2. A decal.

From this we can gather that decal is short for decalcomania, which is all about transferring graphic overlays onto surfaces. That's exactly what we want to do - transfer our graphic overlay, or decal, onto our terrain surface. In terms of computer graphics, a decal is essentially a geometry mesh that replicates a portion of an existing mesh. This replicated geometry is then raised slightly above the original mesh and given the appropriate decal texture. The effect is like placing stickers onto the original geometry.

In this article we will use the coordinate system found in 3D Studio Max, where, with respect to your computer monitor, +X is right, +Y is into the screen and +Z is up. So if you're looking down on the terrain (your line of sight is parallel with the Z-axis), the Y & X axis appear as they would in the Cartesian coordinate system. You can now forget about the Z-axis, as a terrain's Z-axis displacement, i.e. it's height, has no effect on our decals and is thus of no consequence. To make proceedings even simpler, we're going to place our terrain entirely in the first Cartesian quadrant, that is, the quadrant that is positive in both the x and y directions.

Cell Alignment and Texture Clamping

A cell is a square segment consisting of two triangle primitives belonging to a uniform terrain grid. As you would expect, decals do not always cover a complete cell or cells of a terrain, in fact, they are almost always found upon a fraction of a cell. To display a decal over a fraction of a cell we need to set the decal's texture to ‘clamp to the edge', this tells the graphics card to map edge texels to adjacent polygon regions that have texture UVs below zero or above one.


[Figure 1] The red pixels at the edge of the decal are set to full transparency.


[Figure 2] The repeated edge pixels have no transparency, causing the decal to cover all nine cells.


[Figure 3] The repeated edge pixels cannot be seen, displaying the decal over a fraction of the cells.

A problem may occur when a decal texture is resized to a smaller resolution. Transparent edge texels becoming compromised from blending with adjacent, non-transparent texels. The fix this problem the transparent border of the decal texture is widened, so that when resizing occurs, there will still be fully transparent texels at the edge of the texture.





Texture Coordinates


Contents
  Introduction
  Texture Coordinates

  Printable version
  Discuss this article