Jump to content
  • Advertisement
Sign in to follow this  
Leo_E_49

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

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

-- Eric Lengyel

Edit: Made link clickable

Share this post


Link to post
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 this post


Link to post
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).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!