Skip to main content
GameDev.net gamedev.net
🔒 Locked

Decals

Started by Leo_E_49 Aug 23, 2005 at 10:23 PM 5 replies 3k views
Original Post
Leo_E_49
Leo_E_49
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.
choffstein
choffstein
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.
Eric Lengyel
Eric Lengyel
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
Leo_E_49
Leo_E_49
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?
Eric Lengyel
Eric Lengyel
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.

http://www.terathon.com/c4engine/download.html

-- Eric Lengyel

Edit: Made link clickable
Leo_E_49
Leo_E_49
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?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.