PDA

View Full Version : Decal rendering

M109uk
09-07-2005, 09:58 AM
Hi all,

How would i go about rendering a decal to a face?
I have an impact point of a face, but do i render the decal texure using the texture matrix?

Thanks for any help

Paulius
09-07-2005, 11:14 AM
I don?¢_Tt really see how the texture matrix could help here. If you want a possibly large amount of decals there?¢_Ts not much else to do then draw textured pollys on top, when depth testing is set to less or equal everything should look just fine. To get axis by which to extrude a quad/triangle out of the hit point you could use one vector from subtracting the position of two vertices of a face, the other one is a bit tricky, do a cross product with the first used vector and another one extracted in the same way so we get a vector perpendicular to the face, then do another cross product with that vector and the first one and there we have two vector on a face and perpendicular to each other. You might want to clip the decal to the edges of the face by hand, but a lot of games don?¢_Tt even bother.

M109uk
13-07-2005, 12:39 PM
Ok, i was thinking using the texture matrix to position the decal on the texture of the face...

I have a simple routine to get the axis, its probably the wrong way about doing it, and it only works with flat faces:

function GetAxis(Face: TFace): Integer;
var
i: Integer;
min,max: TVertex3f;
begin
For i := 0 To 3 Do
Begin
If Face.vertex[i,0] < min Then min := Face.vertex[i,0];
If Face.vertex[i,1] < min Then min := Face.vertex[i,1];
If Face.vertex[i,2] < min Then min := Face.vertex[i,2];

If Face.vertex[i,0] > max Then max := Face.vertex[i,0];
If Face.vertex[i,1] > max Then max := Face.vertex[i,1];
If Face.vertex[i,2] > max Then max := Face.vertex[i,2];
End;
If (min = max) And (min = max) Then Result := AXIS_XY Else
If (min = max) And (min = max) Then Result := AXIS_XZ Else
If (min = max) And (min = max) Then Result := AXIS_YZ;
end;

Does any one know of a better way?

thanks

Paulius
13-07-2005, 07:29 PM
So you want to draw the whole face again just with adjusted texture coordinates for the decal? I suppose that?¢_Ts one to avoid clipping it, but unless all you?¢_Tre faces are really small you?¢_Tll burn a lot of fillrate on totally transparent fragments (might seem not much now, but what if a face close to the camera has tens of bullet marks). But then I don?¢_Tt get what you want with the axis. And why you?¢_Td mess with texture matrix at all, since you?¢_Td still need to fill in texture coordinates. I still suggest you do it the way I described above and mess with decal?¢_Ts vertex rather than texture coordinates.

Sly
13-07-2005, 10:22 PM
Here is a flipCode article on doing decals such as bullet marks, etc.
http://www.flipcode.com/articles/article_decals.shtml
Note that the linked demo and screenshots no longer exist.

Here is another demo using that article as a reference that does exist.
http://members.net-tech.com.au/alaneb/decals.html