Archived

This topic is now archived and is closed to further replies.

SoaringTortoise

Decal tutorial

Recommended Posts

Want to do tire-tracks, bullet-holes, etc. Don''t know how to. Assume create extra geometry, but how to clip to surface? Last thing to go through a tortoise''s mind before it hits the ground at 40mph? "D3DXVec3Add (Tortoise.Pos, Tortoise.Delta, Tortoise.OldPos"

Share this post


Link to post
Share on other sites
Or is better use projected texture?

Last thing to go through a tortoise''s mind before it hits the ground at 40mph? "D3DXVec3Add (Tortoise.Pos, Tortoise.Delta, Tortoise.OldPos"

Share this post


Link to post
Share on other sites
Hi
You can simply add one or two triangles just over the existing geometry, and offset it by a small number (like 0.001f) along the surface''s normal, so that z-buffer artifacts are not present. I think there exists a z-bias value that can be set for such effects, without having to actually offset your decal. Look for ''z-bias'' somewhere, you''ll find what u want.

Share this post


Link to post
Share on other sites
Yah, but what about complex surfaces? You can''t just add a couple of triangles, you need to sub-divide the decal to fit the geometry. Consider a craggy hill-top with an impact decal... depending on the actual impact point there could be as many as (erm... on my terrain...) about 20 polygons that the decal will overlay, each with their own normal.

Always prey on the weak, the timid and the stupid. Otherwise you''ll just get your butt kicked

Share this post


Link to post
Share on other sites
The proper way to do this is to create a 3D shape that represents your decal (usually a box). Next find the triangles that intersect this box. Then clip those triangles against the decal box to create your decal geometry. Finally, apply the decal texture to this geometry by calculating new UV coordinates based on the position of the vertex within the box.

The hardest part of this is the clipping. You could (I think!) actually skip this part, but if you''re going to have a lot of decals its nice to keep them small. If you want to skip the clipping you''d have to make sure that your decal texture isnt set to tile.

Share this post


Link to post
Share on other sites
Thanks Treething. It sounds like a lot of processing, but I''ll give it a go.

Cheers

Always prey on the weak, the timid and the stupid. Otherwise you''ll just get your butt kicked

Share this post


Link to post
Share on other sites
I suppose that with my terrain I could also just use a Tri-Fan to define the quad. Each silhouette vertex can take the height of the terrain at that position, then the center vertex is placed at the highest point within the quad. This won''t always look accurate, but it should be reasonably accurate most of the time. A single decal could never be bigger than a terrain quad, but that''s a fairly small limitation. Pretty easy to calculate too... just find the closest intersection of terrain geometry (easy enough... just round off the x,y co-ords) to get the center of the decal, and then extrapolate the edges from there and get the correct UV map. Hmmm.

Always prey on the weak, the timid and the stupid. Otherwise you''ll just get your butt kicked
For a tortoise, this is extremely hard to do, but when you get it right... the expression on their faces :-)

Share this post


Link to post
Share on other sites