two really big problems with decals

Blitz3D Forums/Blitz3D Programming/two really big problems with decals

eizdealer(Posted 2004) [#1]
Hi

First of all, it's hard to express such complicated stuff like I am about to do. Especially if you do it in a foreign language. So please let me know if you don't get my problems or if there are any other inaccuracies in my description.

I'm working on a mesh terrain engine, right now I'm at the decal code. Decals are supposed to be 2d textures that are put on the terrain and fit the terrain's shape.
The terrain consists of tiles that are each .5 x .5 blitz units large. All vertex points' heights can be changed.
As I wrote before the decals should fit the shape of the terrain. In order to assure this everywhere where

a) the decal is on a crosspoint of the tiles
b) the connections of the edges of the decal overlap a terrain's line

must be a vertex point of the decal. Yes I know, noone knows what I'm talking about right now. But please have a closer look at the graphic and think a bit about it:



(the green thingy is the decal, the red circles mark cutting points)

If I had a plane instead of this and the terrain mesh would be a little higher at this point, the decal would not be visible at all.

So I'm getting to my first problem at least ;)

How would you try to get the cutting points described in b) ? I've got the ones described in a). Hint: The coordinates of the 4 edges are given.


Now for my second problem:

Let's say all the cutpoints are given. I first thought to connect the edges of the decal with 2 triangles, then go for each cutpoint, clip the triangle it is in and create three new triangles so that the cutting point would be a 'real' vertex point of the decal.

This was the result (wframe):


(note that the only the cutting points described in a) as well as the edges are in this screen)

Looks OK at first. But imagine if you lifted some of the terrain points - exactly, the terrain would be over the the decal again. Why? Because the grey lines (decal) overlap the brown lines (terrain). This is a result of the rather random clipped triangles. How to fix that? Well, I thought about the same procedure I've just described but for each single tile.

Now we've got a new situation:



Given are the cutpoints of this single tile. But how do I know how to add the tiles without adding too many but still covering the whole area restricted by the cutpoints? This is easy of course with three or four cutpoints. But with a bit of luck I will have to do this with up to 8 of them.




Now that you're completely confused 8) I want to thank you just for reading till the end. I would very very much appreciate if you told me whether you have understood the text or not. And it would be absolutely perfet if you had any ideas for solutions of the problems.


JoshK(Posted 2004) [#2]
Why bother with all thatr slicing? Just use texture clamping and apply the texture to the whole terrain, or just to the triangles it affects?


eizdealer(Posted 2004) [#3]
The important thing for the decals is that you can't only have rectangles but also quadrangels (i need that for another function).
The whole terrain is much to big to apply a single decal texture on it. And it should be possible to have transparent decals. So you can't put the texture on the triangles it affects because you wouldn't be able to see the textures that are under the decal.


JoshK(Posted 2004) [#4]
I assume this decal is a blast mark or something with transparency around the edges?

Just lock clamp the texture and create a mesh using only those triangles that get affected:



If you just make sure the edges are transparent, the areas of triangle that go way beyond what you actually want will be invisible. The real deal will look like this:




eizdealer(Posted 2004) [#5]
This is another possibility I have thought about, too. But if you do it this way, you will always have to use textures which are transparant at the edges (what I do not want).
Thanks very much though!


sswift(Posted 2004) [#6]
1. When you load your decal, enable UV clamping. Make sure the edges of the decal are transparent if you are using a decal with an alpha map, or black, if you are using a decal you want to multiply with what is behind it.

2. For each triangle that falls within the decal, copy that triangle to a new mesh or a new surface within your terrain mesh.

3. Set the texture coordinates for the triangle. If the trangle falls partially outside your decal region, then your coordinates might be less than 0, or greater than 1. Pretend that the decal tiles.


The UV clamping ensures that the decal will NOT actually appear to tile. And if you have a lot of small triangles in your terrain, then it won't really matter if you have a little extra area being textured with an invisible texture.


Where you really need to worry about clipping the triangles so they fit the region exactly is when you have a large flat wall in a first person shooter and you want to put a scorche mark or shadow on that. Then you'll get a lot of overdraw form the extra invisible areas, and you don't want that.

I made a clipping system which can handle clipping polygons so you can do very precise decals with no overlapping stuff. It's free, and you may request it from me via email, but it's very advanced. If you don't know what a plane equation is, then you might not be able to figure it out. I don't want to be proividing lots of support to everyone, but I will answer a question or two. It's a real nice system though.

[edit]
I see you know aobut that UV clamping method... Well, you're free to use my lib if you want. It does "sutherland-hodgeman clipping". It is the fastest clipping algorithm out there and very robust. It'll do what you want if you can figure out how to set up the clipping planes. I'll step you though the basics if you need me to.
[/edit]

[edit2]
Oh and btw... The system will automatically build your new polygons for you, and set the UV coordinates as needed based on the originals.
And you could use a decal of any shape with any number of sides.
[/edit]


eizdealer(Posted 2004) [#7]
Now this is an interesting idea sswift, thanks a lot for it!

Did I get that right - when you have the clamping flag turned on the tris where the u/v coordinates are not between 0 and 1 will be transparent?
But the edges of the texture have to be transparent, don't they?

Edit: It would be very very nice if you could give me the lib you mentioned. I'd say I have a look at it til tomorrow (since it's already late here) and contact you if I need any help.
Thanks very very much again, I already thought I'm lost :)

My mail is eizdealer (a t) web .de


sswift(Posted 2004) [#8]
"Did I get that right - when you have the clamping flag turned on the tris where the u/v coordinates are not between 0 and 1 will be transparent?"

Yes. The edges have to be transparent. That was what Halo was trying to describe to you.

When UV clamping isturned on, anything on a texture outside 0..1 will use a color which has been pulled from the edge of the texture.

If you looked at a texture like this in the middle of a polygon, then you'd see the edge pixel colors stretched vertically and horizontally to infinity.

You can also position the texture so that instead of the texture being at 0..1, it might be at 2..3. You can scale it too.