# Decals

This topic is 4833 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How do you handle decals? I would like a simple system for such things as footprints and bullet holes. Articles, book references and tutorials are welcome [grin]. I'm particularly interested in how you avoid coplanar trouble with decals.

##### Share on other sites
I assume you mean z-fighting by coplanar troubles...
Personally, I would just use a textured quad for simple things like bullet holes and foot prints.

Anyway, here is a good page on preventing z-fighting in D3D ... with alternative methods at least. Offseting the quad off of the plane should do the trick as well, though this is a cheap hack, and sometimes doesn't even work (camera is in the distance, etc).

There are a bunch of hacks out there to help prevent z-fighting. Do some digging via google.

##### Share on other sites
There are two components to rendering decals that you'll need to deal with. The first is actually constructing the decal mesh itself. I've written an article about this that can be found in the following two places:

"Applying Decals to Arbitrary Surfaces", Game Programming Gems 2, Section 4.8, Charles River Media, 2001.

Mathematics for 3D Game Programming and Computer Graphics, 2nd ed., Section 9.2, Charles River Media, 2004.

The second thing is implementing some kind of polygon offset. OpenGL has the glPolygonOffset() function and DirectX has the D3DRS_DEPTHBIAS render state, but using either of these causes hardware-based hierarchical z-buffering to be disabled, reducing performance. I developed an alternative back in 2000 that modifies the projection matrix to achieve the same effect without any performance impact. You can find this article in the following two places:

"Tweaking a Vertex's Projected Depth Value", Game Programming Gems, Section 4.1, Charles River Media, 2000.

Mathematics for 3D Game Programming and Computer Graphics, 2nd ed., Section 9.1, Charles River Media, 2004.

-- Eric Lengyel

##### Share on other sites
Thanks, I've got all three of those books so I'll be sure to take a look.

One question though, is this method of implementing decals costly in terms of processing? Or can it be used liberally?

##### Share on other sites
I use it very liberally in my engine, and the performance is fine. Since creating a decal is not something you do every frame (unless lots of characters are continuously spraying bullets all over the place), it doesn't have a significant performance cost. And I've found that clipping a mesh to a decal boundary goes very quickly (that is, there is no detectable delay, even with good instrumentation, that appears during frames in which you do create new decals).

You can download a demo of my engine at the link below. All of the scorch marks that you see when you shoot stuff use the exact techniques described in the above articles. Go ahead and go crazy with the plasma gun (the green gun that you can find in the warehouse-like room -- hit 4 to use) and see how well it works. You can toggle wireframe to see the decal meshes by typing "wire" in the command console.

-- Eric Lengyel

##### Share on other sites
Cheers mate! [grin]

Very nice engine. What method did you use for your shadows? I noticed the trees in the screencap below, how did you manage the leaf shadows?

##### Share on other sites
Thanks. The standard shadow technique used by the engine is stencil. The shadows for the trees are actually stored in a precomputed orthographic shadow map (depth along the light direction).

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 11
• 12
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
633349
• Total Posts
3011465
• ### Who's Online (See full list)

There are no registered users currently online

×