From a Ray to a Texture address

Started by
4 comments, last by Lestat3D 21 years, 7 months ago
Hi, Im working on a WipOut-like game. And when a ship gets shooted, I have to draw a bullet hole on its texture but I don''t know how to do that, I don''t know even how to know where in the texture I have to draw. Can anyone help me?!? I''m actually in troubles.
Advertisement
I cannot think of any tutorials / docs on this sort of thing off the top of my head but you might want to try and do a search for "decals" and "planar projections". These are the things you are effectively looking for and will get you moving in the right direction.

Regards,
Sharky
I would fake it and use a set of secondary textures, or a render target...
When the ship gets shot, render a bullet sprite or whatever to a texture, possibly in the approximate region of the bullet impact point (I think that if it''s a fast-paced wipeout-stylee job, then players really won''t care, or have time to care where EXACTLY the bullet hit, especially if it''s not a major point of the game, but maybe it is..i don''t know..), and then render this new texture on top of the ship.

Either that, or you could set up 7 or 8 textures with progressivly detailed scrape and bullet marks, and just switch them according to the extremety of the damage to the ship.

In the type of game you describe I wouldn''t go into such detail as finding exact plane coordinates and presice hit points, then worry about how to draw a single bullet hole on the ship..
The pick sample in the SDK describes how to get the u,v coordinates that were struck by a ray. Use that to index into your texture and alter it.

Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces"
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
U and V returned by D3DXIntersect are NOT texture coordinates. They are barycentrics coordinates. You will have to further convert them into texture UV coordinates.

T = T2*Bu + T3*Bv + T1*(1-Bu-Bv)

T is a vector representing the intersection coordinates in UV texture coordinates
T1 is a vector representing the texture coordinate for the first vertex in the face
T2 is the second
T3 is the third
B is a vector representing the barycentric point of intersection
Bu is the U component for barycentric vector
Bv is the V component for barycentric vector


______________________________
Oooh, you found the horadric cube!
Editor42 ...builds worlds
Yes, and to be clear, this is shown in the Pick sample...

Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces"
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials

This topic is closed to new replies.

Advertisement