Jump to content
  • Advertisement
Sign in to follow this  
spek

Arbitrary decals

This topic is 4390 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

Hi, I'm trying to add decals (blood, bullet holes, etc.) to my game, but I get stuck. I want to use more complex decals that "wrap around" the surface where they are placed on (so not just flat quads). I can determine where the decal is, and on which polygons it should be mapped. So I could make a copy of those polygons for constructing the decal mesh. But now it gets more difficult. Those polygons are ussually way to big, so I need to clip them or something. And secondly, I need to calcualte texture coordinates for that decal mesh. I was wondering how to do that. Another thing, decals should also be applied on dynamic objects. I think its pretty much the same for non-animated objects, except that the decal needs to be transformed so it moves along with its "host". But what about animated characters? I've been searching for a good article/demo, but I couldn't find much. You have any tips/tricks/sources? Greetings, Rick

Share this post


Link to post
Share on other sites
Advertisement
For static geometry, you'll need some neighbour information and a bit of poly-poly intersection code. And a bias handling, so decals don't aliase with the world geometry. They shouldn't write to z-buffer themselves.

For animated meshes, you can map the decal over the mesh (like skin the mesh on CPU, project decal onto it or wrap it like for static geometry, save texcoords in a vertex buffer, then feed it like a second stream), and render a part of the mesh (subdivide the mesh roughtly, and detect which parts the decal intersecs with) with that second vertex stream.
Or reserve a distinct texture map with unique texture mapping for decals baking.

Share this post


Link to post
Share on other sites
Hi again,

This post is already weeks old now, but I still have questions (and I have to thank Zemedelec for his reply). Internet was much down in the meanwhile, so sorry that I dig up this old post.

Anyway, I'm still looking for a way to create decals that fit on more complex surfaces (so not just simple quads). I can make a copy of polygons that are nearby the impact point, but I need to make it smaller. Maybe with clipping? I don't know what a fast way is, and besides, I don't know how to clip! There's stuff about clipping on internet, but those are mostly scientific sheets that handle polygons with >3 vertices. I'm not really good at math, so I was hoping for a more simple explanation.

And when the decal mesh is constructed, how to calculate the UV coordinates for it?

Greetings,
Rick

Share this post


Link to post
Share on other sites
Quote:
Original post by spek
Hi again,

This post is already weeks old now, but I still have questions (and I have to thank Zemedelec for his reply). Internet was much down in the meanwhile, so sorry that I dig up this old post.

Anyway, I'm still looking for a way to create decals that fit on more complex surfaces (so not just simple quads). I can make a copy of polygons that are nearby the impact point, but I need to make it smaller. Maybe with clipping? I don't know what a fast way is, and besides, I don't know how to clip! There's stuff about clipping on internet, but those are mostly scientific sheets that handle polygons with >3 vertices. I'm not really good at math, so I was hoping for a more simple explanation.

And when the decal mesh is constructed, how to calculate the UV coordinates for it?

Greetings,
Rick
Eric Lengyel wrote an article on this topic (with source code) in one of the first two Game Programming Gems books. It answers all the questions you mentioned.

If for some reason you can't get a hold of this reference, you'll have to dig in and write some clipping code yourself. Each candidate polygon should be clipped to a rectangular volume centered on the decal origin and with one basis vector aligned with the normal of the primary polygon. The texture coordinates for the resulting polygons can be computed by simple planar mapping.

If you get stuck on anything in particular you can always post back with any specific questions you have.

Share this post


Link to post
Share on other sites
I saw Eric's name on this often indeed :) But I don't have the book, and to buy a book just for this... Maybe a good christmas present though.

Clipping is the problem indeed, unless there's a completely different way for decals (I saw another post here about decals & projective textures). I find pretty much sites on the terms "polygon clipping", but most of them aren't really focussed on "games" and thus are making it more complex than nessesary in my case. And since I'm not very good in math (and lazy, I admit)... So if somebody knows a nice sheet/demo?

Greetings,
Rick

Share this post


Link to post
Share on other sites
As a note, the books are quite a well of knowledge, do it's not like you don't get anything else with that one block of code you're looking for. :D Aside from, that, one approach I considered before is a type of CSG operation. You basically make a sphere out of the decal, and use that to find what faces are going to be hit (using a ray or whatever find the point of impact, then create a sphere there to find the faces it would hit around it). Then, with those faces, you do a union operation of the sphere and the faces it hits, using the resulting geometry as the decal (basically cutting the sphere outta the wall, then using the pieces that were (was?) inside). For texturing, just use a type of planar projection, the extents of the sphere are 0,0 to 1,1.

Share this post


Link to post
Share on other sites
I use Sutherland-Hodgeman polygon clipping algorithm using an orthographic camera (setup right and top clipping planes to the size of the decal) to generate the decal mesh. The normalized device coordinates of the clipped vertices can be used to compute the texture coordinates (because in NDC the range is x=-1..1 and y=-1..1).

Share this post


Link to post
Share on other sites
Rather than scissoring triangles at runtime, I'd suggest that you just increase the number of triangles in the source mesh. Modern hardware can chew through triangles pretty quickly, and it's just a lot easier to have smaller triangles that you don't have to clip.

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!