Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I had issues finding information about decals, so maybe this question will help others. The implementation is for a forward renderer.

Could somebody confirm if i got decal implementation right?

  • You define a cube of any dimension that'll define the projection volume in common space. You check for triangle intersection with the defined cube to recieve triangles that the projection will affect.
  • You clip these triangles and save them.
  • You then use matrix tricks to calculate UV coordinates for the saved triangles that'll reference the texture you're projecting.
  • To do this you take the vectors representing height, width and depth of the cube in common space, so that f.e. the bottom left corner is the origin.
  • You put that in a matrix as the i, j, k unit vectors, set the translation for the cube, then you inverse this matrix.
  • You multiply the vertices of the saved triangles by this matrix, that way you get their coordinates inside of a 0 to 1 size cube that you use as the UV coordinates.
  • This way you have the original triangles you're projecting onto and you have UV coordinates for them (the UV coordinates are referencing the texture you're projecting).
  • Then you rerender the saved triangles onto the scene and they overwrite the area of projection with the projected image.

Now the questions that i couldn't find answers for. Is the last point right? I've never done software clipping, but it seems error prone enough, due to limited precision, that the'll be some z fighting occuring for the projected texture. Also is the way of getting UV coordinates correct?

share|improve this question
Here is a link with links:… – Luis Estrada Aug 10 '12 at 13:28

Take a look at this article:

It seems he is using the exact same approach you're using. He doesn't talk about z-fighting, but it could definitely become an issue at larger distances.

My suggestion would be to disable decals after a certain distance if the z-fighting becomes very visible.

share|improve this answer
i've seen this article multiple times, the thing is that it doesn't talk at all about what i'm asking about, like you've mentioned, the z fighting isn't really an issue of distance, it's just that you're trying to render right on top of existing geometry and due to limited precision, can/cannot you be sure that'll be on top or exactly in the same place – dreta Jul 11 '12 at 10:35
When drawing decals, you could always set the depth buffer comparison function to less-than-or-equal rather than less-than so decals are always drawn just on top of the surface they are affecting. – jmegaffin May 6 '13 at 19:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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