Mesh Decals

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Mesh Decals

Post by slavik262 »

Putting decals (blood, bullet holes, etc.) is one thing (and there's plenty of previous threads about that), but how would you place a decal on a mesh? I'm making a space game, and when a missile or laser or something hits a ship, I'd like to show a blast mark there on a ship.

The best way I can think of doing this is to have a second texture that starts as completely transparent, then apply blast mark decals as needed. This texture could then be blended onto the final image using a shader. My current problems are
  • How would I control the size of the decals? The texture size can have nothing to do with the model size, so if I placed the same sized decal on two differently sized ships, the resulting final blast mark would be totally different sizes.
  • How would I get texture coordinates at a point? The collision manager allows you to ray cast to find a triangle and which scene node you collided with, but that's it. I saw an example in the DirectX SDK of the a DirectX picker that also gives UV coordinates of the collision point.
I know this is an extremely common effect (pretty much on any modern FPS to put blood on the characters). Does anyone know the common implementation?
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

Hmm, I think you might be interested in projective texturing.
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

Sounds about right. Any good links or resources?
booe
Posts: 76
Joined: Thu Jul 29, 2010 2:12 pm

Post by booe »

I'd rather create new triangles (or better, quads) for decals and bind them to ship model position. This should work fine for all non-animated meshes. If you want to put your decals on animated models as well, you can try to bind your quads to the given triangle of your model.
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

But if I use a flat quad, wouldn't the decal, i.e. a scorch mark, look bad from a side angle? And making a copy of the local geometry of the mesh around the impact point sounds expensive.

Another thought I had would be to do something like freetimecoder's shield effect.
booe
Posts: 76
Joined: Thu Jul 29, 2010 2:12 pm

Post by booe »

slavik262 wrote:But if I use a flat quad, wouldn't the decal, i.e. a scorch mark
Well, right, but such flat quads are a very cheap for creation/rendering, they are used by eg Quake III engine, (altrough everything depends on the quality of effect that you want to achieve).
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

How does, say, Counterstrike Source or Team Fortress 2 do it? Blood decals regularly appear on the characters themselves and appear to wrap around the mesh, not just be a flat quad.
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Maybe you could use a second transparent texture layer and dynamically paint the bloodstains into it. Then just blend it with the color texture.

Sounds good in theory -- not sure how to actually get a specific region from the uv coords, though.
Never take advice from someone who likes to give advice, so take my advice and don't take it.
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

Bate wrote:Maybe you could use a second transparent texture layer and dynamically paint the bloodstains into it. Then just blend it with the color texture.

Sounds good in theory -- not sure how to actually get a specific region from the uv coords, though.
This was my original idea almost exactly, but like I said in my OP,
  • How would I control the size of the decals? The texture size can have nothing to do with the model size, so if I placed the same sized decal on two differently sized ships, the resulting final blast mark would be totally different sizes.
  • How would I get texture coordinates at a point? The collision manager allows you to ray cast to find a triangle and which scene node you collided with, but that's it. I saw an example in the DirectX SDK of the a DirectX picker that also gives UV coordinates of the collision point.
Iyad
Posts: 140
Joined: Sat Mar 07, 2009 1:18 am
Location: Montreal, Canada

Post by Iyad »

What i suggest :
-Write a decal scene node, which will be called each time you shoot, here is a site where can have more information on implementaing decals :
http://www.flipcode.com/archives/Decals_Explained.shtml
-Add a bump and transparent layer to your decal scenenode, so it could be much more realistic.

Other thing you can do is using shaders (much more complicated) :
http://blog.wolfire.com/2009/06/decals- ... art-three/
#include <Iyad.h>
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Ops, should have read the thread thoroughly :)

Anyway, seems like the implementation would be rather difficult that way. Getting the uv coords of a point would be cool though (also in general). Do you think it would be possible to implement that "DX picker" you mentioned? I didn't stumble upon it yet.
Never take advice from someone who likes to give advice, so take my advice and don't take it.
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

@Bate I don't know how it would be possible in Irrlicht. Maybe the Devs have somtething to say about it?

@Iyad - I don't mind shaders - I'm using them heavily in my project. Your first link is just the quad surface I was talking about above - I'm leaning away from that. I looked at the second link, though and all it explains is how the lighting and coloring is done, not how the textures are actually applied.
Post Reply