Decal implementation
Posted
by
dreta
on Game Development
See other posts from Game Development
or by dreta
Published on 2012-07-11T09:42:35Z
Indexed on
2012/07/11
15:24 UTC
Read the original article
Hit count: 439
graphics-programming
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?
© Game Development or respective owner