Sign in to follow this  
Kest

Projecting without stretching

Recommended Posts

I'm trying to project decals onto triangles for bullets and "explosion smoked" areas. I've generated a list of all world triangles (from walls/floors/furniture) that fall into the sphere area of the decal radius. I'm also preparing a clipping routine that will overlay the decal rectangle onto each individual triangle in this list and only keep the part that overlaps (haven't finished this bit). My concern at this point is that I don't know how to generate the texture coordinates for each vertex in a way that will cause the decal to "lay over" all of these triangles without stretching and without coordinate inconsistencies between triangle edges. For example, if I fire a weapon nearly parallel to a wall, a planar map will cause the bullet to stretch nearly all the way down that wall. But if I use the wall's normal vector to generate the coordinates, then what happens when I fire into a corner where two walls (with different normals) must share this decal? Does anyone know what I should do with this mess? I'm open to compromises. Thanks for any help.

Share this post


Link to post
Share on other sites
I wanted to add a few things.

First, to avoid stretching, I'm thinking I might have to "pull back" vertices (move them toward the center of the impact point) to prevent the vertex distance from going beyond the texture space.

Second, if I can manage to map the texture coordinates onto individual triangles without too much stretching, I can then do a scan to find vertices (in separate triangles) that have equal world positions. For each set of vertices with equal positions, I can average their texture coordinates and lock them all to the result, making them all match. This will probably cause a little distortion, but I doubt it will become a problem.

So my biggest issue is finding a method to project the decal before I do any of this. Any advice would be appreciated.

Share this post


Link to post
Share on other sites
I'm not an expert here, but I'd think you'd want to do something like 'find the best wall' and just paste one triangle/decal oriented to the wall. Alternatively for each wall in collision, paste a distinct triangle/decal oriented to the wall. Trying to match things up sounds like more trouble than it's worth, especially for things like small bullet holes which shouldn't be super noticeable when they're fired into corners.

One thing you might do as well is boot up your favorite fps game and spray a corner with bullets. See what the result looks like.

Share this post


Link to post
Share on other sites
I still haven't gotten around to doing this, but I haven't stopped thinking about it. Here's what I'm considering so far:



1. Project the decal onto the impact triangle's vertices. It doesn't really matter where the decal edges are, yet - just set the triangle's vertex UV coordinates to values that place the decal into position on that triangle's plane. This impact triangle is referenced as [0].

2. Find all of the triangles welded to [0]'s, and mark these as [1].

3. The UV coordinates of the vertices that weld all [1]'s to [0] are set to the same values as [0].

4. The other vertex UVs on [1]'s are generated with angles and distance, relative to the welded vertices.

5. Repeat steps 2 through 4, but change [0] to [1] and [1] to [2]. Do this until all triangles in the decal sphere have been scanned.

6. Find all vertices (throughout all triangles) that have equal world positions, get the average UVs, and set them all to it.

7. Find the decal borders and clip them. This step hasn't been fully thought out, but I think I can actually use the texture coordinates to do it. Just find the lines where they pass beyond 0.0 or 1.0. Sounds nice in theory.




I'm not exactly sure how to best go about step 4. I could just generate "up" and "right" vectors, relative to the impact triangle's normal, then rotate these for each neighbor triangle, and so on. It seems like a hassle, but I haven't thought up anything better.

If anyone can help me improve or replace, I'd appreciate it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this