2
\$\begingroup\$

I'm trying to figure out exactly how to project textures onto an animated model. I've taken a look at L4D2's wound's white paper. But their method doesn't exactly explain how they went about this.

I've tried using the old school method to create a mesh and attach it to the object... But that would require the GPU to store that data for a long period of time, and recall it correctly for the animated model. On top of that there's the Z-fighting problem with it.

I've tried the Deferred shading method. But I can't get that to work correctly either. My set up requires some form of filter in order to prevent the decal from projecting onto other models. And then should a moving body part cross over the volume, it gets rendered onto that as well, which is not as desired.

\$\endgroup\$
1
\$\begingroup\$

What i do is store an object ID in a uint16 rendertarget when i build my G-Buffer then in the decal pass i just convert the decal box vertex positions to screen space and then read back the object ID buffer and see if the returned ID is the target ID of the decal.

I have my decal shader setup so i can pass in an array of object ID's that way you if you want your decal to hit say the player and the terrain you just up load the payer object ID and the terrain object ID and away the shader goes.

The object ID buffer is also used in my lighting pass to set up the material properties.

\$\endgroup\$
1
\$\begingroup\$

One of the simplest methods I've seen is to project into the model's texture map itself. Then it tracks & animates with the model just as the rest of the model's skin does, at no additional geometry/blending cost each frame.

This does have some restrictions:

  • models that can be decalled must be unwrapped uniquely, without mirroring/parts of the texture re-used in different places around the model

  • each decalled instance requires a unique copy of its texture, and (unless you're atlassing them) a separate draw call from other models using the undecalled version of that texture

  • decals away from UV seams are easiest to process. Decals crossing UV seams can be accomplished using a projection method. Though this has a similar "overspray" possibility mentioned for the deferred case, it's usually more manageable because the projection math happens just once, rather than animating continuously with a moving limb. If the projection is performed in the model's T-pose the risk of undesired splash is much lower. Non-projection methods can work too, but generally require some non-trivial mesh-walking to find the correct alignments.

The technique of layering an additional geometry "skin" over the decal area works too, inheriting the skinning weights from the original mesh so it animates together with it seamlessly. To avoid z-fighting, it usually suffices to render the decal second, and apply a slope-sensitive z-bias. Since the decal skin closely follows the source mesh, it's not quite as fiddly to tune as arbitrary z-fighting cases. ;)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.