Hi, I am trying to generate decals such as the bullet hole on a geometry, I read the article <Applying Decals to Arbitrary Surfaces> in game programming gems 2, the article give the math method for picking triangles from geometry. But I think the method is a CPU-intensive process, can someone give me a method for better performance or use such as the graphic feature to do that?
One thing that works quite well is just projected decals. Similar to deferred lighting, you create simple geometry to encompass your decal, then after GBuffer is made, do a pass where you draw these simple meshes, and apply decals based on gbuffer content, exactly like you would for a spotlight.
The method described in GPG2 is very efficient and practical. I've been using it for over ten years (since the time I wrote the article), and I've been extremely happy with it. It's important to realize that the polygon clipping only happens once, when the decal is created, so it's not like you're spending time building the decal every frame. It does not cause a performance problem. Managing the decal on the CPU also has certain advantages that you can't get in a GPU-only method. For example, suppose a decal was created on an object that later moves, like a door opening or a barrel rolling down a hill. If the portions of the decal applied to those objects inherit the transform properly, then the decals move with the objects they are attached to. Even if the transforms were communicated to the GPU, a deferred rendering technique would have a serious problem trying to distinguish between the geometries to which the decal should be applied and those that may be near the decal now but shouldn't have the decal applied to them.